The current (and only) use-case I have for this is embellishing expansion with type annotations to assist with inferencing. When the inferencing improves this use-case vanishes. The current example at hand is the expansion of racket/place's (place ch body ...) - to roughly -> (lambda (ch) body ...) and with `ch' now as Any, where (lambda: ((ch : Place-Channel)) body ...) would assist TR. But I understand and agree with avoid conditional code.<div>
<div><div><div><br></div><div><br></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Nov 5, 2012 at 3:43 PM, Sam Tobin-Hochstadt <span dir="ltr"><<a href="mailto:samth@ccs.neu.edu" target="_blank">samth@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Mon, Nov 5, 2012 at 3:28 PM, Ray Racine <<a href="mailto:ray.racine@gmail.com">ray.racine@gmail.com</a>> wrote:<br>
> On syntax expansion. Is there a way to determine in the macro whether I'm<br>
> expanding in a typed/racket environment vs regular racket.? Say for example<br>
> in place.rkt conditionally embellish the syntax templates with additional TR<br>
> annotations if the syntax is being expanded in TR vs R.<br>
<br>
</div>Jay is correct about how to do this, but you shouldn't need to. In<br>
particular, the TR annotations are all ignored by other tools, so it's<br>
safe to add them unconditionally.<br>
<div><div class="h5"><br>
><br>
> Thanks,<br>
><br>
><br>
> On Mon, Nov 5, 2012 at 3:14 PM, Ray Racine <<a href="mailto:ray.racine@gmail.com">ray.racine@gmail.com</a>> wrote:<br>
>><br>
>> OK, so it is a little bit of red herring on the unbound identifer<br>
>> `place?', i.e. there is an unexported identifier(s) in the expansion of<br>
>> `place?' which is the true issue. For what it's worth is yet another level<br>
>> of syntax explosion below `place?'. But if I get the full explosion graph<br>
>> of these these internal procedures situated into base-special-env.rkt it<br>
>> will all clear up is what I'm taking away. A quick glance leads me to<br>
>> believe it is less than a dozen, which means doable in finite time.<br>
>><br>
>> Time to saddle up and start charging them windmills.<br>
>><br>
>> Thanks,<br>
>><br>
>><br>
>> On Mon, Nov 5, 2012 at 2:50 PM, Sam Tobin-Hochstadt <<a href="mailto:samth@ccs.neu.edu">samth@ccs.neu.edu</a>><br>
>> wrote:<br>
>>><br>
>>> On Mon, Nov 5, 2012 at 1:58 PM, Ray Racine <<a href="mailto:ray.racine@gmail.com">ray.racine@gmail.com</a>> wrote:<br>
>>> > Consider the innocuous appearing snippit below from<br>
>>> > collects/racket/place/distributed/examples/hello-world.rkt<br>
>>> ><br>
>>> > #lang typed/racket<br>
>>> ><br>
>>> > (require racket/place/distributed<br>
>>> > racket/place)<br>
>>> ><br>
>>> > (provide hello-world)<br>
>>> ><br>
>>> > (: hello-world (-> Place))<br>
>>> > (define (hello-world)<br>
>>> > (place ch<br>
>>> > (printf "hello-world received: ~a\n"<br>
>>> > (place-channel-get (assert ch place-channel?)))<br>
>>> > (define HW "Hello World")<br>
>>> > (place-channel-put (assert ch place-channel?) (format "~a\n"<br>
>>> > HW))<br>
>>> > (printf "hello-world sent: ~a\n" HW)))<br>
>>> ><br>
>>> ><br>
>>> > First issue is:<br>
>>> > `place' is syntax entailing 2 closed over procs `place/proc' and<br>
>>> > `start-place defined in racket/place. No prob. I know the secret<br>
>>> > incantation.<br>
>>> ><br>
>>> > So I add a couple of strawman typings base-special-env.rkt and these<br>
>>> > immediate undefined identifier errors magically go away.<br>
>>> ><br>
>>> > ;; from the expansion of `place'<br>
>>> > [(make-template-identifier 'place/proc 'racket/place)<br>
>>> > (-> -Variable-Reference -Symbol -Symbol (-> -Symbol<br>
>>> > -Resolved-Module-Path<br>
>>> > -Symbol (-opt -Input-Port) (-opt -Output-Port) (-opt -Output-Port)<br>
>>> > -Place)<br>
>>> > (-opt -Input-Port) (-opt -Output-Port) (-opt -Output-Port)<br>
>>> > -Place)]<br>
>>> > [(make-template-identifier 'start-place 'racket/place)<br>
>>> > (-> -Symbol -Resolved-Module-Path -Symbol (-opt -Input-Port) (-opt<br>
>>> > -Output-Port) (-opt -Output-Port)<br>
>>> > -Place)]<br>
>>> ><br>
>>> > The next one in the conga line is an unknown identifier error for<br>
>>> > `place?',<br>
>>> > which _is_ publicly exported by racket/place. But `place?' is itself<br>
>>> > syntax, so I donno, we have some sort of require-syntax-for-syntax sort<br>
>>> > of<br>
>>> > thing going on.<br>
>>> ><br>
>>> > Just for laughs I tossed the below into base-special-env.rkt. and now<br>
>>> > hello-world.rkt has errors on duplicate definition of `place?'.<br>
>>> > [(make-template-identifier 'place? 'racket/place)<br>
>>> > (-> Univ -Boolean)]<br>
>>><br>
>>> If `place?` is indeed exported by `racket/place`, then the above won't<br>
>>> work. You'll need to give a type to the internal identifier that<br>
>>> `place?` expands into.<br>
>>><br>
>>> However, looking at the expansion of the hello-world.rkt program, it<br>
>>> doesn't seem to contain `place?`. So I'm confused as to where that's<br>
>>> coming from.<br>
>>><br>
>>> Finally, the way the `place` form works means that it would be better<br>
>>> to give a type annotation to `ch` using the #{ch : Place} form.<br>
>>><br>
>>> > Any ideas on how move forward? The idea was to take a run at TRing the<br>
>>> > collects/racket/place/distributed/examples/hello-world.rkt<br>
>>> ><br>
>>> > Thanks in advance,<br>
>>> ><br>
>>> > Ray<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>
>>><br>
>>> --<br>
>>> sam th<br>
>>> <a href="mailto:samth@ccs.neu.edu">samth@ccs.neu.edu</a><br>
>><br>
>><br>
><br>
<br>
<br>
<br>
</div></div>--<br>
sam th<br>
<a href="mailto:samth@ccs.neu.edu">samth@ccs.neu.edu</a><br>
</blockquote></div><br></div>