[edited due to missing # in answer]
It's kind of janky to go that route, since the intent of
constantly is to allow a function of arbitrary arguments that always returns a constant. The #(...) anonymous function shorthand provides quick ways of defining anonymous functions working on various arities
0 - #(vector)
1- #(vector %1)
2 - #(vector %1 %2)
n - #(vector %1 %2 ... %n)
& args - #(apply vector %&)
There' some limitations though, since you are defining the body of the function....it will end up looking like an invocation if you try to define something like identity...
#(%) ;;this will try to invoke the single argument as if it were a unary function.
A way around this is to bind the input in a let or some other form to communicate the arity...
#(let [v %] v)
will work like identity, we just return it in the body.
We want to define a function of variable args though, so we want %& to indicate the args. Yet the args are meaningless for the result...the only communicate to the anonymous function sugar the number or arity of the args.
While awkward, this is one way to do it:
(defn constantly2 [v]
;;ignore the arguments, but communicate a varargs function
#(let [_ %&]
user=> (def f (constantly2 10))
user=> (f 1 2 3 4)
user=> (f 1)
user=> (f 5)
user=> (f :a)
I would probably avoid using the #(..) syntax sugar for these kinds of things. The shorthand is most useful for very simple inline anonymous functions, and even then I typically prefer to write out the