I've sometimes found it convenient in Clojure to define reduced arity versions of functions, that return a partial function, e.g.
(defn prefix
([pre string]
(str pre ":" string))
([pre]
(fn [string]
(prefix pre string))))
This means that you can do either:
(prefix "foo" 78979)
=> "foo:78979"
((prefix "foo") 78979)
=> "foo:78979"
This seems quite Haskell-ish and avoids the need for partial
to create partial functions.
But is it considered good coding style / API design in Lisp?
Using partial
to create a curried function is based on the concept of Explicit is better (in most cases :)). And I have found that this concept to be more applicable/used in dynamically typed languages like Clojure, Python etc may be because of the missing type signature/static-typing it makes more sense to make things explicit .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With