------------------------------------------------------------------------------
MC logo
Dyn Link Example
[^] Functions
------------------------------------------------------------------------------
[Ch. 1: Overview and History] [Syntax] [Names and Scope] [Types and Type Systems] [Semantics] [Functions] [Memory Management] [Imperitive Programs and Functional Abstraction] [Modular and Class Abstraction] [Functional Programming] [Logic Programming]
[Call-by-Reference] [Call-by-Value-Result] [Call-by-Name] [Dyn Link Example] [Dyn Link Example] [C++ Translation of Java Dyn Link] [Variable Location] [Parameter Passing Method Exercise]
callex.pas
PROGRAM passer(input, output);
    VAR
        a, b: integer;
    PROCEDURE fred(VAR b: integer);
        BEGIN
            a := a + b;
            b := 4;
        END;

    PROCEDURE barney(c: integer);
        VAR
            a: integer;
        PROCEDURE sigfreid;
            BEGIN
                fred(a);
            END;
        BEGIN
            a := c;
            sigfreid;
            writeln(a, ' ', b, ' ', c);
        END;
    BEGIN
        a := 2;
        b := 7;
        barney(3);
        writeln(a, ' ', b);
    END.

Output is:
4 7 3
5 7