> On Feb 25, 2021, at 10:12 AM, Norman Gray <
norma...@glasgow.ac.uk> wrote:
>
>
> I think this is called 'zip', or a convolution [1]. The variant you describe is (effectively) with circular lists, but seems to be the same principle.
>
> ...and I see that, with that name in hand, SRFI/1 does indeed have a zip procedure, which works with circular lists.
Thanks, Norman! Looks like “zip” is the right name for the general process, and now that I can browse the docs for it there seems to be several flavors in various library modules, depending on creator intention. I’ve generalized mine a bit to fit intention and some of theirs.
(define/contract (zip #:length (len max) . lsts)
(->* () (#:length (or/c procedure? natural?)) #:rest (listof list?) (listof list?))
(define (loop cnt (acc empty))
(cond
[(zero? cnt) acc]
[else
(define n (sub1 cnt))
(loop n (cons (map (λ (lst) (list-ref lst (modulo n (length lst)))) lsts) acc))]))
(loop (cond
[(procedure? len)
(apply len (map length lsts))]
[else len])))
Kevin