summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-07-22 21:28:17 -0400
committerDavid Thompson <dthompson2@worcester.edu>2014-07-22 21:28:17 -0400
commita16b75ba5504c1605fa5638e0cea14a2ab693e16 (patch)
treeb998bbe87b3026990a198fa0b40e7c022f08e26a
parent662b2b183f03b27e10ee99979b6d0e82565e2555 (diff)
Add signal-switch procedure.
* sly/signal.scm (signal-switch): New procedure.
-rw-r--r--sly/signal.scm13
1 files changed, 13 insertions, 0 deletions
diff --git a/sly/signal.scm b/sly/signal.scm
index f8545eb..3e5ce26 100644
--- a/sly/signal.scm
+++ b/sly/signal.scm
@@ -41,6 +41,7 @@
signal-filter
signal-reject
signal-drop-repeats
+ signal-switch
signal-constant
signal-count
signal-tap
@@ -258,6 +259,18 @@ testing equivalence."
(signal-ref signal)
signal))
+(define (signal-switch pred on off)
+ "Create a new signal whose value is that of the signal ON when the
+signal PRED is true, or the value of the signal OFF otherwise."
+ (define (current-value)
+ (if (signal-ref pred)
+ (signal-ref on)
+ (signal-ref off)))
+ (make-boxed-signal (current-value)
+ (lambda (self value)
+ (%signal-set! self (current-value)))
+ (list pred)))
+
(define (signal-constant constant signal)
"Create a new signal whose value is always CONSTANT regardless of
what the value received from SIGNAL."