[Omake] Scoping

Jason Hickey jyh at cs.caltech.edu
Mon Nov 6 21:21:17 PST 2006


On Nov 6, 2006, at 6:36 PM, Nathaniel Gray wrote:
> Can somebody explain why these two things are not the same:
> === Thing1: ===
> 	Thing(name) =
> 		BLAH = yes
> 		return $(MakeThing $(name))
> 	thing = $(Thing foo)
>
> === Thing2: ===
> 	BLAH = yes
> 	thing = $(MakeThing foo)

Variables are defined from the point of the definition to the end of  
the scope containing the definition.  In addition, binding is dynamic  
and the language is pure except for I/O.  So for Thing1, the extent  
of the definition of BLAH is the body of the function; for Thing2 it  
is to the end of the file.

A function body defines a scope, but so does any indented block.  The  
export command can be used to export definitions from an inner  
scope.  So here are two other ways to do what you want (see also  
http://omake.metaprl.org/omake-language.html#htoc38).

    thing =
        BLAH = yes
        MakeThing(foo)

    section
        BLAH = yes
        thing = $(MakeThing foo)
        export thing

Jason

--
Jason Hickey                  http://www.cs.caltech.edu/~jyh
Caltech Computer Science      Tel: 626-395-6568 FAX: 626-792-4257





More information about the Omake mailing list