summaryrefslogtreecommitdiff
path: root/2d
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@member.fsf.org>2013-11-30 12:33:31 -0500
committerDavid Thompson <dthompson@member.fsf.org>2013-11-30 12:33:31 -0500
commit781a3dcacedc210e51e9dfc6669b4319a48878ab (patch)
tree2817a2f9bb10811a3f470c6b7cd74ca0e65d1d01 /2d
parentdec204b546e128dcf3eb7ad30a21e97ead1a69f1 (diff)
Add signal-ref-maybe procedure.
* 2d/signals.scm (signal-ref-maybe): New procedure.
Diffstat (limited to '2d')
-rw-r--r--2d/signals.scm10
1 files changed, 9 insertions, 1 deletions
diff --git a/2d/signals.scm b/2d/signals.scm
index 4a455c2..28d2c6f 100644
--- a/2d/signals.scm
+++ b/2d/signals.scm
@@ -29,6 +29,7 @@
signal?
make-signal
signal-ref
+ signal-ref-maybe
signal-transformer
signal-listeners
signal-connect!
@@ -66,12 +67,19 @@
(init #f) (connectors '()))
"Create a new signal with initial value INIT that uses the given
TRANSFORMER procedure to process incoming values from another
-signal. Additionally, the signal will be connected to all of the
+signal. Additionally, the signal will be connected to all of the
signals in the list CONNECTORS."
(let ((signal (%make-signal init transformer '())))
(for-each (cut signal-connect! <> signal) connectors)
signal))
+(define (signal-ref-maybe object)
+ "Dereferences OBJECT if it is a signal and returns OBJECT
+otherwise."
+ (if (signal? object)
+ (signal-ref object)
+ object))
+
(define (%signal-transform signal value from)
"Call the transform procedure for SIGNAL with VALUE."
((signal-transformer signal) value (signal-ref signal) from))