summaryrefslogtreecommitdiff
path: root/2d
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-02-17 18:45:56 -0500
committerDavid Thompson <dthompson2@worcester.edu>2014-02-17 18:45:56 -0500
commit116446cb2a77d47393ef1caa372e61e8a51535d9 (patch)
treea67652fb6e776d9d7f48aba1895ed51c42bdf560 /2d
parent64de4d1bfe1a2d67b8aa3e846d8d86760682b395 (diff)
Add hook->signal procedure.
* 2d/signal.scm (hook->signal): New procedure.
Diffstat (limited to '2d')
-rw-r--r--2d/signal.scm11
1 files changed, 11 insertions, 0 deletions
diff --git a/2d/signal.scm b/2d/signal.scm
index 53f676a..4d6fe3f 100644
--- a/2d/signal.scm
+++ b/2d/signal.scm
@@ -30,6 +30,7 @@
signal-box?
make-signal
define-signal
+ hook->signal
signal-ref
signal-ref-maybe
signal-set!
@@ -148,6 +149,16 @@ be spliced into the new signal."
;;; Higher Order Signals
;;;
+(define (hook->signal hook init proc)
+ "Return a new signal whose initial value is INIT and has future
+values calculated by applying PROC to the arguments sent when HOOK is
+run."
+ (let ((signal (make-signal init)))
+ (add-hook! hook
+ (lambda args
+ (signal-set! signal (apply proc args))))
+ signal))
+
(define (signal-merge signal1 signal2 . rest)
"Create a new signal whose value is the that of the most recently
changed signal in SIGNALs. The initial value is that of the first