public inbox for cgen@sourceware.org
 help / color / mirror / Atom feed
From: Doug Evans <dje@sebabeach.org>
To: cgen@sourceware.org
Subject: pmacro expansion snafu?
Date: Thu, 13 Aug 2009 17:15:00 -0000	[thread overview]
Message-ID: <200908131714.n7DHElXN026281@sspiff.sspiff.org> (raw)

I'm adding pmacro builtin .let*.  No point in leaving it out.

Anyways, I was adding another testcase for .let and found some
unintuitive behaviour.

guile> (pmacro-trace '(.let ((x y) (y 2)) (.list x y)) (make <location> nil))
Pmacro expanding: (.let ((x y) (y 2)) (.list x y))
Pmacro location: standard input:11:16
    Expanding: (.list x y)
          env: ((x . y) (y . 2))
     location: standard input:11:36
       result: (2 2)
Pmacro result: (2 2)
(2 2)
guile> (pmacro-trace '(.let ((x z) (y 2)) (.list x y)) (make <location> nil))
Pmacro expanding: (.let ((x z) (y 2)) (.list x y))
Pmacro location: standard input:14:16
    Expanding: (.list x y)
          env: ((x . z) (y . 2))
     location: standard input:14:36
       result: (z 2)
Pmacro result: (z 2)
(z 2)
guile> 

The problem is cgen's pmacro expansion will re-evaluate an expanded
pmacro if the expansion also happens to be a pmacro.
So in the first case x -> y, y is also a pmacro, so x -> y -> 2.

The following is even less unintuitive (I think).

guile> (pmacro-trace '(.let ((x y) (y x)) (.list x y)) (make <location> nil))
Pmacro expanding: (.let ((x y) (y x)) (.list x y))
Pmacro location: standard input:15:16
    Expanding: (.list x y)
          env: ((x . y) (y . x))
     location: standard input:15:36
       result: (x y)
Pmacro result: (x y)
(x y)
guile> 

I expected to get (y x), but x -> y (which is also a pmacro, so ...) -> x
and similarly y -> x -> y.

I'm not sure I prefer this behaviour.

Comments?

I'm happy with removing cgen's quirky pmacro expansion so that
(.let ((x y) (y x)) (.list x y)) -> (y x)
if that's the preferred thing to do.

                 reply	other threads:[~2009-08-13 17:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

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

  git send-email \
    --in-reply-to=200908131714.n7DHElXN026281@sspiff.sspiff.org \
    --to=dje@sebabeach.org \
    --cc=cgen@sourceware.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).