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:

    Wise Draco comes, deep in the midnight roll
    Of black artillery; he comes, though late;
    In code corroborating Calvin’s creed
    And cynic tyrannies of honest kings;
    He comes, nor parlies; and the Town, redeemed,
    Gives thanks devout; nor, being thankful, heeds
    The grimy slur on the Republic’s faith implied,
    Which holds that Man is naturally good,
    And—more—is Nature’s Roman, never to be
    scourged.
    Herman Melville (1819–1891)