Example Oberon-2 Code
The following Oberon-2 code would implement a very minimal list class:
MODULE Lists; (*** declare global constants, types and variables ***) TYPE List* = POINTER TO ListNode; ListNode = RECORD value : Integer; next : List; END; (*** declare procedures ***) PROCEDURE (l : List) Add* (v : Integer); BEGIN IF l = NIL THEN NEW(l); (* create record instance *) l.value := v ELSE l.next.Add(v) (* recursive call to .add(n) *) END END Add; PROCEDURE (l : List) Get* : Integer; VAR v : Integer; BEGIN IF l = NIL THEN RETURN 0 (* .get must always return an INTEGER *) ELSE v := l.value; (* this line will crash if l is NIL *) l := l.next; RETURN v END END Get; END Lists.Read more about this topic: Oberon-2 (programming Language)
Famous quotes containing the word code:
“Many people will say to working mothers, in effect, I dont think you can have it all. The phrase for have it all is code for have your cake and eat it too. What these people really mean is that achievement in the workplace has always come at a priceusually a significant personal price; conversely, women who stayed home with their children were seen as having sacrificed a great deal of their own ambition for their families.”
—Anne C. Weisberg (20th century)