[racket] TRing Places Issue Resolved

From: Ray Racine (ray.racine at gmail.com)
Date: Wed Nov 7 11:55:02 EST 2012

So I solved why TR was giving me an "unknown identifier place?" which I was
assuming needed some sort of additional work in base-special-env.rkt (it
doesn't).

This works just fine in TR.

#lang typed/racket/base

(require racket/place/distributed
         racket/place)

(: hello-world (-> Place))
(define (hello-world)

  (place ch
         (let ((ch ch)) ;; for illustration purposes only
           (when (place? ch)
             (printf "hello-world received: ~a\n"
                     (place-channel-get ch))
             (define HW "Hello World")
             (place-channel-put ch (format "~a\n" HW))
             (printf "hello-world sent: ~a\n" HW)))))


Expanding to:

 (#%require racket/place/distributed)
   (#%require racket/place)
   (define-values ()
     (begin
       (quote-syntax (:-internal hello-world (-> Place)))
       (#%plain-app values)))
   (define-values (lifted.0)
     (lambda:22 (ch)
       (let-values (((ch) ch))
         (if:26 (#%app:27 place? ch)
           (let-values ()
             (let-values ((()
                           (begin
                             (#%app:28
                              printf
                              (quote "hello-world received: ~a\n")
                              (#%app:29 place-channel-get ch))
                             (#%app values))))
               (let-values (((HW) (quote "Hello World")))
                 (#%app:31
                  place-channel-put
                  ch
                  (#%app:32 format (quote "~a\n") HW))
                 (#%app:33 printf (quote "hello-world sent: ~a\n") HW))))
           (#%app:26 void:26)))))
   (define-values (hello-world)
     (lambda ()
       (#%app
        place/proc
        (#%variable-reference)
        'place/anon/code/ecomm-analytics/redtop/rkt/hello-world.rkt1
        'place
        start-place
        (quote #f)
        (#%app current-output-port)
        (#%app:18 current-error-port))))

As clearly explained in the Racket Doc for 'place', given (place ch body0
...) the bodies are lifted to the module top level. As generated binding,
lift.0 is lifted to the top level there is no Type declaration for TR to
see, so the single 'ch' arg of the lifted wrapping lambda is of type Any.
 Hence, the necessity of the added (when (place? ch) ...).

Where I got bogged down was attempting to solve the TR type check error of
lift.0 having (ch : Any) when (ch : Place) is required in place-channel-get
using TR syntax using some variation of TR syntax. Something along the
lines of the following.

(: hello-world (-> Place))
(define (hello-world)

  (place ch
         (let: ((ch : Place ch)) ;; fails with "unknown identifier place?"
             (printf "hello-world received: ~a\n"
                     (place-channel-get ch))
             (define HW "Hello World")
             (place-channel-put ch (format "~a\n" HW))
             (printf "hello-world sent: ~a\n" HW)))))

I ended up burning cycles on why place? was not being seen by RT, ie as a
base-special-env.rkt issue (which it is not).

Appears the place top level lifting macro and the accompany use of the
let-values misplaces (pun intended) the type annotation (ch : Place) in the
let-values bindings, causing the unknown place? identifier error.  But it
is an unknown identifier in let bindings and _not_ some sort of failure to
correctly import 'place?' into TR.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20121107/83fc4535/attachment.html>

Posted on the users mailing list.