This is the mail archive of the cgen@sourceware.org mailing list for the CGEN project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

pmacro expansion snafu?


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]