[racket] Formal Presentation and initial doubts.

From: Konrad Hinsen (konrad.hinsen at fastmail.net)
Date: Sat Mar 22 07:15:28 EDT 2014

--On 22 mars 2014 04:18:03 -0400 Neil Van Dyke <neil at neilvandyke.org> wrote:

> One tip for writing macros: make your transformer pattern variables be
> all-uppercase.  This convention makes reading and writing macros much
> easier for humans, and also less confusing to learn (because people
> seeing examples are less confused over what is a pattern variable and
> what is a normal Racket variable).

That sounds like very useful advice, but does anyone follow it? I haven't 
seen this convention used in any Racket macros I looked at.

A few words on this from my own experience coming to Racket from a Clojure 
background. For those not familiar with Clojure, its macro system is pretty 
close to Common Lisp, with a few interesting and useful differences that I 
won't go into here.

My experience is that Racket macros are way more powerful if you want to do 
a serious job. Doing a serious job means writing macros that behave like 
syntax features of a language. It means in particular that macros should do 
syntax checking and report errors in an understandable way. In the Clojure 
(and CL) world, few macros do syntax checking at all, and those that do 
just give up in case of an error, with a message that becomes clear only 
after one reads the macro source code.

Unfortunately, that power comes with a steep learning curve, which isn't 
helped by the lack of good tutorials. The Racket documentation is perfectly 
clear and complete, but it requires a serious motivation.

The biggest problem I had in practice was exactly with pattern variables, 
so I really like your advice given above. It is important to keep track of 
each symbol's status, pattern variable or plain bound symbol, in order to 
understand a syntax-parse macro.


Posted on the users mailing list.