[racket] TR - Syntax Entailing Syntax

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Mon Nov 5 14:50:24 EST 2012

On Mon, Nov 5, 2012 at 1:58 PM, Ray Racine <ray.racine at gmail.com> wrote:
> Consider the innocuous appearing snippit below from
> collects/racket/place/distributed/examples/hello-world.rkt
> #lang typed/racket
> (require racket/place/distributed
>          racket/place)
> (provide hello-world)
> (: hello-world (-> Place))
> (define (hello-world)
>   (place ch
>          (printf "hello-world received: ~a\n"
>                  (place-channel-get (assert ch place-channel?)))
>          (define HW "Hello World")
>          (place-channel-put (assert ch place-channel?) (format "~a\n" HW))
>          (printf "hello-world sent: ~a\n" HW)))
> First issue is:
> `place' is syntax entailing 2 closed over procs `place/proc' and
> `start-place defined in racket/place.  No prob. I know the secret
> incantation.
> So I add a couple of strawman typings base-special-env.rkt and these
> immediate undefined identifier errors magically go away.
>  ;; from the expansion of `place'
>   [(make-template-identifier 'place/proc 'racket/place)
>    (-> -Variable-Reference -Symbol -Symbol (-> -Symbol -Resolved-Module-Path
> -Symbol (-opt -Input-Port) (-opt -Output-Port) (-opt -Output-Port) -Place)
>        (-opt -Input-Port) (-opt -Output-Port) (-opt -Output-Port)
>        -Place)]
>   [(make-template-identifier 'start-place 'racket/place)
>    (-> -Symbol -Resolved-Module-Path -Symbol (-opt -Input-Port) (-opt
> -Output-Port) (-opt -Output-Port)
>        -Place)]
> The next one in the conga line is an unknown identifier error for `place?',
> which _is_ publicly exported by racket/place.  But `place?' is itself
> syntax, so I donno, we have some sort of require-syntax-for-syntax sort of
> thing going on.
> Just for laughs I tossed the below into base-special-env.rkt. and now
> hello-world.rkt has errors on duplicate definition of `place?'.
>  [(make-template-identifier 'place? 'racket/place)
>    (-> Univ -Boolean)]

If `place?` is indeed exported by `racket/place`, then the above won't
work.  You'll need to give a type to the internal identifier that
`place?` expands into.

However, looking at the expansion of the hello-world.rkt program, it
doesn't seem to contain `place?`.  So I'm confused as to where that's
coming from.

Finally, the way the `place` form works means that it would be better
to give a type annotation to `ch` using the #{ch : Place} form.

> Any ideas on how move forward?  The idea was to take a run at TRing the
> collects/racket/place/distributed/examples/hello-world.rkt
> Thanks in advance,
> Ray
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

sam th
samth at ccs.neu.edu

Posted on the users mailing list.