[gambit-list] why does load/include work differently for this

lowly coder lowlycoder at huoyanjinjing.com
Sat Aug 15 04:51:02 EDT 2009


I don't quite get this. There are no free variables in lookup-var.

On Sat, Aug 15, 2009 at 1:19 AM, Adrien
Piérard<pierarda at iro.umontreal.ca> wrote:
> My bad.
> The reason is (a little bit) different.
>
> LOAD does not access the same current environment when in a macro.
> It loaded the file in a fresh environment, where x was indeed unbound.
>
> A simpler example is
>
> $ cat tata.scm
> (define (f x)
>  (+ y x))
>
> $ cat toto.scm
>  (define-macro (foo)
>  (define y 1)
>  (load "tata")
>  (pp (f 3)))
> (foo)
>
> $ gsi toto.scm
> *** ERROR IN f, "tata.scm"@2.6 -- Unbound variable: y
>
>
> The solution?
> Refactor all your code.
> I really believe that you are doing things with macros that should be
> done some other way…
>
> P!
>
> 2009/8/15 lowly coder <lowlycoder at huoyanjinjing.com>:
>> They're loading/including the same function. Then I execute them, and
>> I get different results. Isn't that kind of weird? If you loaded or
>> included a function for +, wouldn't you expect it to give you the same
>> results?
>>
>> On Sat, Aug 15, 2009 at 12:28 AM, Adrien
>> Piérard<pierarda at iro.umontreal.ca> wrote:
>>>> note that lookup-var is just a function ... i'm surprised that
>>>> load/include gives me different results
>>>
>>> Why are you surprised?
>>> If two functions exist, then they do two different things.
>>>
>>> The fact is that LOAD is a function (eval'd at runtime, as one
>>> explained you), and that INCLUDE is not.
>>> Include is a reader-macro. When the parser sees an INCLUDE, it parses
>>> the source code of the other file, and then inserts it instead of that
>>> form.
>>>
>>> No magic here.
>>>
>>> P!
>>>
>>>
>>> --
>>> Français, English, 日本語, 한국어
>>>
>>
>
>
>
> --
> Français, English, 日本語, 한국어
>



More information about the Gambit-list mailing list