[gambit-list] Proposal for lightweight real hygienic macros in Gambit

Marijn hkBst at gentoo.org
Mon Mar 26 12:01:36 EDT 2012


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

Hi Per,

On 20-03-12 20:34, Per Eckerdal wrote:

> Gambit and hygienic macros
> 
> Gambit ships with a generic implementation of syntax-case hygienic
> macros, psyntax, but in practise it does not work very well,
> especially in conjunction with features that are specific to
> Gambit.

Indeed.

> Proposal
> 
> This is more of a straw man than a proper proposal, and I am fully
> aware that this will probably conflict with many ideas that R7RS
> introduces.
> 
> This proposal is about a way of achieving hygienic macros that is
> far more lightweight than any other hygienic Scheme macro system
> that I know of. In fact, Gambit already includes most of the
> machinery that is required by this system.
> 
> I did not invent this technique myself. The basic idea is described
> here: http://www.p-cos.net/documents/hygiene.pdf

According to that paper, symbol macros aka identifier macros are
needed to make this work.

> Restrictions on name binding
> 
> For hygiene to work, shadowing bindings must be disallowed. This
> code snippet illustrates the problem:
> 
> (let ((a 0)) (define-macro (mac name) `(list ,(alias a) ,name)) 
> (let ((a 1)) ;; This should return (0 1), but it will return (1
> 1). (mac a)))
> 
> 
> To make this possible, defining a name that is already defined must
> be disallowed. I would make it a compilation error.

Almost stopped reading after that last sentence there!

> Auto-aliasing bindings

Fortunately then my eye caught sight of the below and I continued
reading...

> The restriction of not being allowed to bind a name that's already
> bound is clearly too limiting; we want the code above with the two
> |a|s to work.

> I would love to hear what you think about this.

I would be interested in knowing how this proposal compares with
implementing a low-level hygienic macro system such as syntactic
closures or explicit renaming macros. Actually now that I said that
this proposal sounds very much like a (partial?) implementation of
explicit renaming macros on top of the defmacro system. Doesn't the
paper you referenced mention something like that as well?

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

iEYEARECAAYFAk9wkuAACgkQp/VmCx0OL2xduACffyOklmF0q1jziiB2pPn1OjHM
tREAn1dD+TFTyV3D+yvH54dsMh1PbMde
=8xwU
-----END PGP SIGNATURE-----



More information about the Gambit-list mailing list