I wanted a function in the style of zip
, but rather than stopping when one of the supplied lists runs out, I wanted it to continue using zip
on the rest of the lists.
Looking around at a few Emacs functions (referring mainly to those internal to Emacs and in the Common Lisp, and dash.el
extensions), I found a few functions like mapcar*
, -zip
, and -zip-fill
that were close to what I was looking for, but ended when one of the given lists ran out.
I ended up writing my own function, but I'm interested in knowing why many of the functions I saw implement this behavior. Looking online, it appears that this is the most common interpretation of how zip
should work.
Would my desired function be considered zip
? I figure it may be called something else, unless is a specialized unnamed variant.
To hopefully clarify myself some, here is the function I wrote:
(defun my-zip-alt (&rest lists)
(when lists
(cons (mapcar #'car lists)
(apply #'my-zip-alt (delq nil (mapcar #'cdr lists))))))
;; (my-zip-alt '(1 2 3) '(4 5) '(6) '(nil))
;;=> ((1 4 6 nil) (2 5) (3))
Recommendations for making my function simpler or more efficient are welcome, of course :)