diff options
author | David Thompson <dthompson2@worcester.edu> | 2014-02-17 18:45:56 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2014-02-17 18:45:56 -0500 |
commit | 116446cb2a77d47393ef1caa372e61e8a51535d9 (patch) | |
tree | a67652fb6e776d9d7f48aba1895ed51c42bdf560 | |
parent | 64de4d1bfe1a2d67b8aa3e846d8d86760682b395 (diff) |
Add hook->signal procedure.
* 2d/signal.scm (hook->signal): New procedure.
-rw-r--r-- | 2d/signal.scm | 11 |
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 |