Re:Try Clojure
by ReleaseCandidat on Wednesday May 22, 2024 @04:22PM
(#40445944)
Of course `+` and `*` are special, but defining such functions yourself is possible:
https://clojure.org/guides/learn/functions#_multi_arity_func...
https://clojure.org/guides/learn/functions#_variadic_functio...
Re:Try Clojure
by globular-toast on Thursday May 23, 2024 @05:22AM
(#40452438)
Yeah, it always annoys me to have to pass an initial argument. The idea of identities is built into Lisps and seems conspicuously missing from other languages and I don't know why. In Python and JS people have to write stuff like `lambda x: x` over and over again. The identity function is surely special enough to get its own name.
This does not involve an identity function?
It's just a textbook monoid: an operation on two elements which produces another (+ or *), with a "neutral" element provided (0 or 1).
Re:Try Clojure
by globular-toast on Saturday May 25, 2024 @05:08PM
(#40477886)
I know this isn't the identity function, but it's the same idea and a feeling I get when using Lisps that the language is kind of "complete". Including the identity function and having built in 0-ary functions where it makes sense are examples of this.
(In my functional programming languages, `reduce` also requires passing an initial value, like `foldl (+) 0 [1, 2, 3]`. But surely it should get a monoid instead of two separate arguments for the operation and the starting value!)