[r6rs-discuss] Interpreters need not apply?

From: Aubrey Jaffer <agj>
Date: Wed Mar 7 20:13:47 2007

 | Date: Wed, 07 Mar 2007 19:32:20 -0500
 | From: David Van Horn <dvanhorn_at_cs.brandeis.edu>
 |
 | Aubrey Jaffer wrote:
 | > | From: Pascal Costanza <pc_at_p-cos.net>
 | > | Date: Wed, 7 Mar 2007 16:05:53 +0100
 | > |
 | > | ...
 | > | Here is an example:
 | > |
 | > | (if expression form1 form2)
 | > |
 | > | Assume that both form1 and form2 are macro invocations. Will
 | > | form1 and form2 both be macroexpanded before the if statement
 | > | is evaluated, or will first the expression be evaluated and
 | > | depending on its outcome only either form1 or form2 be
 | > | expanded and then evaluated?
 | >
 | > In SCM, only form1 or form2 will be expanded and evaluated.
 |
 | Given this, the following behavior is curious to me:
 |
 | $ scm -r r5rs
 | > (define-syntax go (syntax-rules () ((go) (go))))
 | #<unspecified>
 | > (if #t #t (go))
 | #t
 | > (lambda () (go)) ;; loops
 |
 | From my understanding of this discussion, this implies SCM is not
 | a "pure interpreter", correct?

If go is defined with defmacro, SCM behaves as advertised:

> (defmacro (go) '((go) (go)))
  #<unspecified>
> (lambda () (go))
  #<CLOSURE <anon> () ((go) (go))>

But your example does loop:

> (define-syntax go (syntax-rules () ((go) (go))))
  #<unspecified>
> (lambda () (go))

  ERROR: user interrupt ...

R5RS-macro magic was added to SCM by Radey Shouman. It seems that the
first expression in a LAMBDA expression gets expanded early if it is
an R5RS-macro; I don't know why. If (go) is not first, then its
expansion is delayed until it is evaluated:

> (lambda () (list) (go))
  #<CLOSURE <anon> () (list) (go)>

So SCM must settle for being a 99.44% pure interpreter.
Received on Wed Mar 07 2007 - 20:13:11 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC