2013/9/9 Dmitry Bogatov <kact...@gnu.org>

>
> Hello!
>
> 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:

http://hg.gnu.org.ua/hgweb/slayer/file/554a63bd3c6c/guile-modules/extra/common.scm#l420

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,
M.

Reply via email to