<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16890" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face="Courier New" size=2>Use datum->syntax for unhygienic
macros:</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>#lang scheme</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Courier New" size=2>(define-syntax (define-my-id
stx)<BR> (syntax-case stx ()<BR> ((_ id)<BR> #`(define<BR>
#,(datum->syntax stx<BR>
(string->symbol<BR> (string-append
"my-id-"<BR> (symbol->string
(syntax->datum #'id)))))<BR> (lambda () (display
'id))))))</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Courier New" size=2>(define-my-id trout)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Courier New" size=2>(my-id-trout) ; --> void, displaying
trout</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>Jos</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=laurent.orseau@gmail.com
href="mailto:laurent.orseau@gmail.com">Laurent</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=plt-scheme@list.cs.brown.edu
href="mailto:plt-scheme@list.cs.brown.edu">PLT-Scheme Mailing List</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Saturday, September 26, 2009 8:34
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [plt-scheme] #'(require
help)</DIV>
<DIV><BR></DIV>Hi all,<BR><BR>I timidly require your help on a simple macro
I've been trying to do for some time now.<BR><BR>I usually prefer to do things
myself, but I'm stuck.<BR><BR>Here's the thing :<BR>I have an identifier and I
want to generate an identifier based on it but with a different name.<BR>(in
fact I have lots of identifiers)<BR><BR>for example :<BR>(define-my-id trout)
<BR>would generate the macro identifier my-id-trout that expands to, say,
(display "trout").<BR>My concern is about using in the program an identifier
that is not defined explicitly in the program file.<BR>This should be possible
though, since this is partly what define-struct does, I
suppose.<BR><BR><BR>With eval and quasi-quoting I can easily generate an
approximation with a lambda'd form but Scheme won't let me use identifiers
that are not explicitly defined (it works in the REPL though):<BR>(define
(define-my-id id)<BR> (eval `(define ,(string->symbol (string-append
"my-id-" (symbol->string id)))
<BR> (lambda () (display
,(symbol->string id))))))<BR><BR>I also know that syntax-id-rules can
generate expanding identifiers, but I can't use string-append et al in macros
to generate a new id...<BR><BR>Also, where can I find some simple macro
samples, other than in the guide ?<BR><BR>Thanks a lot,<BR>Laurent<BR><BR><BR>
<P>
<HR>
<P></P>_________________________________________________<BR> For
list-related administrative tasks:<BR>
http://list.cs.brown.edu/mailman/listinfo/plt-scheme<BR></BLOCKQUOTE></BODY></HTML>