The meaning of `isFunction`

I was hoping isFunction might be a “protocol identifier”, but alas only Function itself and its subclasses make it true. BinaryOpFunction.isFunction is false for instance. There are no actual uses for isFunction in the class library… but I found the need myself to treat BinaryOpFunction as “the same”, meaning I need to call value on it to “resolve” it, i.e.

f = {42}
g = f + 3

f.value // 42
g.value // 45

g.isFunction // -> false

Of course it is trivial to do

g.isKindOf(AbstractFunction) // -> true

instead, but I was wondering what the meaning of isFunction is actually supposed to be.

isX and asX are convenience methods. E.g. there’s asArray, but sometimes you need as(Array)

Note also that not all AbstractFunctions are interchangeable with Functions (Pattern and UGen in particular). So isKindOf(AbstractFunction) is a bit dangerous if you expect to .value the object.

I do think it would be reasonable for XxxOpFunctions to answer true here. Seems like a minor oversight. Feel free to submit a PR.


1 Like