<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" class="" style="font-size:medium;text-decoration:none;color:blue;font-family:monospace;white-space:nowrap;background-color:rgb(232,232,255)">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-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">200-1575 W. Georgia</span><br>
Vancouver, BC <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">V6G2V3</span><br><br>_______________________________________<br>To iterate is human; to recur, divine
</div></div></div></div>