[racket] Syntax arrows: Strange capturing behavior

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Thu Jan 8 18:12:37 EST 2015

#lang web-server converts the program to ANF and something like CPS. Then
ANF stages the program into steps and then the CPS-ish stage takes each of
those steps and lifts them to the top-level adding arguments that close
over free variables. In Jordan's program and Robby's example, each usage of
"me" introduces a new "step" and thus a new closure. The transformer takes
the previously available "me" and uses it bind the next "me".

I believe that the way to "fix" the arrows would be to change this line:

https://github.com/racket/web-server/blob/master/web-server-lib/web-server/lang/closure.rkt#L89

so that rather than using fvars, it used a new argument fvar-bindings which
would be bound-identifier=? but would have different srclocs. Computing
that would be difficult as we'd have to change the interface to
make-closure to accept some sort of top-down mapping of all the bindings.

Jay

On Sun, Jan 4, 2015 at 9:51 AM, Robby Findler <robby at eecs.northwestern.edu>
wrote:

> This looks to me like something tricky that #lang web-server is doing.
> Here's a simplified example:
>
> #lang web-server
> (define (f me)
>   `((a . ,me)
>     (r . ,me)
>     , at me))
>
>
> Perhaps someone (Jay?) can shed a little light on what transformations
> #lang web-server is doing in this case and we can see if it needs to change
> or if check syntax does.
>
> My guess is that the second "me" is ending up in a binding position that
> shadows the original binding of "me" and probably just rebinds it. Looking
> at the expansion it isn't clear to me which one and whether or not there
> are actually two of them (if there are, then the one that "looks wrong" to
> check syntax can just be turned off somehow probably).
>
> Robby
>
>
>
> On Sun, Jan 4, 2015 at 1:18 AM, Jordan Johnson <jmj at fellowhuman.com>
> wrote:
>
>> Hi all,
>>
>> This behavior (shown in attached images) showed up in some code I was
>> working on tonight: A complex quasiquoted expression is apparently fooling
>> DrRacket (6.1.1 under OS X Yosemite) into thinking one reference refers to
>> another reference, not to its actual binding.
>>
>>
>> (In the code pictured here, *oauth2-client* is a struct type defined in
>> the file, and *me* refers to an instance of it. *me* was a constant that
>> I was in the process of lifting to be a parameter.)
>>
>> If I replace the *,(oauth2-client-callback me)* with a different
>> expression, the bottommost *me* is then correctly shown referring to the
>> function parameter, but if I retype anything of the form *,(some-defined-function
>> me)*, the odd behavior comes back. It persists across saving and
>> reloading of the file.
>>
>> This seemed worthy of reporting, but after about 40 min of
>> experimentation, I still haven’t managed to reproduce the behavior in
>> another file, so I thought I’d best throw it out to the list to see if it
>> triggers any ideas from someone with more knowledge of the syntax-checking
>> internals.
>>
>> Cheers,
>> Jordan
>>
>>
>>
>> ____________________
>>   Racket Users list:
>>   http://lists.racket-lang.org/users
>>
>>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
>


-- 
Jay McCarthy
http://jeapostrophe.github.io

           "Wherefore, be not weary in well-doing,
      for ye are laying the foundation of a great work.
And out of small things proceedeth that which is great."
                          - D&C 64:33
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150108/ed240ab3/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2015-01-03 at 10.46.45 PM.png
Type: image/png
Size: 60993 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20150108/ed240ab3/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2015-01-03 at 10.46.23 PM.png
Type: image/png
Size: 73637 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20150108/ed240ab3/attachment-0003.png>

Posted on the users mailing list.