aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-04-20 02:15:33 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-04-20 02:15:33 +0200
commita4c4af2cb793850b09b39bd3564668f3b189a2f4 (patch)
tree62944da263b6aafc21c1017e30e2b9f4c1dc6ef8
parentAdd ->> macro. (diff)
downloadcalp-a4c4af2cb793850b09b39bd3564668f3b189a2f4.tar.gz
calp-a4c4af2cb793850b09b39bd3564668f3b189a2f4.tar.xz
Change cross-product to take any number of lists.
-rw-r--r--module/util.scm9
1 files changed, 8 insertions, 1 deletions
diff --git a/module/util.scm b/module/util.scm
index c7535310..bb1fdcd5 100644
--- a/module/util.scm
+++ b/module/util.scm
@@ -416,13 +416,20 @@
;; Returns the cross product between l1 and l2.
;; each element is a cons cell.
-(define-public (cross-product l1 l2)
+(define (cross-product% l1 l2)
(concatenate
(map (lambda (a)
(map (lambda (b) (cons a b))
l2))
l1)))
+(define-public (cross-product . args)
+ (if (null? args)
+ '()
+ (let* ((last rest (car+cdr (reverse args))))
+ (reduce-right cross-product% '()
+ (reverse (cons (map list last) rest ))))))
+
;; Given an arbitary tree, do a pre-order traversal, appending all strings.
;; non-strings allso allowed, converted to strings and also appended.
(define-public (string-flatten tree)