Pascal: A Brief History
Pascal was defined in 1970 by Prof. Niklaus Wirth, in a very successful attempt to find an evolutionary successor to Algol. Pascal cleaned up and left out some of Algol's more obscure features, and, in addition, added the capability to define new data types out of simpler existing ones and introduced support for dynamic data structures.
When Wirth and the Swiss Federal Institute of Technology released a Pascal compiler that produced a simple intermediate code for a virtual machine (P-code), instead of true native code for a particular machine, a giant was born. This simplified porting Pascal to other processor architectures considerably, because only a new P-code interpreter needed be written for this purpose, not a whole new compiler.
What people began to find was that Pascal didn’t require a large mainframe, but rather, that it would run on the, then new, Apple II personal computers. This advance, and Pascal’s compact approach, paved the way for high school teachers and professors around the world to embrace Pascal as a teaching language.
Since then, with the release of Turbo Pascal, and other similar products, Pascal has remained a staple in the world of programming languages, and because of this, Pascal has greatly influenced the design and evolution of many other languages, from Ada to Visual Basic.
Scope and Binding Rules
- Statically (lexically) scoped
- Follows Closest Nested Scope Rule - a name that is introduced in a declaration is known in the scope in which it is declared, and in each internally nested scope, unless it is hidden by another declaration of the same name in one or more nested scopes
- Deep Binding
Type System
- Basic Types: char, integer, real, boolean, text
- Type Constructors: arrays, records
- Allows arrays to be constructed from any discrete index type and component type.
- Pascal is more orthogonal than that of Fortran (pre-Fortran 90)
- Several non-orthogonal properties:
- Requires that variant fields of a record follow all other fields
- Limits function return values to scalar and pointer types
- Requires the bounds of each array to be specified at compile time except when the array is a formal parameter subroutine.
- Does not provide true subroutine types: a subroutine cannot be returned by a function or stored in a variable (though subroutines can be passed as params)
- Pascal is nearly strongly typed
Memory Management
- Heap-Based Allocation (dynamic memory allocation)
- dynamic storage in Pascal is referenced by pointers, not names.
- Garbage Collection: It is up to the programmer to use “dispose” to release heap storage when it is no longer needed.
Call Mechanisms
- Parameters are passed by value by default
- They are only passed by reference if preceded by the keyword var in their subroutine header’s formal parameter list.
Evaluation Strategy
- eager strategy: all args evaluated before function is invoked.
Pointers
- Pointers are restricted to only objects in the heap
- The only way to create a new pointer value (without using variant records or casts) is to call a built-in function that allocates a new object in the heap, and returns a pointer to it.
- Pointers are a “First Class” Type (can be returned from a subroutine, passed as a parameter, or assigned into a variable)
High-Order Functions
- Functions are NOT a “First Class” Type
- They are a “Second Class” Type, as they can be passed as a parameter, but not returned by a function, or stored in a variable.
Compilation
- Pascal is a compiled language
Does Not Support
- Nondeterminism
- Polymorphism
- Concurrency
- Object/Class extraction
Intended Use
- Has been widely used for teaching, as it is relatively compact, and easy to learn.
Assertions, Invariants, and Pre/Post Conditions
- Pascal Supports assertions, invariants, and pre/post conditions.
Example Program 1:
program binding_example (input, output)
procedure A (I : integer; procedure P);
procedure B;
begin
writeln (I);
end;
begin (* A *)
if I > 1 then
P
Else
A (2, B);
end;
procedure C; begin end;
begin (* main *)
A (1, C);
end.
This prints 1, as Pascal has deep binding and static scoping. With shallow binding, it would print a 2.