On Sun, Aug 14, 2011 at 6:08 AM, Mats Rauhala <[email protected]> wrote:
> Another function in the same way is 'const :: a -> b -> a' (on haskell,
> but easy to make in clojure if it doesn't exist) which
> disregards the second argument and always returns the first.
The functions returned by "constantly" in Clojure do something
similar. They accept any arity but return a constant value:
(defn constantly
"Returns a function that takes any number of arguments and returns x."
{:added "1.0"
:static true}
[x] (fn [& args] x))
It's not hard to make an exact copy of the Haskell behavior in Clojure:
(defn firstarg [x & args]
x)
(constantly x) then is expressible as (partial firstarg x). :)
--
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en