<div dir="ltr"><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">Using a binding that carries everything with it, or using a syntax-time hash table that carries out of band data that can be looked up based on the original binding, is reliable. </span></blockquote>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div>Good point, Sam made it at the same time.  :)<div><br></div><div>Wouldn't a syntax-time hash-table introduce problems as well since there's no guarantee it gets copied over either?</div>
<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jan 20, 2014 at 3:35 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">But there's no guarantee that if someone imports the original name somewhere, renames it somehow, etc., that they'll copy over a <name>-META binding as well.  Using a binding that carries everything with it, or using a syntax-time hash table that carries out of band data that can be looked up based on the original binding, is reliable.  Using an extra binding that _should_ be there in most namespaces, can be broken by contexts you have no control over.<span class="HOEnZb"><font color="#888888"><br>


</font></span></div><div class="gmail_extra"><span class="HOEnZb"><font color="#888888"><br clear="all"><div>Carl Eastlund</div></font></span><div><div class="h5">
<br><br><div class="gmail_quote">On Mon, Jan 20, 2014 at 6:31 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"><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">If/when it does matter, instead you could use a hashtable on the side,<br>



</span><span style="font-family:arial,sans-serif;font-size:13px">mapping from the procedure to the info. Of course that way, you need<br></span><span style="font-family:arial,sans-serif;font-size:13px">to use `(lookup thing)` to get the info.</span></blockquote>



<div><br></div><div>Not to mention that it's vastly simpler to do it this way.  You get a straightforward transformer proc and a hashtable bound as syntax.</div><div><br></div><div>This is partly a learning exercise for me - so it's valuable to go through - but the more I look at it the more I think it's a lot of complexity just to be able to overload the struct name, when it would suffice for match and other macros that wanted compile-time meta info to follow a convention like struct-name-META or something.  Afterall, structs already come with a lot of magical bindings that you have to learn by convention, what's one more?</div>



<div><br></div><div>Just my two cents.</div><div><br></div><div>sk</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jan 20, 2014 at 1:41 PM,  <span dir="ltr"><<a href="mailto:users-request@racket-lang.org" target="_blank">users-request@racket-lang.org</a>></span> wrote:<br>



<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">Send users mailing list submissions to<br>
        <a href="mailto:users@racket-lang.org" target="_blank">users@racket-lang.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="http://lists.racket-lang.org/users/listinfo" target="_blank">http://lists.racket-lang.org/users/listinfo</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:users-request@racket-lang.org" target="_blank">users-request@racket-lang.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:users-owner@racket-lang.org" target="_blank">users-owner@racket-lang.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of users digest..."<br>
<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>
<br>
Today's Topics:<br>
<br>
   1. Re: Structs and syntax-local-value ... how is the struct name<br>
      overloaded? (Carl Eastlund)<br>
   2. Re: Structs and syntax-local-value ... how is the struct name<br>
      overloaded? (Greg Hendershott)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Mon, 20 Jan 2014 13:00:35 -0500<br>
From: Carl Eastlund <<a href="mailto:carl.eastlund@gmail.com" target="_blank">carl.eastlund@gmail.com</a>><br>
To: "Alexander D. Knauth" <<a href="mailto:alexander@knauth.org" target="_blank">alexander@knauth.org</a>><br>
Cc: Scott Klarenbach <<a href="mailto:scott@pointyhat.ca" target="_blank">scott@pointyhat.ca</a>>, Racket mailing list<br>
        <<a href="mailto:users@racket-lang.org" target="_blank">users@racket-lang.org</a>><br>
Subject: Re: [racket] Structs and syntax-local-value ... how is the<br>
        struct name overloaded?<br>
Message-ID:<br>
        <CAEOPtY09_5EUFpOn6uYBcJAB+TXTdDk=EK-DUHbLU2wu=<a href="mailto:XzDZw@mail.gmail.com" target="_blank">XzDZw@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Yes, that's exactly it.<br>
