<div dir="ltr">On Mon, Sep 9, 2013 at 2:39 PM, Scott Klarenbach <span dir="ltr"><<a href="mailto:scott@pointyhat.ca" target="_blank">scott@pointyhat.ca</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>@Jay</div><div class="gmail_extra"><br>
</div><div class="gmail_extra"><div class="im"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
I'm not sure what you mean by "<span style="font-size:13px;font-family:arial,sans-serif">Doing a regex-match loses the original typing information"</span></blockquote><div><br></div></div><div>I just meant that since I want a:"2" to parse as '(a . "2") and a:2 to parse as '(a . 2), I'm having to perform a bunch of checks on the regex match string to see if I can convert it to back to a number, etc. Something like your (string->identifier-symbol-string-or-number). I was thinking maybe that was misguided and the syntax object contained information to help me in this regard. Obviously if I go with the reader approach I'll have to do it this way, but at #%top I thought maybe there was some type hints available.</div>
</div></div></blockquote><div><br></div><div>There is not.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_extra"><div class="im">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="font-family:arial,sans-serif;font-size:13px">The complicated way would have to deal with stuff like (f 1):5</span></blockquote>
<div><br></div></div><div>Ya, I never really thought of all the implications. At first It seemed like the Reader approach was the <i>less</i> complicated way, but now I realize that the following should work:</div><div>
((λ (x) (add1 x)) 1):5 => (cons ((λ (x) (add1 x)) 1) 5) => '(2 . 5)</div>
<div><br></div><div>and so I must recursively parse backwards to see where the sexp terminates. Maybe this what Eli was getting at with letting the reader do the job first and then looking though the syntax tree after.</div>
</div></div></blockquote><div><br></div><div>And as you can see from all the emails, this is a complicated thing. In fact, it was the subject of Jon Rafkind's PhD: <a href="http://www.cs.utah.edu/~rafkind/">http://www.cs.utah.edu/~rafkind/</a></div>
<div><br></div><div>Jay</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">
<span class=""><font color="#888888">
<div><br></div><div>Scott.</div><br></font></span><div class="gmail_quote"><div class="im">On Mon, Sep 9, 2013 at 5:49 AM, Jay McCarthy <span dir="ltr"><<a href="mailto:jay.mccarthy@gmail.com" target="_blank">jay.mccarthy@gmail.com</a>></span> wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="im">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><div><div class="h5"><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></div><div class="gmail_extra">
<br>
<br>
<div class="gmail_quote"><div><div class="h5"><div><div>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>
</div></div>
</div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="h5"><div><div>
<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 <a href="tel:604-568-4280" value="+16045684280" target="_blank">604-568-4280</a><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></div></div></div></div><div class="im">____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></div></blockquote></div><span><font color="#888888"><br><br clear="all"><div><br></div><div class="im">-- <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></font></span></div>
</blockquote></div><br><br clear="all"><div class="im"><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>
</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></div>