The Perfect Developer Language Reference Manual

Version 7.0, February 2017

Disclaimer

The information in this publication is given in good faith but may contain errors and omissions. The contents of this document and the specifications of Perfect Developer and the Perfect language are subject to change without notice.

Contents

1. Introduction

1.1 Purpose of this manual
1.2 Status of this edition
1.3 Organization
1.4 Syntax used to describe the grammar of Perfect

2. Goals and principles of the language

2.1 Design goals
2.2 Principles
2.3 Context

3. Lexical form

3.1 Overview
3.2 Character set
3.3 Comments
3.4 White space
3.5 Multi-character tokens
3.6 Reserved words
3.7 Identifiers
3.8 Character literals
3.9 String literals
3.10 Integer literals
3.11 Real literals

4. Classes and Types

4.1 Overview
4.2 Concepts of type

4.2.1 Classes
4.2.2 Types

4.3 Predefined classes
4.4 Predefined types
4.5 Literals for predefined classes
4.6 Class declarations

4.6.1 Enumeration generator
4.6.2 Tag generator
4.6.3 Abstract class declarations

4.7 Type expressions
4.8 Instantiating class templates
4.9 Constrained types
4.10 United types
4.11 Union of all derived classes
4.12 Reference types
4.13 Type naming
4.14 Predefined class templates

4.14.3 Sequences
4.14.4 Pairs
4.14.5 Triples
4.14.6 Mappings

4.15 Type compatibility

4.15.1 Overview
4.15.2 Fundamental type relations
4.15.3 Examples

5. Expressions and Operators

5.1 Overview
5.2 Functions, Selectors and Constructors

5.2.1 Using functions and selectors
5.2.2 Using constructors

5.3 Operators

5.3.1 Unary operators
5.3.2 Binary operators
5.3.3 Equality operator
5.3.4 Rank operator
5.3.5 Type comparison operator
5.3.6 Operator precedence
5.3.7 Suggested operator pronunciation

5.4 Other expression constructs

5.4.1 Operators on types
5.4.2 Brackets, temporary names, assertions, conditionals and trace
5.4.3 Choosing
5.4.4 Transforms
5.4.5 Quantified expressions
5.4.6 Cast expression
5.4.7 Type widening expression
5.4.8 Type enquiry expression
5.4.9 Subclass expression
5.4.10 Subjunctive expression
5.4.11 Over expression
5.4.12 Heap expression
5.4.13 Value expression
5.4.14 Converting between types
5.4.15 Scope resolution
5.4.16 "?" expression

5.5 Writable, Limited writable and Non-writable expressions
5.6 Primed expressions

6. Modules and Declarations

6.1 Declarations
6.2 Constant declaration
6.3 Heap declarations
6.4 Variable declarations
6.5 Function declarations

6.5.1 Syntax of function declarations
6.5.2 Polymorphic function declarations
6.5.3 Function usage

6.6 Operator declarations

6.6.1 Syntax of operator declarations
6.6.2 Comparison operator declarations
6.6.3 Declaring operator properties

6.7 Selector declarations

6.7.1 Syntax of selector declarations

6.8 Schema declarations

6.8.1 Syntax of schema declarations
6.8.2 Postconditions

6.9 Property declarations
6.9.1 Syntax of property declarations

6.10 Axiom declaration
6.11 Type compatibility of parameters and results

6.11.1 Type compatibility of undecorated parameters
6.11.2 Type compatibility of parameters decorated with "!"
6.11.3 Type compatibility of repeated parameter groups
6.11.4 Type compatibility of result values

6.12 Function, Operator, Selector and Schema Overloading
6.13 Modules

7. Abstract Classes

7.1 Abstract class declaration

7.1.1 Syntax
7.1.2 Class specification
7.1.3 Inherits part
7.1.4 Abstract members
7.1.5 Internal members
7.1.6 Confined and Interface members
7.1.7 Rank and equality declarations
7.1.8 Nonmember declarations
7.1.9 Recursive class declarations
7.1.10 Class invariants
7.1.11 History invariants
7.1.12 Storable classes

7.2 Constructors
7.3 Derived abstract classes

7.3.1 Inheriting another abstract class
7.3.2 Overriding inherited declarations
7.3.3 Accessing overridden members
7.3.4 Deferred abstract classes

7.4 Class templates

8. Implementations and Proof Lists

8.1 Overview
8.2 Syntax of implementations

8.2.1 Declarations
8.2.2 Let-statement
8.2.3 Postcondition statement
8.2.4 Labels
8.2.5 Jumps
8.2.6 Loops
8.2.7 Assertions
8.2.8 Conditional statement
8.2.9 Block statements
8.2.10 Value completors
8.2.11 State completors
8.2.12 Throw statements
8.2.13 Try statements

8.3 Proof lists

9. Scopes, Overloading and Binding

9.1 Overview
9.2 Name spaces
9.3 Definition of the various declaration contexts
9.4 Overloading class and type names
9.5 Overloading variable and function names
9.6 Overloading operator and selector symbols
9.7 How binding is defined in Perfect
9.8 Uniting and Core
9.9 Definition of the general dictionary for various regions

9.9.1 Global declaration list
9.9.2 General dictionary for declarations of functions, operators and selectors
9.9.3 General dictionary for declarations of schemas
9.9.4 General dictionary for declarations of constructors defined using a result expression
9.9.5 General dictionary for declarations of constructors defined without using a result expression
9.9.6 General dictionary for implementations
9.9.7 General dictionary for the inherits-part of a class declaration
9.9.8 General dictionary for member declaration regions of a class declaration
9.9.9 Bracketed expressions
9.9.10 Expressions involving bound variables

9.10 Class member dictionaries
9.11 Access restrictions
9.12 Forward referencing and references to declarations in imported files

10. Interface to other languages

10.1 Overview
10.2 Local pragmas
10.3 Global pragmas

11. Library overview

11.1 Order and sorting
11.2 Input/Output

11.2.1 Console input / output
11.2.2 File operations
11.2.3 Disk operations
11.2.4 Opening sockets
11.2.5 Other environment methods
11.2.6 Runtime checks and profiling

11.3 Debugging functions
11.4 Streams
11.5 Serialization
11.6 Character encoding and decoding

12. Application Startup and Initialization

12.1 Program entry point written in Perfect
12.2 Program entry point not written in Perfect

Appendix A: Library Reference

A1. Global methods

debugPrint
debugHalt
flatten
interleave
loadObject
max
min
storeObject
swap

A2. Classes

anything
bag of X
bool
byte
ByteData
ByteInputStream
ByteOutputStream
char
CharDecoder
CharEncoder
CharEncoderDecoder
Comparator of X
DebugType
Environment
FileAttribute
FileError
FileHandle
FileInputStream
FileMode
FileModeType
FilePath
FileStats
FileOutputStream
GuardedObject of X
InputStream
int
map of (X -> Y)
nat
OsInfo
OsType
OutputStream
pair of (X, Y)
rank
real
ReverseComparator of X
seq of X
SerialError
SerialErrorType
set of X
SimpleComparator of X
SocketError
SocketMode
StandardInputStream
StandardOutputStream
Storable
string
Time
triple of (X, Y, Z)
void

Appendix B: LALR(1) Grammar

B1. Introduction
B2. Grammar

 

Perfect Language Reference Manual, Version 7.0, February 2017.
© 2017 Escher Technologies Limited. All rights reserved.