[Top][All Lists]

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

Re: Syntax-rules generate symbol

From: Panicz Maciej Godek
Subject: Re: Syntax-rules generate symbol
Date: Mon, 9 Sep 2013 18:59:06 +0200

2013/9/9 Dmitry Bogatov <address@hidden>


Here is my implementation of for loop. I found lisp really extremely
flexible, but there is one problem --- more often then not I do not need
var part, so I do not care how it would be named --- all I care is that
it will not shadow any other bindings.

I think I can do it(did not tryed it) with `define-macro` and uninterned
symbols, but it mean give up beauty of syntax-rules.

Masters of syntax-rules and syntax-case, please give me peace of advice.

(define-syntax for
    (syntax-rules (in => as)
        ([_ (pattern as var in list) exp ...]
         [for-each (lambda (var) (match var (pattern exp ...))) list])))
Actually, the whole point of hygienic (syntax-rules) macros
is that you don't need to worry about the names of variables.

I often use a very similar python-like for loop macro in my projects:

That code works just perfectly fine.

IMO a bigger problem would be to break the referential
transparency, so e.g. the definition like

(define-syntax for
  (syntax-rules (in => break)
    ((_ pattern in list body ...)
     (call/cc (lambda(break)
                  (for-each (match-lambda pattern body ...) list))))))

won't work as one might expect (i.e. you won't be able to write
(break) inside a loop, because the "break" label gets renamed).
The workaround is possible somehow, but I never had time to
figure that out, so currently I just don't do breaks ;]

Best regards,

reply via email to

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