3 ms·
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 (n
by mraison 11y ago
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.