[Top][All Lists]

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

Re: Syntax-rules generate symbol

From: Taylan Ulrich B.
Subject: Re: Syntax-rules generate symbol
Date: Mon, 09 Sep 2013 22:03:43 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (berkeley-unix)

Panicz Maciej Godek <address@hidden> writes:

> 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:
> 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.

For anyone who didn't know, "breaking" to arbitrary places is made
simple (and efficient) with `let/ec' from the module (ice-9 control), a
wrapper around `call-with-escape-continuation':

(let/ec break
  (display "foo\n")
  (display "bar\n"))

displays only foo.
One can return any number of values of course:

(let-values (((foo bar baz)
              (let/ec return
                (display "what should I return?\n")
                (return 1 2 3))))
  (+ foo bar baz)) ;=> 6

(`let-values' is in SRFI 11.)

An "escape" continuation cannot be "re-entered" after it returns once,
making the following usage invalid, but thus the implementation very

(let ((re-enter #f))
    (let/ec display-this
      (set! re-enter display-this)
      (display-this "foo\n)))
  (re-enter "infinite foos!\n"))

If we used call/cc, that would loop infinitely displaying "infinite
foos!" (after the first "foo"), but with the escape continuation we just
get an error after displaying the first "foo", because once we return
from the escape continuation we can't call it anymore even if we store
it somewhere.

reply via email to

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