Thanks for pointing it out. Still, it seems highly unlikely someone would decide to use such a function declaration yet want to use the proposed syntax to pass both positional and keyword arguments.
I didn't know the last one. Nevertheless I find the mix of functions with no arguments, function values and optionnal parenthesis quite confusing syntax wise.
I find the word “clamp” extremely satisfying for this concept, especially with optional named parameters in order to leave off one bound e.g. `x.clamp(low=10)` but it still works fine with both required and anonymous, it’s just a bit less convenient.
Thank you for sharing. I wish this were the default behavior of positional and keyword arguments rather than requiring a `/, *` in every function definition.
On 1 I'll just say it'd be nice if append (and other varargs functions) could take multiple of individually listed and slice-expanded args at the same time. As in: `append(a[:2], 3, a[2:]...)`. I already expect append to be O(n), and this would be some very nice sugar.
It gets really annoying when you have short single-arg functions. Imagine what swap(_:_) or Collection.suffix(_) would look like with mandatory first arguments.
It would make me sad to type getSqrt(), getMin(), getMax(), getStrLen(), getSizeOf(), get…
Putting a verb in the function name is not a bad idea, but if you find yourself identifying the verb as “get”, then it’s a useless three extra letters.
It would be far more useful if it supported function arguments. I wonder how much of the other features they'd have to give up to support those within 512 bytes.
"- Comment strings appearing before argument lists in
functions. I would like to see the entire protocol,
name and args, before reading the docstring which may
refer to the args."
I think writing one doc string for a multivariate function is better than having to write one for many. Check out clojure core's min function:
(defn ^number min
"Returns the least of the nums."
([x] x)
([x y] (cljs.core/min x y))
([x y & more]
(reduce min (cljs.core/min x y) more)))
So there are occasions for this related to efficiency. Where would you prefer the docstring?
I'm sorry, but I really see no point in this article.
Do you realize that if the optional arguments were not included in Function#length, you'd just be saying "They are not reflected in the function’s length property. C'mon, man" instead ?
reply