Manual |
|
Introduction |
|
1. INTRODUCTION
1.1 What is Seed7?
Seed7 is a general-purpose programming language. It is a higher level language compared to Ada, C++ and Java. In Seed7 new statements and operators can be defined easily. Functions with type results and type parameters are more elegant than the usual template or generics concept. Object orientation is used when it brings advantages and not in places when other solutions are more obvious. Although Seed7 contains several concepts of other programming languages it is generally not considered as a direct descendant of any other programming language.
The programmer should concentrate on problem solving instead of administration or the fulfillment of some paradigm. Therefore Seed7 allows programming in the "problem space" instead of bending everything into a small syntactic or semantic concept. The predefined constructs of Seed7 are defined in a way to be easy readable and understandable. This practical approach can be summarized as:
Programming should be fun
Seed7 programs can be interpreted or compiled. Therefore Seed7 can be used for scripting and for "real" programs.
1.2 Why a new programming language?
Conventional programming languages have a firmly given syntactic structure. The form of the statements, operators, declarations, procedures and functions is fixed in the language definition and cannot be changed by the user. It is only possible to declare new procedures, functions and in some languages also new operators. However the syntax of procedure, function and operator calls cannot be changed. Although this rigid pattern is favorable for the portability of programs, the improvement of the programming language is almost impossible. Extensions are however desirable, in order to repair existing weaknesses, to introduce new more obvious constructs and to adapt the programming language to different application areas. E.g.: In the area of mathematics the readability of a program can be substantially increased by the introduction of matrix and vector operators. After declaring an inner product and an outer (or cross) product for vectors it is possible to write e.g.
v1: = v2 cross v3; write(v1 * v2);
Programs which search for some data in a database can become more understandable by using a for statement to loop over the tables. A usage of such a for statement could be:
for person1, person2 where person1.age = person2.age and person1.mother = person2.mother and person1 <> person2 do writeln("Twins: " <& person1.name <& " and " <& person2.name); end for;
Such extensions make understanding, changing and debugging of a program easier.
1.3 Features of Seed7
Seed7 has the following features
- User defined statements and operators.
- Types are first class objects and therefore templates and generics can be defined easily without special syntax.
- Predefined constructs like arrays or for-loops are defined in the language itself.
- Object orientation is based on interfaces, supports multiple dispatch and allows to connect methods to objects.
- Static type checking and no automatic casts.
- There is exception handling
- There are checks for array indices and integer overflow.
- Overloading of procedures/functions/operators/statements
- Various predefined types like resizable arrays, hashes, bitsets, structs, etc.
But a new programming language differs not only from existing ones by new features. The real advantage comes from omitting features which are outdated.
Several concepts in use by other languages are not present
- There is no Null.
- There is no goto statement. Hidden gotos like break- and continue-statements are also omitted.
- There is no return statement. Instead a result variable can be defined to which the result of a function can be assigned.
- There are no automatic type conversions. When a subprogram should be used for different types it must be overloaded.
- There is no implicit fall-through for control flow as in the switch statement of C.
- There is no undefined behavior.
- There is no manual memory management.
- There is no "do what I mean" heuristic, where the compiler tries to read the programmers mind.
- There is no preprocessor to accommodate for language features that should exist by default.
- There are no variable length parameter lists. Instead it is possible to use arrays as parameters.
- There are no default parameters. But it is easy to define two subprograms: One with and one without an additional parameter.
- There is no special "parameter" called "self" or "this". In a procedure the receiving object is defined as formal parameter with a user-defined name.
- There is no macro feature since this mechanism is too similar to the subprogram feature. Instead subprograms can be used in a more flexible way than in other languages.
- There are no reserved words.
- There is no conceptual distinction between functions, operators, procedures and statements.
- The procedure calling mechanism is not based on a concept with an object-message pair (An object receives a message). Instead a match is done over a list of objects. This more general (and powerful) mechanism is called multiple dispatch and it includes the simple object-message mechanism as special case.
There are several concepts which are also used by other languages:
- Block comments start with (* and end with *) and may be nested.
- Line comments start with # and are terminated with the end of the line.
There are several concepts which are new
- Variables and constants must be initialized when they are defined.
- Every expression has exactly one type. That means that overloaded functions are resolved with their actual parameters and not with the context of their call. (This is different to the overloading mechanism used by ADA)
- With a syntax declaration new operators and statements can be defined.
- Not only predefined operator symbols can be overloaded. Additionally it is possible to invent completely new operator symbols.
Several restrictions of other languages are released
- There is no limitation in the length of an identifier and all characters of an identifier are significant.
- Statements and parentheses can be nested without limitation in depth.
- The number of parameters and local variables is not limited.
- Strings can contain any characters (also the NUL character) This allows holding binary information in strings.
- Although strings are not NUL terminated they have no size limitation. (Except there is no more memory)
- String literals can have any length.
- There is no limitation in the length of a source line.
- There is no level limitation for nesting includes.
1.4 How to read the manual
You can have several views of the Seed7 programming language. Dependent on the view you can concentrate on specific chapters.
For example Seed7 can be used as conventional programming language. In this case you are interested in how the statements look like, which types are available, which operators are predefined, how to declare variables and procedures and other things like these. The statements and the predefined types are described in chapter 4 (Predefined statements) and chapter 5 (Predefined types) and the declaration mechanism is described in chapter 3 (Declarations).
But Seed7 is also an object oriented programming language. In this case you are interested in how to define new classes, how instances are generated, the method calling mechanism, the predefined class hierarchy and other things like these. The object orientation of Seed7 is described in chapter 7 (Object orientation). A good example for classes and instances is the file system which is described in chapter 8 (The file system).
And Seed7 is also an extensible programming language. In this case you are interested in how to declare new statements, how to define new operators, assigning a priority and an associativity to operators and other things like these. An overview about syntax declarations can be found in Chapter 3.2 (Syntax declarations). A detailed description of the Seed7 syntax definitions can be found in chapter 9 (Structured syntax definition). Chapter 4 (Predefined statements) contains various examples of syntax and semantic declarations. The basic parts of the syntax are described in chapter 10 (Tokens) and chapter 11 (Expressions).
|
|