sclang allows to call methods in a “functional” style by passing the receiver as the first argument. You typically see this with control flow methods like if or while:
I just found it surprising that there was a special syntax for when you want to do that with an operator. I was looking through the bison file when I found it and though, what on earth is that, but it makes sense given that goal!
It does look confusing, but I think it is mostly caused by fill working with arrays.
I know I just thought it was really confusing syntactically. It seem the only unique behaviour is in setting operator adverbs through arguments. (+)(1, 2, _).
I may have misunderstood your post, but I don’t think this is a special syntax.
The underscore notation (_+_) is indeed (i believe) is just syntax for placeholder arguments, creating a function with implicit parameters. Not sure how far it can pass an operator as a first-class function just using parenthesis. It does not seem to work here.
I have seen more code like this:
~applySymOp = {|symbol, a, b| a.perform(symbol, b)};
~applySymOp.value('+', 5, 3);
Right?
Also works:
~applyOp = {|func, a, b| func.(a, b)};
~applyOp.(_+_, 5, 3);
And:
var add = _+_;
var subtract = _-_;
var multiply = _*_;
var divide = _/_;
add.(5, 3).postln;
subtract.(5, 3).postln;
multiply.(5, 3).postln;
divide.(6, 3).postln;
EDIT: Oh, I read your other message, and you figured that out already.
Exactly, that’s why I did a comparison. In Haskell, an infix operator automatically becomes a prefix operator with parenthesis (that’s just a syntax rule), but is often necessary topass it as first-class function to another function, for example.
It is very consistent in the the other language, not SC.