Function stored in event with default args: is this possible?

Trying to specify a keyword argument in a function stored in an event fails with an exception.
I’m not sure I understand what is happening here, or if this can somehow be made to work?

(
e = (\test : { | self, a, b=1 | a+b; });
e.test(1); // gives 2 = OK!
e.test(5, 4); // gives 9 = OK!
e.test(5, b:3); // WARNING: keyword arg 'b' not found in call to IdentityDictionary:doesNotUnderstand
)

Nevermind, the syntax is wrong. This seems to work:
e.test(5, b=3);

No sorry, I reduced too much. It still doesn’t work.

(
e = (\test : { | self, a, b=true, longarg=false | (a||b||longarg); });
e.test(true); // gives true = OK!
e.test(false, b=false); // gives false = OK!
e.test(false, longarg:false); // WARNING: keyword arg 'longarg' not found in call to IdentityDictionary:doesNotUnderstand
e.test(false, longarg=false); // ERROR: Variable 'longarg' not defined.
)

I’m afraid not.

e[\test].value(e, ...) would connect the keyword arguments to the function arguments… but e.test(...) isn’t going down that code path.

The doesNotUnderstand handler doesn’t have access to the function’s argument names for keyword matching.

hjh

1 Like

Thanks for the reply. The e[\test].value(e,…) syntax will suffice!