[Top][All Lists]

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

Syntax transformers and definition order

From: Luca Saiu
Subject: Syntax transformers and definition order
Date: Fri, 26 Mar 2010 14:02:37 +0100
User-agent: Mozilla-Thunderbird (X11/20091109)

Hash: SHA1

Hello guilers! Long time no see. I hope everything's all right.

Guile rocks more and more. Thanks :-).

I've found an incompatibility between 1.8 and 1.9 (tested with 1.9.8 and
1.9.9); if it's a documented change then sorry for the noise, I may just
have missed it.

Here's a distilled test case:

;;; Define a function calling a macro which is not yet defined:
(define (go)
  (display (m 42)))

;;; Define the macro:
(define-macro (m form)
  `(list ,form))

;;; Call the function:

The code above does the right thing in 1.8, but 1.9 fails with
  ERROR: In procedure vm-debug-engine:
  ERROR: Wrong type to apply: #<syntax-transformer m>
, either with or without the VM.

I guess that when 1.9 parses the definition of go it assumes that the
as-yet-unknown operator m will be a closure, and the assumption is not
rectified later.  I agree that what I wrote above is bad style, even if
something very similar occurred in real code of mine, and the thing does
indeed feel "Schemey".
  Of course if I move the definition of m before the definition of go
then everything works also with 1.9.

Just for completeness (I think it's not surprising, particularly for you
who know the implementation), there isn't any such problem if go becomes
a macro containing a *quoted* call of a macro which is not defined yet
- -- this case is much more important in practice, as it's needed to
define mutually-recursive macros:

(define-macro (m1 form)
  (if (zero? (random 10))
      `(cons 1 (m2 ,form))))

(define-macro (m2 form)
  (if (zero? (random 10))
      `(cons 2 (m1 ,form))))

(define (go)
  (display (m1 42)))


This second snippet works fine also in 1.9.

Best regards,

- --
Luca Saiu
GNU epsilon: http://www.gnu.org/software/epsilon
Marionnet:   http://www.marionnet.org
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


reply via email to

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