Is it possible to integrate the similar functions into one, by expending its abilities.
For instance: max; maximum; findmax.
can you give an example of your desired syntax?
These functions all have different use cases - max
returns the maximum of its arguments, findmax
returns the index of the maximal element in the given collection and maximum
returns the maximal element itself. While it could be argued that max
and maximum
can be merged, findmax
serves a different purpose and should imo stay separate. Additionally, the maximum
function allows for a function to be called on each element of the given collection before reducing.
A generalization I could think of is allowing an arbitrary comparison operator for findmax
& friends instead of the hardcoded isless
. Then findmin
just amounts to using !isless
, etc.
Cf
I don’t know about merging but personally I always found that the current maximum
should be named max
(for example switch the two names). My feeling is that people (surely me) are using maximum
much more often than max
, so it’s a bit annoying that the long version has to be typed more often. Also, while not a particularily strong argument, in other PLs max
is often Julia’s maximum
.
Cf
https://github.com/JuliaLang/julia/issues/4652
and the detailed explanation in the referenced discussion
Yes, they are different, due to acting on different data structures.
It seems both maximum and findmax targeting the same data structure?
If that, can it be using maximum(a, dims=1, position=true) instead of findmax?
Theoretically yes — the compiler is now smart enough (I think) to do the constant folding, so in general any two functions can be combined into a single one:
f(args...) = "something"
g(args...) = "something else"
fg(args...; do_f = true) = do_f ? f(args...) : g(args...)
So sure, it is possible, but it may not be a proposal that would gather wide support, as findmax
and maximum
share neither their purpose nor their implementation.