<!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.16890" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face="Courier New" size=2>You mean the following?</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>#lang scheme</FONT></DIV>
<DIV><FONT face="Courier New" size=2>(define-syntax (my-hash
stx)<BR> (syntax-case stx ()<BR> ((_ (key . val) ...)<BR>
(let<BR> ((keys (map syntax->datum (syntax->list #'(key
...))))<BR> (vals (map syntax->datum (syntax->list
#'(val ...)))))</FONT></DIV>
<DIV><FONT face="Courier New" size=2> ; make the hash-table at
expansion time!<BR> (datum->syntax #'here
(make-immutable-hash (map cons keys vals)))))))</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>; tests:</FONT></DIV>
<DIV><FONT face="Courier New" size=2>(define h (my-hash (a . 1) (b . 2) (c .
3)))<BR>(hash-map h list) ; --> ((a 1) (b 2) (c 3))<BR>(hash-ref h 'a) ;
1</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>Best wishes, Jos.</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=psteiger@dcc.ufba.br href="mailto:psteiger@dcc.ufba.br">Patrick
Steiger</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@list.cs.brown.edu</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Monday, September 14, 2009 5:39
AM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [plt-scheme] Define-syntax and
#hash - ugly compiling behavior</DIV>
<DIV><BR></DIV>Hello, all. This is my first post on the list, I'm a CS student
and I've been giving Scheme a shot. (liking it a lot, so far).<BR><BR>Now,
given the following code:<BR><BR>(define-syntax myhash<BR> (syntax-rules
(->)<BR> [(_ (x -> y) ...)<BR>
#hash((x . y) ...)]))<BR><BR>When trying to compile it, I get:<BR><BR>. read:
expected `(' or `[' or `{' to start a hash pair<BR clear=all><BR>I was told
that this happens because the compiler recognizes #hash as a hash-table long
before (in the lexical analysis?) knowing that it is inside a (define-syntax),
and therefore doesn't get the semantics of '...' - it just interprets it as
illegal syntax.<BR><BR>This seems like a major wart with the language. What
are your opinions?<BR><BR>-- <BR>Patrick Steiger.<BR><BR>"Theory is when you
know something, but it doesn't work. Practice is<BR>when something works, but
you don't know why.<BR>Programmers combine theory and practice: Nothing works
and they don't<BR>know why." - Anon <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>