"Maciek Godek" <[EMAIL PROTECTED]> 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...
