Ruby has a variable argument syntax as well as fixed number of arguments
syntax. The caller does not know about how the called function's syntax.
In case of variable arguments, it is expected caller to provide with
number of arguments while for the other case it might not.
Since, I am writing a VM for Ruby, I would like to know how should one
handle this problem?
How can you say caller know about the number of arguments. It might be
possible that it call the function with all what he has and caller
responds with "I am being called with too few or too many arguments".
This can be shown as the error you have indicated.
About VM, it is open source and will be uploaded in a week or so.
How can you say caller know about the number of arguments. It might be
possible that it call the function with all what he has and caller
responds with "I am being called with too few or too many arguments".
This can be shown as the error you have indicated.
But you can check the method's arity before calling it. If it's a positive number then it expects exactly that many arguments. If it's a negative number it expects at least ~arity arguments. Is this not what you asked?
"Florian Gross" <flgr@ccan.de> schrieb im Newsbeitrag
news:34ihugF4b43vqU1@individual.net...
Mystifier wrote:
> How can you say caller know about the number of arguments. It might be
> possible that it call the function with all what he has and caller
> responds with "I am being called with too few or too many arguments".
> This can be shown as the error you have indicated.
But you can check the method's arity before calling it. If it's a
positive number then it expects exactly that many arguments. If it's a
negative number it expects at least ~arity arguments. Is this not what
you asked?
Florian, I'm as confused as you. After all, ArgumentError is a runtime
error - an exception. So whatever he does about method invocation etc.
the VM has to be able to deal with exceptions in the same way the
interpreter does. You just invoke the method with the arguments you have
and see what happens. That's it IMHO.