mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 21:59:17 +02:00
They can be close()d explicitly with close-file-descriptor, and will close() on gc, but only explicitly closing the last port on them will close the fileno. Notably needed for network sockets where we open separate input and output ports on the same socket.
40 lines
1.2 KiB
Scheme
40 lines
1.2 KiB
Scheme
;; param.scm -- SRFI-39 parameters
|
|
;; Copyright (c) 2010-2011 Alex Shinn. All rights reserved.
|
|
;; BSD-style license: http://synthcode.com/license.txt
|
|
|
|
(define (parameter-convert param value)
|
|
(let ((proc (parameter-converter param)))
|
|
(if (procedure? proc)
|
|
(proc value)
|
|
value)))
|
|
|
|
(define (make-parameter init . o)
|
|
(let ((conv (and (pair? o) (car o))))
|
|
(%make-parameter (if conv (conv init) init) conv)))
|
|
|
|
(define-syntax parameterize
|
|
(syntax-rules ()
|
|
((parameterize ("step")
|
|
((param value p old new) ...)
|
|
()
|
|
body)
|
|
(let ((p param) ...)
|
|
(let ((old (p)) ...
|
|
(new (parameter-convert p value)) ...)
|
|
(dynamic-wind
|
|
(lambda () (p new) ...)
|
|
(lambda () . body)
|
|
(lambda () (p old) ...)))))
|
|
((parameterize ("step")
|
|
args
|
|
((param value) . rest)
|
|
body)
|
|
(parameterize ("step")
|
|
((param value p old new) . args)
|
|
rest
|
|
body))
|
|
((parameterize ((param value) ...) . body)
|
|
(parameterize ("step")
|
|
()
|
|
((param value) ...)
|
|
body))))
|