unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* syntax-case
@ 2002-08-19 14:57 Lynn Winebarger
  2002-08-19 15:22 ` syntax-case Lynn Winebarger
  0 siblings, 1 reply; 2+ messages in thread
From: Lynn Winebarger @ 2002-08-19 14:57 UTC (permalink / raw)



    Does anyone else see the following behaviour (from a Petite Chez
session) as inconsistent?
     I was trying to figure out how you can eagerly expand macros without
worrying about this sort of thing, and  

> (define x 5)
> (define-syntax foo
  (lambda (exp)
    (syntax-case exp ()
      ((_ y) (with-syntax ((z (datum->syntax-object (syntax _) x)))
	       (syntax (quote (z y))))))))
> (foo 8)
(5 8)
> (let ((x 8))
    (let-syntax ((foo (lambda (exp)
			(syntax-case exp ()
			  ((_ y) (with-syntax ((z (datum->syntax-object (syntax _) x)))
				   (syntax (quote (z y)))))))))
      (foo 'bar)))
Error: identifier out of context x.
Type (debug) to enter the debugger.
> 

I thought maybe the foo got expanded and _then_ the marked up x was not
recognized in the environment, so I tried this:
> (define tmp
    (call/cc
      (lambda (k)
	(let-syntax ((foo (lambda (exp)
			    (syntax-case exp ()
			      ((_ x ...) (k (syntax _)))))))
	  (foo 'h)))))

Error: identifier out of context k.
Type (debug) to enter the debugger.

    So, apparently let-syntax is allowed access only to global variables
(and other syntax), though  bindings from let(rec)  do shadow syntactic
keywords.

Lynn


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


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

* Re: syntax-case
  2002-08-19 14:57 syntax-case Lynn Winebarger
@ 2002-08-19 15:22 ` Lynn Winebarger
  0 siblings, 0 replies; 2+ messages in thread
From: Lynn Winebarger @ 2002-08-19 15:22 UTC (permalink / raw)


On Monday 19 August 2002 09:57, Lynn Winebarger wrote:
>     Does anyone else see the following behaviour (from a Petite Chez
> session) as inconsistent?
>      I was trying to figure out how you can eagerly expand macros without
> worrying about this sort of thing, and  
       this sort of thing means the dependence of a macro expansion on a
variable binding that could change.  And apparently, plain lexical variable
bindings are not in scope in a let(rec)-syntax, but global variable bindings
are.  The last email didn't include an example of the global binding working
in a let-syntax (just in define-syntax), so here's one (again from Chez):

> (define x 5)
> (let-syntax ((foo (lambda (exp)
			(syntax-case exp ()
			  ((_ y) (with-syntax ((z (datum->syntax-object (syntax _) x)))
				   (syntax (quote (z y)))))))))
      (foo 'bar))
(5 'bar)
>

      I had thought this behaviour was part of syntax-case, but now I see it's actually part
of let(rec)-syntax.  If the lexical variables were in scope in a let(rec)-syntax, macros
would have to be re-expanded every time an expression that contained them got
executed.  I'm not sure why the same criticism doesn't hold for global variable bindings,
though.

Lynn


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


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

end of thread, other threads:[~2002-08-19 15:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-19 14:57 syntax-case Lynn Winebarger
2002-08-19 15:22 ` syntax-case Lynn Winebarger

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