| Date: Wed, 07 Mar 2007 19:32:20 -0500
 | From: David Van Horn <[EMAIL PROTECTED]>
 | 
 | Aubrey Jaffer wrote:
 | >  | From: Pascal Costanza <[EMAIL PROTECTED]>
 | >  | 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.

_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss

Reply via email to