summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-03-09 08:46:43 -0400
committerDavid Thompson <dthompson2@worcester.edu>2015-03-09 08:46:43 -0400
commit8ac70ff3cef2963c460ce5382e37946eb0a4914e (patch)
tree1d63d0dc71997dc0e30acac168377d79cdfbd3e1
parent7aa9d9e5dcd3dbb459343bb2372372d875cea95c (diff)
signals: Add signal-timer.
* sly/signal.scm (signal-timer): New procedure. * doc/api/signals.texi: Document it.
-rw-r--r--doc/api/signals.texi5
-rw-r--r--sly/signal.scm7
2 files changed, 11 insertions, 1 deletions
diff --git a/doc/api/signals.texi b/doc/api/signals.texi
index a4e2c01..9f674e1 100644
--- a/doc/api/signals.texi
+++ b/doc/api/signals.texi
@@ -191,6 +191,11 @@ Create a new signal that takes on the value of @var{signal} every
Create a new signal that emits @var{step} every @var{step} ticks.
@end deffn
+@deffn {Scheme Procedure} signal-timer [@var{step}]
+Create a new signal that emits the total time elapsed since its
+creation every @var{step} (1 by default) ticks.
+@end deffn
+
@deffn {Scheme Procedure} signal-since @var{step} @var{signal}
Create a new signal that emits the time since @var{signal} was updated
ever @var{step} ticks.
diff --git a/sly/signal.scm b/sly/signal.scm
index 788bb25..83f1ea5 100644
--- a/sly/signal.scm
+++ b/sly/signal.scm
@@ -50,7 +50,7 @@
signal-tap
signal-timestamp signal-time
signal-sample
- signal-every signal-since
+ signal-every signal-timer signal-since
signal-delay
signal-throttle
signal-generator))
@@ -366,6 +366,11 @@ ticks."
"Create a new signal that emits STEP every STEP ticks."
(signal-sample step (make-signal step)))
+(define* (signal-timer #:optional (step 1))
+ "Create a new signal that emits the total time elapsed since its
+creation every STEP ticks."
+ (signal-fold + 0 (signal-every step)))
+
(define (signal-since step signal)
"Create a new signal that emits the time since SIGNAL was updated
every STEP ticks."