chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] unbound variable: or


From: John Cowan
Subject: Re: [Chicken-users] unbound variable: or
Date: Fri, 29 May 2015 22:23:03 -0400
User-agent: Mutt/1.5.20 (2009-06-14)

Jinsong Liang scripsit:

> I want to learn some basic macro programming in Chicken. However, it seems
> there are multiple macro definition APIs in Chicken: define-syntax,
> syntax-rules, syntax-case, define-macro. Which one should I start with?

Define-macro is completely obsolete and not supported in Chicken 4 or
any modern Scheme.

Define-syntax is a general wrapper for defining macros like this:

(define-syntax <name> (<transformer> <whatever>))

This defines a macro named <name> using the syntax transformer
<transformer>.  The syntax and semantics of <whatever> depend on the
symbol used for <transformer>.

Define-syntax corresponds to define and can be written in the same
places.  You can also define local macros (like local variables) by
using let-syntax or let-syntax*, which correspond to let and let*.

Chicken supports three syntax transformers:  syntax-rules,
er-macro-transformer, and ir-macro-transformer.  The abbreviations "er"
and "ir" stand for "explicit renaming" and "implicit renaming".  It does
not support syntax-case, sc-macro-transformer ("syntactic closure"),
or rsc-macro-transformer ("reverse syntactic closure"), though they are
supported by other Schemes.

Syntax-rules is the most widely supported, the easiest to use, and
the most idiot-proof, though not the most powerful.  The other syntax
transformers are more powerful but also more dangerous.

> Also, I have heard that, different from Lisp, macro programming in Scheme
> is not recommended. Is it true?

Procedures provide new run-time function, whereas macros provide new
syntax forms to extend the basic set (if, cond, set!, lambda, etc.)
They serve different roles.

But in general, you should write a procedure if you can.  If not, use a
syntax-rules macro.  Only if a syntax-rules macro is insufficient should
you use an implicit-renaming macro, and only if that is too slow should
you use an explicit-renaming macro.

Googling for "syntax-rules" will point you to a lot of basic tutorials.
When you want something more advanced, look for "JRM's Syntax-rules
Primer for the Mildly Eccentric".  Read that until you have trouble
understanding it; you now know as much as you can absorb.  Go back to
it later when you need more.

-- 
John Cowan          http://www.ccil.org/~cowan        address@hidden
Half the lies they tell about me are true.
        --Tallulah Bankhead, American actress



reply via email to

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