> On Feb 25, 2021, at 10:12 AM, Norman Gray <[email protected]> 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
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/650A2841-B8F8-4802-9116-7AB9876EA901%40gmail.com.