[Omake] Scoping

Nathaniel Gray n8gray at caltech.edu
Wed Nov 8 20:22:50 PST 2006


Jason Hickey wrote:
> 
> 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.

I thought I understood the scoping rules, but I don't understand why 
this works:

OCAMLINCLUDES += foo/bar
x = $(OCamlProgram a, b)

but when you substitute this:

FancyOCamlProgram(a, b)
	OCAMLINCLUDES += foo/bar
	return $(OCamlProgram $(a), $(b))
x = $(FancyOCamlProgram a, b)

You don't get "-I foo/bar" in the arguments to ocamlc.  Isn't the 
(re-)definition of OCAMLINCLUDES the closest dynamically-scoped 
definition during the call to OCamlProgram?

> 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

I think my example wasn't clear enough.  The idea is that I want to 
define a function that wraps a library function (OCamlProgram), adding 
some extra compiler flags.

Cheers,
-n8

-- 
 >>>-- Nathaniel Gray -- Caltech Computer Science ------>
 >>>-- Mojave Project -- http://mojave.cs.caltech.edu -->


More information about the Omake mailing list