<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>I'm just curious, is this what you mean?</div><div><br></div><div><div><font class="Apple-style-span" face="'Courier New'">#lang racket</font></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><font class="Apple-style-span" face="'Courier New'">(require rackunit</font></div><div><font class="Apple-style-span" face="'Courier New'"> (for-syntax</font></div><div><font class="Apple-style-span" face="'Courier New'"> syntax/parse))</font></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><font class="Apple-style-span" face="'Courier New'">(begin-for-syntax</font></div><div><font class="Apple-style-span" face="'Courier New'"> (struct proc-with-info (proc info) #:property prop:procedure (struct-field-index proc)))</font></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><font class="Apple-style-span" face="'Courier New'">(define-syntax thing</font></div><div><font class="Apple-style-span" face="'Courier New'"> (proc-with-info (lambda (stx)</font></div><div><font class="Apple-style-span" face="'Courier New'"> (syntax-parse stx #:literals (thing)</font></div><div><font class="Apple-style-span" face="'Courier New'"> [(thing x ...)</font></div><div><font class="Apple-style-span" face="'Courier New'"> #'(#%app thing x ...)]</font></div><div><font class="Apple-style-span" face="'Courier New'"> [thing</font></div><div><font class="Apple-style-span" face="'Courier New'"> #'(lambda (x) x)]))</font></div><div><font class="Apple-style-span" face="'Courier New'"> 'info))</font></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><font class="Apple-style-span" face="'Courier New'">(define-syntax get-info</font></div><div><font class="Apple-style-span" face="'Courier New'"> (lambda (stx)</font></div><div><font class="Apple-style-span" face="'Courier New'"> (syntax-parse stx</font></div><div><font class="Apple-style-span" face="'Courier New'"> [(get-info x)</font></div><div><font class="Apple-style-span" face="'Courier New'"> (datum->syntax stx `(quote ,(proc-with-info-info (syntax-local-value #'x))))])))</font></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><font class="Apple-style-span" face="'Courier New'">(check-equal? (thing 1) 1)</font></div><div><font class="Apple-style-span" face="'Courier New'">(let ([x (random)])</font></div><div><font class="Apple-style-span" face="'Courier New'"> (check-equal? (thing x) x))</font></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><font class="Apple-style-span" face="'Courier New'">(check-equal? (get-info thing)</font></div><div><font class="Apple-style-span" face="'Courier New'"> 'info)</font></div></div><div><br></div><br><div><div>On Jan 20, 2014, at 12:37 AM, Carl Eastlund wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div><div>It sounds like you've got it. A syntax transformer must be a procedure, and prop:procedure is how you make a procedure that can also be something else. So if you want something to be both a syntax transformer and a struct binding, for instance, you need to use prop:procedure and prop:struct-info. You can't make something both a procedure and a symbol, because symbols don't work via struct properties, but you could make it both a procedure and a struct that contains a symbol.<br clear="all"> </div></div><div><div><div><br><div class="gmail_extra"><div>Carl Eastlund</div> <br><div class="gmail_quote">On Mon, Jan 20, 2014 at 12:21 AM, 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"><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:12.727272033691406px">That doesn't look like a complete program; what does #'done refer to? And where did the "val is: " printout go?</span></blockquote> <div><br></div></div><div>That's just a quick hack for illustration purposes. #''done is just something to return. (note the two quotes) The output is: </div><div><div>val is: #<procedure:self-ctor-checked-struct-info>#<procedure:posn></div> <div>'done</div></div><div class="im"><div><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"> <span style="font-family:arial,sans-serif;font-size:12.727272033691406px">But your supposition is correct: posn is always bound as syntax to a self-ctor-checked-struct-info-</span><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">object. That object works as a syntax transformer; run time references to posn are transformed into references to the actual procedure value you're seeing as #<procedure:posn>.</span></blockquote> <div><br></div></div><div>Thanks Carl, it's starting to make sense. So the prop:procedure of the struct is actually the transformer? And so in expression context it acts as a macro, but in syntax-local-value context it acts as a struct? I was trying to produce something similar, but ran into the following issues:</div> <div> </div>Say I want (define-syntax (posn) ...) to transform syntax, but I also want (syntax-local-value #'posn) to return 'something.<div>Without the struct trick I can only have one but not the other. I could either have (define-syntax posn 'something), and lose the ability to call it as a macro (illegal syntax), or have (define-syntax (posn) #'something), and then (syntax-local-value #'posn) returns the transformer, rather than 'something.</div> <div><br></div><div><br></div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Jan 19, 2014 at 8:57 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"><div>It's not changing it, I'm just trying to figure out the implementation and understand what I'm seeing.</div> <div>For example, given this:</div><div><br></div><div>(struct posn (x y))</div><div> <br></div><div>(define-syntax (test stx)</div><div> (syntax-case stx ()</div><div><span style="white-space:pre-wrap"> </span>[(_ x)</div><div><span style="white-space:pre-wrap"> </span> (printf "val is: ~s" (syntax-local-value #'posn))</div> <div><span style="white-space:pre-wrap"> </span> #''done]))</div><div><br></div><div>> posn</div><div>#<procedure:posn></div><div><br></div><div>> (test x)</div><div>#<procedure:self-ctor-checked-struct-info></div> <div><br></div><div>I'm surprised that the values are different. Is posn actually always a self-ctor-checked-struct-info object, but it's prop:procedure is defined to allow for being used in an expression in the first case? </div> <div><br></div><div><br></div></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Jan 19, 2014 at 8:40 PM, Carl Eastlund <span dir="ltr"><<a href="mailto:carl.eastlund@gmail.com" target="_blank">carl.eastlund@gmail.com</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">If syntax-local-value is returning something other than the value you put in, that's a bug. It shouldn't be wrapping it or changing it in any way. Do you have a program where you bind something via define-syntax that satisfies struct-info?, and get something out via syntax-local-value that doesn't?<span><font color="#888888"><br> </font></span><div class="gmail_extra"><span><font color="#888888"><br clear="all"><div>Carl Eastlund</div></font></span><div><div> <br><div class="gmail_quote">On Sun, Jan 19, 2014 at 11:27 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"><div>But I don't see how the same binding can be a transformer and also return something else (like a list, or a checked-struct-info-thing) via syntax-local-value.<br></div><div><br></div><div>If I bind my-fn as a transformer, then any other macros that use it with syntax-local-value will receive the transformer procedure back, not any special meta data. And if I bind it as meta data directly, ie (define-syntax my-fn 'something) then it works with syntax-local-value but any attempts to use it as a transformer result in illegal syntax.</div> <div><br></div><div>Even if I create a transformer that returns a struct which implements both prop:procedure and prop:struct-info, using that binding with syntax-local-value will return the transformer procedure itself, rather than the final struct.</div> <div><br></div></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Jan 19, 2014 at 8:04 PM, Carl Eastlund <span dir="ltr"><<a href="mailto:carl.eastlund@gmail.com" target="_blank">carl.eastlund@gmail.com</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">Yes, I believe that the name of a structure defined by "struct" is bound at syntax-time to a value that implements both prop:procedure, so that it can expand to a use of the constructor when used in an expression, and prop:struct-info so that it can be use to look up static information when passed to relevant macros.<br> </div><div class="gmail_extra"><br clear="all"><div>Carl Eastlund</div> <br><br><div class="gmail_quote"><div><div>On Sun, Jan 19, 2014 at 11:00 PM, Scott Klarenbach <span dir="ltr"><<a href="mailto:scott@pointyhat.ca" target="_blank">scott@pointyhat.ca</a>></span> wrote:<br> </div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div> <div dir="ltr">How is it that the definition of (struct my-name (x y)) can bind <i>my-name</i> both as a #<procedure:my-name> at runtime and a transformer-binding <i>my-name</i> that at compile time (via syntax-local-value) produces #<procedure:self-ctor-checked-struct-info>.?<div> <br></div><div>Or, put another way, how can I define a transformer <i>my-fn</i> that produces syntax, but that also exposes hidden meta-data under the same binding to other macros that might wish to know about the binding at compile time?<br> <div><br></div><div>I'm specifically wondering how the overloading works. Is it some clever use of prop:procedure?</div><div><br></div><div>Thanks.</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> <br></div></div>____________________<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></div> </blockquote></div><br><br clear="all"><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></blockquote></div><br></div></div></div></div> </blockquote></div><br><br clear="all"><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></blockquote></div><br><br clear="all"><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></blockquote></div><br></div></div></div></div></div> ____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>