Enumerations in Turbo Pascal type Colours = (Red, White, Blue);
Enumerations in Go type Colours int
const (
Red Colours = iota
White
Blue
)
FFI in Turbo Pascal function Sin(const num: Integer): Double; external 'ext name';
FFI in Go (requires external help from a C compiler) // #include <stdio.h>
// #include <errno.h>
import "C"
func Sin (num uint) float32 {
return C.sin
}
Reference parameters in Turbo Pascal with null safety thanks type system procedure Swap(var a,b:Integer);
var
temp: Integer;
begin
temp:=a;
a:=b;
b:=temp
end;
Swap(x, y)
Swap(nil, y) { compiler error: Got "Pointer" expected "SmallInt" }
Reference parameters in Go (no type safety via type system, manual testing for nil required) func Swap (a *int, b*int) {
var temp = *a
*a = *b
*b = temp
}
Swap(&x, &y)
Swap(nil, &y) { runtime error: Invalid memory address or nil pointer dereference }
I was also tempted to move the time scale from 1992 to 2009, but then I wouldn't be able to reproduce the generics from Object Pascal in Go.Ah, and Turbo Pascal 5.5 was compiling around 34 000 lines/minute in computers whose CPUs were maxed at about 30 MHZ, http://edn.embarcadero.com/article/20803 |
Regarding nil safety, did Pascal allow something along the line of the following?