Oberon-2 (programming Language) - Example Oberon-2 Code

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:

    Hollywood keeps before its child audiences a string of glorified young heroes, everyone of whom is an unhesitating and violent Anarchist. His one answer to everything that annoys him or disparages his country or his parents or his young lady or his personal code of manly conduct is to give the offender a “sock” in the jaw.... My observation leads me to believe that it is not the virtuous people who are good at socking jaws.
    George Bernard Shaw (1856–1950)