[racket] for/hash: bad syntax in: for/hash

From: Marijn (hkBst at gentoo.org)
Date: Wed Jan 4 04:57:12 EST 2012

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 03-01-12 20:15, Eli Barzilay wrote:
> Two hours ago, Marijn wrote:
>> Hi,
>> 
>> for/hash is giving me a syntax-error, but the error is in 
>> macro-expanded code which is not shown by default and which is
>> also seemingly inaccessible via the macro-stepper. The for/hash 
>> expression works outside my macro, so I guess it's my fault, but
>> it would help if the syntax-error could be a bit more
>> informative. The code: [...]

Thanks for taking the time to look into this.

> 4. It's now easy to continue reducing it to the core of the
> problem:
> 
> (define-syntax with-variables (syntax-rules () ((_ (a ...))
> ((with-variables a) ...)) ((_ a) a))) (with-variables (let* ((y 1))
> 2))
> 
> Looks like you're doing a code walk (which is what makes me think 
> that this is too complex for whatever it is you're trying to do), 
> and treat some names in a special way.  The problem is that
> 
> ((with-variables a) ...)
> 
> is creating a function application so the error is the same as
> just entering `let*' to get its value -- and the only error that it
> can throw at this point is a "bad syntax" with the whole
> expression, which is just `let*'.

It took me a while to understand what you're saying here, but if I am
not mistaken you're saying that the result of the macro-expansion is a
function-application with `let*' (or `for/hash') in the function
position. Then when #%app looks that name up in the environment it
doesn't find anything and thus complains about it. What I would then
expect is that it complains about an undefined variable `let*'.

> 5. And BTW, the reason it doesn't work is that the first expansion 
> gets to
> 
> ((with-variables let*) (with-variables ((y 1))) (with-variables
> 2))
> 
> and this form is not a macro -- so it's expanded as a function 
> call,
> 
> (#%app ...same...)
> 
> and the rest is obvious.

It's not so obvious to me why this should degenerate into a function
call; I'd say it depends on the result of (with-variables let*).

Marijn

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8EIngACgkQp/VmCx0OL2xmkQCgq6Zc2D3I8AwyFeHJra6d3fTh
tOYAoJ++S7Gpq2XnLFOflL2qIfWgwXsR
=9TxG
-----END PGP SIGNATURE-----


Posted on the users mailing list.