From 9958edd9d61f13b181a9f44ec12f713d5819451a Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 25 Apr 2016 08:54:51 -0400 Subject: actor: Add apply-effects procedure. * sly/actor.scm (apply-effects): New procedure. * doc/api/scripting.texi (Actors): Document it. --- doc/api/scripting.texi | 6 ++++++ sly/actor.scm | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/doc/api/scripting.texi b/doc/api/scripting.texi index 299cf0f..77ef734 100644 --- a/doc/api/scripting.texi +++ b/doc/api/scripting.texi @@ -157,6 +157,12 @@ new actor containing the value returned from @var{proc}. The actor's action remains unchanged. @end deffn +@deffn {Scheme Procedure} apply-effects @var{effects} @var{world} +Apply each effect procedure in @var{effects} using @var{world} as an +initial value. Each successive effect is applied with the world +returned by the previous effect. +@end deffn + @node Actions @subsection Actions diff --git a/sly/actor.scm b/sly/actor.scm index 90803e7..b63a66d 100644 --- a/sly/actor.scm +++ b/sly/actor.scm @@ -35,6 +35,7 @@ update-actor actor-filter-update call-with-actor + apply-effects action-lift action-effect-lift @@ -92,6 +93,14 @@ containing the value returned from PROC." (let ((new (proc (actor-ref actor)))) (make-actor new (actor-action actor)))) +(define (apply-effects effects world) + "Apply each effect procedure in EFFECTS using WORLD as an initial +value. Each successive effect is applied with the world returned by +the previous effect." + (fold (lambda (effect world) (effect world)) + world + effects)) + ;;; ;;; Actions -- cgit v1.2.3