From a4c4af2cb793850b09b39bd3564668f3b189a2f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 20 Apr 2020 02:15:33 +0200 Subject: Change cross-product to take any number of lists. --- module/util.scm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'module') 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) -- cgit v1.2.3