Interpreter 6: Perl

Nov 16, 2011 02:43

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 )

Leave a comment

Comments 14

wjl November 16 2011, 03:36:12 UTC
Regarding multimap, your assessment for typed languages seems spot on. I know I've seen code for such a beast on Rob's whiteboard, though, so it's an idea that's out there; I wouldn't be surprised if Rob saw it in some lisp and was trying to figure out how to type it.

Reply

wjl November 16 2011, 03:41:26 UTC
I haven't tried to understand this: Data.List.ZipWithN. References Scheme's polyvariadic map!

Reply

gwillen November 16 2011, 04:35:02 UTC
Wow, crazy. That is clearly the thing-I-want. And apparently this implies that map in scheme can do that thing I want too. Awesome.

Reply

zahariel November 16 2011, 19:56:55 UTC
wjl, that's pretty crazy.

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


aleffert November 16 2011, 04:04:42 UTC
I never remember the details of those features, but I bet you can do your multi for using list comprehensions in at least one of haskell and python.

Reply

gwillen November 16 2011, 04:33:14 UTC
The list comprehensions I've seen wouldn't let you do parallel-for -- they let you do cartesian-product-for, if that makes sense.

Reply

aleffert November 16 2011, 04:39:15 UTC
I think I thought that there was some way to make it zip in at least one of them, but I can't find it so maybe not.

Reply


physics_dude November 16 2011, 05:47:53 UTC
It sounds like by multimap you mean one or both of the following: rule out the unequal-lengths case at compile time, and have multimap itself be a first-class function. If you forego both of those, it is pretty trivial to add it as a syntactic construct to any typed language.

Reply


vatine November 16 2011, 06:43:10 UTC
If you're playing in the Common pool, there's always the joys of LOOP.

(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

gwillen November 16 2011, 06:45:41 UTC
Goodness, I forgot about loop. Three cheers for the insanity of CL.

Reply

vatine November 16 2011, 08:52:24 UTC
LOOP is horrible and wonderful.
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

Up