next up previous contents
Next: Procedure calls in Up: CHAPTER.2: INTRODUCTION TO Previous: Procedure definitions are

Global and local procedure definitions

Where a procedure is to be accessible only within another procedure, or only within a file, its name can be made into a lexical identifier, e.g.

    define lvars silly(item);
        item =>  item =>
    enddefine;
Or if there is no requirement ever to be able to change the value of silly to be another procedure, or anything else, then it can be defined as a lexical constant, as in:

    define lconstant silly(item);
        item =>  item =>
    enddefine;
Warning: If you define a procedure using lvars or lconstant like this, you will not be able to test it by typing in commands using it. You can invoke it only by calling other global procedures that call these procedures, and are compiled in the same "lexical context". E.g.

    define lconstant silly(item);
        item =>  item =>
    enddefine;

    define test_silly(item);
        [^item is about to be given to silly] =>
        silly(item);
    enddefine;
If, in the editor, you mark and load both of those at the same time, then test_silly can be used to run silly:

    test_silly([hello there]);
    ** [[hello there] is about to be given to silly]
    ** [hello there]
    ** [hello there]
But if you redefine silly you will have to recompile test_silly also, as they have to be compiled in the same compilation stream for test_silly to access the lexically scoped silly.



Aaron Sloman
Fri Jan 2 03:17:44 GMT 1998