;; (param) => get-cell + cdr ;; (param value) => get-cell + [convert] + set-cdr! ;; need 3 opcodes: param cell ;; context params ;; context-params-set! ;; analyze needs to translate param calls to proper usages of the ;; first two opcodes ;; (parameterize ((param value)) body ...) ;; => (let* ((old-params (thread-parameters)) ;; (new-params (cons (cons param (param-convert value)) old-params))) ;; (dynamic-wind (lambda () (thread-set-parameters! new-params)) ;; (lambda () body ...) ;; (lambda () (thread-set-parameters! old-params)))) (define-module (srfi 39) (export make-parameter parameterize) (import-immutable (scheme)) (body (define (make-parameter value . o) (if (pair? o) (let ((converter (car o))) (lambda args (if (null? args) value (set! value (converter (car args)))))) (lambda args (if (null? args) value (set! value (car args)))))) (define-syntax parameterize (syntax-rules () ((parameterize ("step") ((param value tmp1 tmp2) ...) () body) (let ((tmp1 value) ...) (let ((tmp2 (param)) ...) (dynamic-wind (lambda () (param tmp1) ...) (lambda () . body) (lambda () (param tmp2) ...))))) ((parameterize ("step") args ((param value) . rest) body) (parameterize ("step") ((param value tmp1 tmp2) . args) rest body)) ((parameterize ((param value) ...) . body) (parameterize ("step") () ((param value) ...) body))))))