[racket] racket/engine and parameters

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Jun 29 01:52:40 EDT 2014

Yes, the `engine` function is like `thread`: it captures parameter
values at the point that the engine is created.

I'll fix the docs.

At Sat, 28 Jun 2014 21:35:58 -0400, Neil Van Dyke wrote:
> With the "racket/engine" module, is the "engine" procedure supposed to 
> capture the Racket parameter values that will be used for the proc when 
> "engine-run" is applied?  Rather than the parameters coming from the 
> dynamic extent in which "engine-run" is applied?
> 
> The example below shows that parameters don't work with engines as I'd 
> originally assumed.  (The parts about custodians are because that's what 
> I was originally debugging.)
> 
> #lang racket/base
> 
> (require racket/engine
>           racket/file)
> 
> (printf "with engine as i'd expect...\n")
> (let ((temp-path (make-temporary-file "xxx~A"))
>        (temp-port #f))
>    (let* ((cust (make-custodian (current-custodian)))
>           (eng  (engine (lambda (disable-suspend)
>                           (if (eq? (current-custodian) cust)
>                               (printf "OK: current-custodian is cust\n")
>                               (printf "FAIL: current-custodian is not 
> cust\n"))
>                           (set! temp-port
>                                 (open-output-file temp-path #:exists 
> 'replace))))))
>      (or (parameterize ((current-custodian cust))
>            (engine-run 3000 eng))
>          (error "engine-run timed out"))
>      (custodian-shutdown-all cust))
>    (if (port-closed? temp-port)
>        (printf "OK: port was closed\n")
>        (printf "FAIL: port was not closed\n")))
> 
> ;; with engine as i'd expect...
> ;; FAIL: current-custodian is not cust
> ;; FAIL: port was not closed
> 
> (printf "with engine capturing parameters early...\n")
> (let ((temp-path     (make-temporary-file "xxx~A"))
>        (temp-port     #f)
>        (another-param (make-parameter 'initial)))
>    (let* ((cust (make-custodian (current-custodian)))
>           (eng  (parameterize ((current-custodian cust)
>                                (another-param     'around-engine))
>                   (engine (lambda (disable-suspend)
>                             (if (eq? (current-custodian) cust)
>                                 (printf "OK: current-custodian is cust\n")
>                                 (printf "FAIL: current-custodian is not 
> cust\n"))
>                             (printf "(another-param) = ~S\n" 
> (another-param))
>                             (set! temp-port
>                                   (open-output-file temp-path #:exists 
> 'replace)))))))
>      (or (parameterize ((another-param 'around-engine-run))
>            (engine-run 3000 eng))
>          (error "engine-run timed out"))
>      (custodian-shutdown-all cust))
>    (if (port-closed? temp-port)
>        (printf "OK: port was closed\n")
>        (printf "FAIL: port was not closed\n")))
> 
> ;; with engine capturing parameters early...
> ;; OK: current-custodian is cust
> ;; (another-param) = around-engine
> ;; OK: port was closed
> 
> Thanks,
> Neil V.
> 
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.