<br>
Carl Eastlund<br>
<br>
<br>
On Mon, Jan 20, 2014 at 10:13 AM, Alexander D. Knauth<br>
<<a href="mailto:alexander@knauth.org" target="_blank">alexander@knauth.org</a>>wrote:<br>
<br>
> I'm just curious, is this what you mean?<br>
><br>
> #lang racket<br>
><br>
> (require rackunit<br>
>          (for-syntax<br>
>           syntax/parse))<br>
><br>
> (begin-for-syntax<br>
>   (struct proc-with-info (proc info) #:property prop:procedure<br>
> (struct-field-index proc)))<br>
><br>
> (define-syntax thing<br>
>   (proc-with-info (lambda (stx)<br>
>                     (syntax-parse stx #:literals (thing)<br>
>                                   [(thing x ...)<br>
>                                    #'(#%app thing x ...)]<br>
>                                   [thing<br>
>                                    #'(lambda (x) x)]))<br>
>                   'info))<br>
><br>
> (define-syntax get-info<br>
>   (lambda (stx)<br>
>     (syntax-parse stx<br>
>                   [(get-info x)<br>
>                    (datum->syntax stx `(quote ,(proc-with-info-info<br>
> (syntax-local-value #'x))))])))<br>
><br>
> (check-equal? (thing 1) 1)<br>
> (let ([x (random)])<br>
>   (check-equal? (thing x) x))<br>
><br>
> (check-equal? (get-info thing)<br>
>               'info)<br>
><br>
><br>
> On Jan 20, 2014, at 12:37 AM, Carl Eastlund wrote:<br>
><br>
> It sounds like you've got it.  A syntax transformer must be a procedure,<br>
> and prop:procedure is how you make a procedure that can also be something<br>
> else.  So if you want something to be both a syntax transformer and a<br>
> struct binding, for instance, you need to use prop:procedure and<br>
> prop:struct-info.  You can't make something both a procedure and a symbol,<br>
> because symbols don't work via struct properties, but you could make it<br>
> both a procedure and a struct that contains a symbol.<br>
><br>
> Carl Eastlund<br>
><br>
> On Mon, Jan 20, 2014 at 12:21 AM, Scott Klarenbach <<a href="mailto:scott@pointyhat.ca" target="_blank">scott@pointyhat.ca</a>>wrote:<br>
><br>
>>  That doesn't look like a complete program; what does #'done refer to?<br>
>>> And where did the "val is: " printout go?<br>
>><br>
>><br>
>> That's just a quick hack for illustration purposes.  #''done is just<br>
>> something to return. (note the two quotes)  The output is:<br>
>> val is: #<procedure:self-ctor-checked-struct-info>#<procedure:posn><br>
>> 'done<br>
>><br>
>> But your supposition is correct: posn is always bound as syntax to a<br>
>>> self-ctor-checked-struct-info-object.  That object works as a syntax<br>
>>> transformer; run time references to posn are transformed into references to<br>
>>> the actual procedure value you're seeing as #<procedure:posn>.<br>
>><br>
>><br>
>> Thanks Carl, it's starting to make sense.  So the prop:procedure of the<br>
>> struct is actually the transformer?  And so in expression context it acts<br>
>> as a macro, but in syntax-local-value context it acts as a struct?  I was<br>
>> trying to produce something similar, but ran into the following issues:<br>
>><br>
>> Say I want (define-syntax (posn) ...) to transform syntax, but I also<br>
>> want (syntax-local-value #'posn) to return 'something.<br>
>> Without the struct trick I can only have one but not the other.  I could<br>
>> either have (define-syntax posn 'something), and lose the ability to call<br>
>> it as a macro (illegal syntax), or have (define-syntax (posn) #'something),<br>
>> and then (syntax-local-value #'posn) returns the transformer, rather than<br>
>> 'something.<br>
>><br>
>><br>
>><br>
>><br>
>><br>
>> On Sun, Jan 19, 2014 at 8:57 PM, Scott Klarenbach <<a href="mailto:scott@pointyhat.ca" target="_blank">scott@pointyhat.ca</a>>wrote:<br>
>><br>
>>> It's not changing it, I'm just trying to figure out the implementation<br>
>>> and understand what I'm seeing.<br>
>>> For example, given this:<br>
>>><br>
>>> (struct posn (x y))<br>
>>><br>
>>> (define-syntax (test stx)<br>
>>>   (syntax-case stx ()<br>
>>> [(_ x)<br>
>>>  (printf "val is: ~s" (syntax-local-value #'posn))<br>
>>>  #''done]))<br>
>>><br>
>>> > posn<br>
>>> #<procedure:posn><br>
>>><br>
>>> > (test x)<br>
>>> #<procedure:self-ctor-checked-struct-info><br>
>>><br>
>>> I'm surprised that the values are different.  Is posn actually always a<br>
>>> self-ctor-checked-struct-info object, but it's prop:procedure is defined to<br>
>>> allow for being used in an expression in the first case?<br>
>>><br>
>>><br>
>>><br>
>>><br>
>>> On Sun, Jan 19, 2014 at 8:40 PM, Carl Eastlund <<a href="mailto:carl.eastlund@gmail.com" target="_blank">carl.eastlund@gmail.com</a>>wrote:<br>
>>><br>
>>>> If syntax-local-value is returning something other than the value you<br>
>>>> put in, that's a bug.  It shouldn't be wrapping it or changing it in any<br>
>>>> way.  Do you have a program where you bind something via define-syntax that<br>
>>>> satisfies struct-info?, and get something out via syntax-local-value that<br>
>>>> doesn't?<br>
>>>><br>
>>>> Carl Eastlund<br>
>>>><br>
>>>> On Sun, Jan 19, 2014 at 11:27 PM, Scott Klarenbach <<a href="mailto:scott@pointyhat.ca" target="_blank">scott@pointyhat.ca</a>>wrote:<br>
>>>><br>
>>>>> But I don't see how the same binding can be a transformer and also<br>
>>>>> return something else (like a list, or a checked-struct-info-thing) via<br>
>>>>> syntax-local-value.<br>
>>>>><br>
>>>>> If I bind my-fn as a transformer, then any other macros that use it<br>
>>>>> with syntax-local-value will receive the transformer procedure back, not<br>
>>>>> any special meta data.  And if I bind it as meta data directly, ie<br>
>>>>> (define-syntax my-fn 'something) then it works with syntax-local-value but<br>
>>>>> any attempts to use it as a transformer result in illegal syntax.<br>
>>>>><br>
>>>>> Even if I create a transformer that returns a struct which implements<br>
>>>>> both prop:procedure and prop:struct-info, using that binding with<br>
>>>>> syntax-local-value will return the transformer procedure itself, rather<br>
>>>>> than the final struct.<br>
>>>>><br>
>>>>><br>
>>>>><br>
>>>>> On Sun, Jan 19, 2014 at 8:04 PM, Carl Eastlund <<br>
>>>>> <a href="mailto:carl.eastlund@gmail.com" target="_blank">carl.eastlund@gmail.com</a>> wrote:<br>
>>>>><br>
>>>>>> Yes, I believe that the name of a structure defined by "struct" is<br>
>>>>>> bound at syntax-time to a value that implements both prop:procedure, so<br>
>>>>>> that it can expand to a use of the constructor when used in an expression,<br>
>>>>>> and prop:struct-info so that it can be use to look up static information<br>
>>>>>> when passed to relevant macros.<br>
>>>>>><br>
>>>>>> Carl Eastlund<br>
>>>>>><br>
>>>>>><br>
>>>>>> On Sun, Jan 19, 2014 at 11:00 PM, Scott Klarenbach <<br>
>>>>>> <a href="mailto:scott@pointyhat.ca" target="_blank">scott@pointyhat.ca</a>> wrote:<br>
>>>>>><br>
>>>>>>> How is it that the definition of (struct my-name (x y)) can bind<br>
>>>>>>> *my-name* both as a #<procedure:my-name> at runtime and a<br>
>>>>>>> transformer-binding *my-name* that at compile time (via<br>
>>>>>>> syntax-local-value) produces #<procedure:self-ctor-checked-struct-info>.?<br>
>>>>>>><br>
>>>>>>> Or, put another way, how can I define a transformer *my-fn* that<br>
>>>>>>> produces syntax, but that also exposes hidden meta-data under the same<br>
>>>>>>> binding to other macros that might wish to know about the binding at<br>
>>>>>>> compile time?<br>
>>>>>>><br>
>>>>>>> I'm specifically wondering how the overloading works.  Is it some<br>
>>>>>>> clever use of prop:procedure?<br>
>>>>>>><br>
>>>>>>> Thanks.<br>
>>>>>>><br>
>>>>>>> --<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>
>>>>>>> 200-1575 W. Georgia<br>
>>>>>>> Vancouver, BC V6G2V3<br>
>>>>>>><br>
>>>>>>> _______________________________________<br>
>>>>>>> To iterate is human; to recur, divine<br>
>>>>>>><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>
>>>>>>><br>
>>>>>><br>
>>>>><br>
>>>>><br>
>>>>> --<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>
>>>>> 200-1575 W. Georgia<br>
>>>>> Vancouver, BC V6G2V3<br>
>>>>><br>
>>>>> _______________________________________<br>
>>>>> To iterate is human; to recur, divine<br>
>>>>><br>
>>>><br>
>>>><br>
>>><br>
>>><br>
>>> --<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>
>>> 200-1575 W. Georgia<br>
>>> Vancouver, BC V6G2V3<br>
>>><br>
>>> _______________________________________<br>
>>> To iterate is human; to recur, divine<br>
>>><br>
>><br>
>><br>
>><br>
>> --<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>
>> 200-1575 W. Georgia<br>
>> Vancouver, BC V6G2V3<br>
>><br>
>> _______________________________________<br>
>> To iterate is human; to recur, divine<br>
>><br>
><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>
><br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.racket-lang.org/users/archive/attachments/20140120/1cbff376/attachment-0001.html" target="_blank">http://lists.racket-lang.org/users/archive/attachments/20140120/1cbff376/attachment-0001.html</a>><br>




<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Mon, 20 Jan 2014 16:40:56 -0500<br>
From: Greg Hendershott <<a href="mailto:greghendershott@gmail.com" target="_blank">greghendershott@gmail.com</a>><br>
To: <a href="mailto:users@racket-lang.org" target="_blank">users@racket-lang.org</a><br>
Subject: Re: [racket] Structs and syntax-local-value ... how is the<br>
        struct name overloaded?<br>
Message-ID:<br>
        <CAGspUn3DeoWR7Qfw=uPamDuV+6ig9asRt=-<a href="mailto:DcAjh%2BuViBbTYnA@mail.gmail.com" target="_blank">DcAjh+uViBbTYnA@mail.gmail.com</a>><br>
Content-Type: text/plain; charset=ISO-8859-1<br>
<br>
>> and prop:procedure is how you make a procedure that can also be something<br>
>> else.<br>
<br>
One thing to keep in mind is that there is _some_ overhead. In my<br>
recent experience, applying via prop:procedure took roughly 1.6X the<br>
time as applying a plain procedure. (This with the variant of<br>
prop:procedure where its value is an index to the field in the struct<br>
holding the procedure.)<br>
<br>
I don't know how much of the extra time is due to memory reference,<br>
missing the optimizer, and/or other?<br>
<br>
For many applications that doesn't matter, and it's worth it to have<br>
`thing` self-evaluate to the info.<br>
<br>
If/when it does matter, instead you could use a hashtable on the side,<br>
mapping from the procedure to the info. Of course that way, you need<br>
to use `(lookup thing)` to get the info.<br>
<br>
<br>
End of users Digest, Vol 101, Issue 60<br>
**************************************<br>
</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>
<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></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 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>