chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] ANN: eping


From: John Cowan
Subject: Re: [Chicken-users] ANN: eping
Date: Thu, 22 Aug 2013 10:54:44 -0400
User-agent: Mutt/1.5.20 (2009-06-14)

Michele La Monaca scripsit:

> How can I check if a symbol is bound to a value?

By using eval and trapping any error, as you mention below, but that's
not to the purpose here.  You are trying to do with macros what macros
cannot do.

> (define-syntax eping
>   (syntax-rules ()
>     ((_ h)
>      (if (and (symbol? 'h) (bound? 'h))
>        (_eping h)
>        (_eping (symbol->string '|h|))))))

Like your earlier macro that attempts to remap h to |h|, this one won't
quite work, because the difference between h and |h| disappears in the
reader, and the macro engine never sees it.  192.168.0.1 is simply not
valid Scheme lexical syntax, and nothing you can do at the macro level
will make it so: it so happens that Chicken processes it as a symbol,
but that's an artifact of the implementation.

Similarly, a macro like this will not work either, as should be apparent:

(define-syntax hex
  (syntax-rules ()
    ((hex n) #xn)))

This is an attempt to make (hex 10) expand to 16.  But 10 is 10, and
#xn is just a lexical syntax error.

Your macro will work as far as handling bound and unbound symbols; of
course, symbols *lexically* bound will not be seen, only global symbols.
That's the nature of Scheme's eval.

You should go and read "JRM's Syntax-rules Primer for the Merely
Eccentric" <http://www.phyast.pitt.edu/~micheles/syntax-rules.pdf> to
get a feel for what syntax-rules macros can and cannot do.  Just stop
reading when you no longer follow the text: that means you've absorbed
as much as you can for now.  When you need more, go back to it.

-- 
Time alone is real                      John Cowan <address@hidden>
  the rest imaginary
like a quaternion       --phma          http://www.ccil.org/~cowan



reply via email to

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