diff options
author | David Thompson <dthompson2@worcester.edu> | 2015-01-19 21:37:37 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2015-01-19 21:37:37 -0500 |
commit | 79a6a3efc46c50266e8167c476f05963149ad17c (patch) | |
tree | 288de24d2bcdf8d0852a252798941b3499d26032 /sly/utils.scm | |
parent | 039453697ec95d3b0bbc5ed25298768df9bdf792 (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.scm | 21 |
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))) |