[racket] racket/engine and parameters

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Sat Jun 28 21:35:58 EDT 2014

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.


Posted on the users mailing list.