[plt-scheme] Re: Novice question: evaluating symbols

From: Eli Barzilay (eli at barzilay.org)
Date: Sun Jan 10 02:17:18 EST 2010

On Jan  9, Laurent wrote:
> For the sake of it, here it is (yes, with `apply'):
> [...]

So, as I suspected, your problem was independent of `defmacro', and
doing this exercise would have made that clear.

> My main problem is that `syntax-rules', `syntax-case', `with-syntax'
> and others that I have not used yet use the syntax in quite
> different ways, and sometimes you have to #' and sometimes you have
> to (syntax->datum ....) and sometimes not. I have a hard time to
> know when to use the right one at the right time (the docs are a bit
> obscure on these points).  Whereas in `defmacro', I know exactly
> when to use `quote' and `unquote'.

Using `define-syntax' is practically the same -- it just uses syntax
objects instead of "plain" datums.  This means that there's an extra
layer to dig through if you want to do some games like create your own
identifiers -- and this extra layer is needed because it's how you get
complete control over the lexical scope of the macro results.
`defmacro' is kind of like throwing plain symbols around and hoping
that the scope will be right -- and in almost all cases the scope is
only partially right.

[It takes a while to run into cases where it's not right -- and once
you get burned by that you gain important insight on why hugiene is
important.  As someone pointed out earlier, the fact that the defmacro
version uses whatever `define' happens to be in the scope of the macro
use is a good example for that -- all it takes is a language with
different semantics for `define', and the `defmacro' version will fall
apart in surprisingly hard to debug ways.]

> Wouldn't it be possible to define "safe" quotes and unquotes for
> syntax macros, without having to go from syntax to datum and
> vice-versa at weird places? [...]

I don't think so.  (And like Matthias said, if there is some way to do
that, it hasn't been discovered yet.)

This is also relevant here:


          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.