summaryrefslogtreecommitdiff
path: root/sly/utils.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-01-19 21:37:37 -0500
committerDavid Thompson <dthompson2@worcester.edu>2015-01-19 21:37:37 -0500
commit79a6a3efc46c50266e8167c476f05963149ad17c (patch)
tree288de24d2bcdf8d0852a252798941b3499d26032 /sly/utils.scm
parent039453697ec95d3b0bbc5ed25298768df9bdf792 (diff)
utils: Add vlist-ref* and list->vlist*.
* sly/utils.scm (vlist-ref*, list->vlist*): New procedures. * doc/api/utils.texi: Document them.
Diffstat (limited to 'sly/utils.scm')
-rw-r--r--sly/utils.scm21
1 files changed, 20 insertions, 1 deletions
diff --git a/sly/utils.scm b/sly/utils.scm
index 7256ab6..0e38fe4 100644
--- a/sly/utils.scm
+++ b/sly/utils.scm
@@ -23,6 +23,8 @@
;;; Code:
(define-module (sly utils)
+ #:use-module (ice-9 match)
+ #:use-module (ice-9 vlist)
#:use-module (srfi srfi-1)
#:use-module (rnrs arithmetic bitwise)
#:use-module (sly agenda)
@@ -30,7 +32,8 @@
memoize
forever
trampoline
- chain* chain))
+ chain* chain
+ list->vlist* vlist-ref*))
(define-syntax-rule (define-guardian name reaper)
"Define a new guardian called NAME and call REAPER when an object
@@ -78,3 +81,19 @@ same thread that is running the game loop."
(define-syntax-rule (chain arg (proc ...) . rest)
(chain* (list arg) (proc ...) . rest))
+
+(define (list->vlist* lst)
+ "Convert LST and all sub-lists within to vlists."
+ (list->vlist
+ (map (match-lambda
+ ((sub-lst ...)
+ (list->vlist* sub-lst))
+ (obj obj))
+ lst)))
+
+(define (vlist-ref* vlist index . rest)
+ "Return the element at index INDEX ... in the nested vlist structure
+VLIST."
+ (if (null? rest)
+ (vlist-ref vlist index)
+ (apply vlist-ref* (vlist-ref vlist index) rest)))