3 ms·
> might be impressive to someone who has never seen first class functions (though they'd probably ascribe it to syntactic tricks) It's not just using first-cla
by masklinn 15y ago
> might be impressive to someone who has never seen first class functions (though they'd probably ascribe it to syntactic tricks)
It's not just using first-class functions here, it's partially applying a flipped curried operator. That's not exactly common.
- jhuni 15y agoFlipped curried operator? You mean like this: (defn flip-arguments [func] (fn [& args] (apply func (reverse args)))) (prn (partition-by (partial (flip-arguments <) 60) [49 58 76 82 88 90])) I noticed Haskell does automatic currying. You can easily create that or basically any other language feature using Lisp macros: (defn currify [f n] (fn [arg] (if (= n 1) (f arg) (currify (partial f arg) (dec n))))) (defmacro currying-function [arg-names & code-args] `(currify (fn ~arg-names ~@code-args) ~(count arg-names))) (def gt (currying-function [a b] (> a b))) Once you experience the power of Lisp macros it is hard to go back to non-homoiconic languages such as Haskell that hide the underlying structure of the code. I am not impressed by the Haskell code shown here, flipping and currying are feature Lisps had back in the 1980s or earlier, before Haskell was born. Actually, I find the Haskell code rather revolting. First of all because of the horrid camel-case names (isInfixOf, parseXMLDoc, curlGetString, etc) then there is the very confusing syntactic constructs, like $ and <$>, and hard to interpret names like map, fmap, mapM_, foldl, and foldl1.