[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Me no understand scoping

From: Clinton Ebadi
Subject: Re: Me no understand scoping
Date: Tue, 29 Jul 2008 23:24:59 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

"Maciek Godek" <address@hidden> writes:

> Hi,
> consider the following code (simple iteration
> construct invented mainly to cause naming
> conflict, as the function 'times' is already
> defined in guile)
> (define-macro (times n f)
>   `(let ((env (the-environment)))
>      (let loop ((i 0))
>        (if (< i ,n)
>            (begin
>              (local-eval ,f env)
>              (loop (1+ i))
>              )
>            )
>        )
>      )
>   )
> the whole thing with env was made as
> a workaround disallowing f to see the
> i variable defined in the macro (and to
> perhaps see the value that otherwise
> would be shadowed)
> however,
> (times 20 (display i))
> yields
> 012345678910111213141516171819
> Why?

`macroexpand-1' is helpful here -- (local-eval ,f env) is wrong.

As a matter of style, you probably want to avoid local-eval as it will
have to be removed whenever Guile ends up with a faster compiler (one
day when guile-vm is integrated into core and lexical environments
become fixed arrays or similar), and messing with existing lexical
environments is Very Bad (tm). Avoiding all uses of eval and, by
extension, local-eval is a good idea.

The hubbub of the waking life might close a door 
which in the dreamy Subliminal might remain ajar...

reply via email to

[Prev in Thread] Current Thread [Next in Thread]