Ok, so since we all move this way, let the thread cover this as well (btw. @jamshark70 thanks for chiming in! I just tried to keep things easier to overview).
If we support KeywordArgs as a way to pass keyword arguments to objects in messages, then this would have to be true all over the system. Would be great to have, let’s see how clearly it can be done.
Here is also a Pull Request that solves the problem “from the other side”. It is ready for discussion, too, was a lot of work, so be kind and careful :):
0A means SendMsgX, which is send message with keyword arguments
05 is how many things are on the stack ('obj', 1, 2, 'a' & 3).
the next value 01 tells us how may keyword arguments there are. \obj.asdf(1, 2, a: 3, b: 4) produces 0A 07 02 00, for the 2 keyword args.
I don’t know what the final 00 is.
That PR just turns the stack from this:
obj, 1, 2, a, 3
into this
obj, [1, 2], [a, 3]
Then calls doesNotUnderstandWithKeys.
That would mean the interpreter would have to loop over all arguments to every sendMsg to see if the slot is a kind of KeywordArg, then switch behaviour, unpacking it, rather than switching in the parser. This could incur a performance cost as it would have to happen everywhere.
Regarding expanding KeywordArgs automagically onto the stack…
I think switching on class when passing arguments will be confusing… but you could generalise this even more in a smalltalk way…
and maybe functionPerformWith{|selector, args, kwards, lookupInCurrentEnvir| ... } for prototyping.
These would all be primitives.
This would incur a small performance cost over existing methods, but reduce the amount of C++ that needs to be maintained and, I think, it very explicit.
There’s no way to process arguments without looping over them – when encountering a KeywordArgs, just dispatch to that part of the code. No need to overcomplicate.
Illegal, per language syntax definition. Keywords args must be in the last position, and there’s no reason to support multiple instances. (If the user does the above, 1. Runtime error for multiple KeywordArgs instances, which would be disallowed. 2. Warning because Synth *new has no a argument.)