Okay, so I went ahead and wimped out and did an easy one because I'm behind. Perl's a language I already know well, and I did basically a straight-up port of the Pike version. They turn out to be very similar languages! There are some interesting points of comparison between them.
(
Notes )
Comments 14
Reply
Reply
Reply
Ruby has this multimap, exactly as you want it, in array.zip. Python's map builtin does it too. Of course, these are both unityped at compile time.
Reply
Reply
Reply
Reply
Reply
(loop for foo in foo-list
for bar in bar-list
for gazonk in gazonk-list
collect (list (foo-mangle foo) (bar-mangle bar) gazonk))
Making a macro that makes this "just happen" would be, well, an exercise in macrology.
Reply
Reply
Of course, there's the insanity of:
(defun multi-mapcar (fun-list &rest data-lists)
(labels ((helper (data-lists acc)
(cond ((every #'null data-lists) (nreverse acc))
(t (helper (mapcar #'cdr data-lists)
(cons (mapcar #'funcall fun-list
(mapcar #'car data-lists))
acc))))))
(helper data-lists nil)))
So it's only a function definition away (I thought "default missing elements in less than all data lists as NIL" was about as clean as terminating when the shortest list was done, if you prefer that, s/every/any/).
Reply
Leave a comment