From 781a3dcacedc210e51e9dfc6669b4319a48878ab Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 30 Nov 2013 12:33:31 -0500 Subject: Add signal-ref-maybe procedure. * 2d/signals.scm (signal-ref-maybe): New procedure. --- 2d/signals.scm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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)) -- cgit v1.2.3