unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* Syntax transformers and definition order
@ 2010-03-26 13:02 Luca Saiu
  2010-03-28 12:50 ` Andy Wingo
  0 siblings, 1 reply; 3+ messages in thread
From: Luca Saiu @ 2010-03-26 13:02 UTC (permalink / raw)
  To: bug-guile

-----BEGIN PGP SIGNED MESSAGE-----
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:
(go)

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))
      form
      `(cons 1 (m2 ,form))))

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

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

(go)

This second snippet works fine also in 1.9.

Best regards,

- --
Luca Saiu
http://www-lipn.univ-paris13.fr/~saiu
GNU epsilon: http://www.gnu.org/software/epsilon
Marionnet:   http://www.marionnet.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkussG0ACgkQvzOavibF0oahEQCdGIY1kogi20FBYXadw/9yDlqR
+MQAn3k5Wrspw8aGEdTncTcwwIPVyoUo
=6lNC
-----END PGP SIGNATURE-----




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Syntax transformers and definition order
  2010-03-26 13:02 Syntax transformers and definition order Luca Saiu
@ 2010-03-28 12:50 ` Andy Wingo
  2010-03-29 16:44   ` Luca Saiu
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Wingo @ 2010-03-28 12:50 UTC (permalink / raw)
  To: Luca Saiu; +Cc: bug-guile

Greetings Luca,

On Fri 26 Mar 2010 14:02, Luca Saiu <positron@gnu.org> writes:

> ;;; 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:
> (go)

I'm afraid that this is just how it is. Fortunately it's easy to fix, as
you have seen.

From the NEWS:

    ** Macros need to be defined before their first use.

    It used to be that with lazy memoization, this might work:

      (define (foo x)
        (ref x))
      (define-macro (ref x) x)
      (foo 1) => 1

    But now, the body of `foo' is interpreted to mean a call to the toplevel
    `ref' function, instead of a macro expansion. The solution is to define
    macros before code that uses them.

Regards,

Andy
-- 
http://wingolog.org/




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Syntax transformers and definition order
  2010-03-28 12:50 ` Andy Wingo
@ 2010-03-29 16:44   ` Luca Saiu
  0 siblings, 0 replies; 3+ messages in thread
From: Luca Saiu @ 2010-03-29 16:44 UTC (permalink / raw)
  To: Andy Wingo; +Cc: bug-guile

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Andy Wingo wrote:
>>From the NEWS:

Sorry for the noise :-)

- --
Luca Saiu
http://www-lipn.univ-paris13.fr/~saiu
GNU epsilon: http://www.gnu.org/software/epsilon
Marionnet:   http://www.marionnet.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkuw2QQACgkQvzOavibF0objdwCdH8dHQwbyVFYYGasg+w3oZEB6
uw8AnjHtGMs0wzEtqQHvGr0nFdpulWne
=P2YR
-----END PGP SIGNATURE-----




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-03-29 16:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-26 13:02 Syntax transformers and definition order Luca Saiu
2010-03-28 12:50 ` Andy Wingo
2010-03-29 16:44   ` Luca Saiu

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