unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: taylanbayirli@gmail.com (Taylan Ulrich B.)
To: Panicz Maciej Godek <godek.maciek@gmail.com>
Cc: "guile-user@gnu.org" <guile-user@gnu.org>,
	Dmitry Bogatov <KAction@gnu.org>
Subject: Re: Syntax-rules generate symbol
Date: Mon, 09 Sep 2013 22:03:43 +0200	[thread overview]
Message-ID: <871u4xdaow.fsf@taylan.uni.cx> (raw)
In-Reply-To: <CAMFYt2aA5SL+PgXk3OsEqn1dL=1gdnp+YgxhqLUrs5C-MNxg0w@mail.gmail.com> (Panicz Maciej Godek's message of "Mon, 9 Sep 2013 18:59:06 +0200")

Panicz Maciej Godek <godek.maciek@gmail.com> 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:
>
> 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.

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")
  (break)
  (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
efficient:

(let ((re-enter #f))
  (display
    (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	other threads:[~2013-09-09 20:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-09 16:19 Syntax-rules generate symbol Dmitry Bogatov
2013-09-09 16:59 ` Panicz Maciej Godek
2013-09-09 20:03   ` Taylan Ulrich B. [this message]
2013-09-10  6:11     ` Panicz Maciej Godek
2013-09-10  9:16       ` Taylan Ulrich B.
2013-09-10 10:38       ` Ian Price
2013-09-10 10:33 ` Ian Price

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871u4xdaow.fsf@taylan.uni.cx \
    --to=taylanbayirli@gmail.com \
    --cc=KAction@gnu.org \
    --cc=godek.maciek@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).