News for hackers. Stuff that matters.
Re:PEP 0448 – Additional Unpacking Generalizations by mraison on Saturday July 18, 2015 @02:43AM (#9906798)
Whenever I see a new feature proposal for a programming language, I like to check how a language in the lisp family could solve the same problem with a macro (not trying to point out who is better than who, it's just for fun). For example, this 3-liner would get you the "multiple array unpacking" in clojure:

    (defmacro pep448 [f & args]
      (let [unpack? #(and (list? %) (= (first %) '$))]
        `(apply ~f (concat ~@(map #(if (unpack? %) (second %) [%]) args)))))
which can be used like this:

    (pep448 + ($ [2 3]) 4 ($ [5 6 7]))
    => 27
A bit verbose, so you probably wouldn't do it this way in real life. Thankfully there are generally easier and more elegant ways to handle this kind of situation.

There are no comments on this comment yet.