<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content="MSHTML 6.00.6000.16788" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face="Courier New" size=2>Thanks Matthew, with your help I concocted
the following:</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2> ; (macro-id? id-stx) (identifier? .
-> . boolean?)</FONT></DIV>
<DIV><FONT face="Courier New" size=2> ; For use in a transformer
only.</FONT></DIV>
<DIV><FONT face="Courier New" size=2> ; Returns #t if the
id-stx has a syntactic binding in the syntax local context
of the run-time environment.</FONT></DIV>
<DIV><FONT face="Courier New" size=2> ; If not, returns #f including when
id-stx is not bound at all.</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2> (define (macro-id? id)<BR>
(let/ec ec<BR> (call-with-exception-handler<BR>
(lambda (exn) (ec #t))<BR> (lambda
()<BR> (syntax-case*<BR>
(local-expand #`(#,id) (syntax-local-context)
'())<BR> (#%plain-app)
free-transformer-identifier=?<BR> ((#%plain-app .
z) #f)<BR> (_ #t))))))</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>Jos</DIV>
<DIV><BR></DIV></FONT>
<DIV><FONT face="Courier New" size=2>----- Original Message ----- </FONT>
<DIV><FONT face="Courier New" size=2>From: "Matthew Flatt" <</FONT><A
href="mailto:mflatt@cs.utah.edu"><FONT face="Courier New"
size=2>mflatt@cs.utah.edu</FONT></A><FONT face="Courier New"
size=2>></FONT></DIV>
<DIV><FONT face="Courier New" size=2>To: "Jos Koot" <</FONT><A
href="mailto:jos.koot@telefonica.net"><FONT face="Courier New"
size=2>jos.koot@telefonica.net</FONT></A><FONT face="Courier New"
size=2>></FONT></DIV>
<DIV><FONT face="Courier New" size=2>Cc: <</FONT><A
href="mailto:plt-scheme@list.cs.brown.edu"><FONT face="Courier New"
size=2>plt-scheme@list.cs.brown.edu</FONT></A><FONT face="Courier New"
size=2>></FONT></DIV>
<DIV><FONT face="Courier New" size=2>Sent: Thursday, January 15, 2009 6:57
PM</FONT></DIV>
<DIV><FONT face="Courier New" size=2>Subject: Re: [plt-scheme] attempt to
discern applications from syntactic formsfails</FONT></DIV></DIV>
<DIV><FONT face="Courier New"><BR><FONT size=2></FONT></FONT></DIV><FONT
face="Courier New" size=2>> At Thu, 15 Jan 2009 18:40:36 +0100, "Jos Koot"
wrote:<BR>>> My question is at the <===== in the following
code:<BR>>> <BR>>> (define-syntax (x stx)<BR>>>
(syntax-case stx ()<BR>>> ((_ x)<BR>>>
(let ((y (expand-once #'x)))<BR>>> (printf "~s~n"
(syntax->datum y))<BR>>> (syntax-case y
(#%app)<BR>>> ((#%app . z)
#''app)<BR>>> (_ #''no-app))))))<BR>>>
<BR>>> [...]<BR>>> (x (list 1 2 3))<BR>>> ; printed (#%app
list 1 2 3)<BR>>> ; value: no-app, why??? <===== I expected app<BR>>
<BR>> The `expand-once' is working at phase 1, while `syntax-case' is<BR>>
comparing identifiers at phase 0.<BR>> <BR>> Furthermore, the `#%app' of
`scheme/base' is being expanded to<BR>> `#%plain-app'. Confusingly, in the
scope of the `#%app' definition,<BR>> `#%plain-app' is called `#%app', so the
expansion prints as `#%app'<BR>> <BR>> So, you would have gotten the
expected results with<BR>> <BR>> (syntax-case* y
(#%plain-app) free-transformer-identifier=?<BR>>
((#%plain-app . z) #''app)<BR>> (_
#''no-app))<BR>> <BR>> <BR>> I doubt that this is what you really
intended, though. I think it's<BR>> more likely that you wanted to use
`local-expand' (which will expand<BR>> the given expression at phase 0) and
use `#%app' as one of the stop<BR>> forms, in which case the `syntax-case'
match would work as you expect.<BR>> <BR>> Actually, depending on the
context, it's probably better to use<BR>> `#%plain-app' as a stop form, in
which case you'll match on<BR>> `#%plain-app'. That works with macros defined
in a language other than<BR>> `scheme/base', since `#%plain-app' is the
primitive application form.<BR>> <BR>> <BR>>
Matthew<BR>></FONT></BODY></HTML>