<div dir="ltr">You can do this a complicated way and an easy way. The complicated way would have to deal with stuff like (f 1):5 and the easy way would just work on stuff like x:1. I see "string":e as being part of the complicated way. In my mind, the complicated way would have to be done with a reader that produced some syntax that the expander dealt with the rest of. The easy way would just be a #%top macro like you have.<div>
<br></div><div>I'm not sure what you mean by "<span style="font-family:arial,sans-serif;font-size:13px">Doing a regex-match loses the original typing information" given that there is no "typing" information in the original syntax. My guess is that you need to be more particular about the arguments to datum->syntax after you do the regexp spilt...</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><font face="arial, sans-serif">(map (lambda (ns) (datum->syntax #'sym (string->identifier-symbol-string-or-number ns))) (regexp-split #rx":" (symbol->string (syntax->datum #'sym)))</font></div>
<div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">Jay</font></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div></div><div class="gmail_extra"><br><br>
<div class="gmail_quote">On Sun, Sep 8, 2013 at 1:29 PM, Scott Klarenbach <span dir="ltr"><<a href="mailto:scott@pointyhat.ca" target="_blank">scott@pointyhat.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">So in an attempt to improve my understanding of Racket Macros, I thought I'd implement the following syntax change to Racket: Introduce an alternative syntax for pairs where they are delimited by ':' in addition to ' . ', ie:<div>
<br></div><div>"a":"b" => '("a" . "b")</div><div><br></div><div>Seemed simple enough. I hooked into #%top, split any identifiers on ":" and reconstructed the syntax. I also always quote the left match which catches unbound identifiers ala javascript style object keys.</div>
<div><br></div><div>But, now I want</div><div><br></div><div>1:2 => '(1 . 2)</div><div>"1":2 => '("1" . 2)</div><div><br></div><div>Doing a regex-match loses the original typing information unless I (manually?) store it before symbol->string conversion. What's worse, I also want:<br>
</div><div><br></div><div>(define x 3)</div><div>k:x => '(k . 3)</div><div><br></div><div>But my naive approach loses the binding information along with the typing.</div><div><br></div><div>My questions are:</div>
<div>
<br></div><div>1.) Is my strategy wrong? Should I just tell the Reader to convert any x:y into (cons x y) and let the expander figure out the rest? Are there general guidelines to follow in this regard? (Syntax => Reader, Semantics => Expander)??</div>
<div><br></div><div>2.) If I stick with macros, what tactics should I be using to avoid the problems I have above?</div><div><br></div><div>I'm sure that binding/typing information is a basic concern well addressed by Racket. I've dug through the <a href="http://docs.racket-lang.org/reference/stxcmp.html#%28def._%28%28quote._~23~25kernel%29._bound-identifier~3d~3f%29%29" style="font-size:medium;text-decoration:none;color:blue;font-family:monospace;white-space:nowrap;background-color:rgb(232,232,255)" target="_blank">bound-identifier=?</a> stuff a bit, but my understanding is clearly lacking and before I go about reconstructing lexical information ad-hoc I thought I'd post this as a sanity check to point me in the right direction.</div>
<div><br></div><div>Thanks for your help.</div><div><div><div><div><br></div>-- <br>Talk to you soon,<br><br>Scott Klarenbach<br><br>PointyHat Software Corp.<br><a href="http://www.pointyhat.ca" target="_blank">www.pointyhat.ca</a><br>
p 604-568-4280<br>e <a href="mailto:scott@pointyhat.ca" target="_blank">scott@pointyhat.ca</a><br><span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">200-1575 W. Georgia</span><br>
Vancouver, BC <span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">V6G2V3</span><br><br>_______________________________________<br>To iterate is human; to recur, divine
</div></div></div></div>
<br>____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Jay McCarthy <<a href="mailto:jay@cs.byu.edu" target="_blank">jay@cs.byu.edu</a>><br>Assistant Professor / Brigham Young University<br><a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
<br>"The glory of God is Intelligence" - D&C 93
</div>