Argument matching
Michael O'Brien
mob at mbedthis.com
Fri May 9 11:09:11 PDT 2008
Comments below:
On May 9, 2008, at 10:43 AM, Lars Hansen wrote:
> In strict code ("use strict") the number of passed arguments must
> match
> the number of expected arguments. This has been agreed upon.
I presume that is at execution time?
>
>
> I would expect that if too few arguments are passed to a function with
> a typed interface then you get a type error unless the missing
> parameter
> has a type that includes "undefined" (ie no conversion takes place).
See comment in following email about Array.some callbacks.
>
> Signalling an error "because the function has a typed interface" is
> a variant, I guess, but it seems like an orthogonal concern.
>
> I would expect excess arguments to typed functions to be ignored
> silently,
> as they can be picked up by 'arguments' inside the function.
I think this is the only approach that will work for standard mode code.
So for Array.some in strict mode, the user must supply 3 typed
arguments for the callback.
But in standard mode, they can either do that, or supply one untyped
arg.
I can't think of a better solution (yet).
Michael
>
>
> --lars
>
>> -----Original Message-----
>> From: es4-discuss-bounces at mozilla.org
>> [mailto:es4-discuss-bounces at mozilla.org] On Behalf Of Michael O'Brien
>> Sent: 9. mai 2008 10:30
>> To: es4-discuss Discuss
>> Subject: Argument matching
>>
>> What should ES4 do when there are too many or too few arguments?
>>
>> Seems that the RI will apply different behavior depending on
>> whether the function arguments are typed or not. This is not
>> necessarily unexpected. I just want to nail down the rules as
>> the RI and AS3 behave differently in this regard.
>>
>> Consider:
>>
>> function fun(a, b) {
>> print(a);
>> print(b);
>> }
>>
>> Calling this with:
>>
>> fun(1) prints
>> 1
>> undefined
>>
>> fun(1,2,3,4) prints
>> 1
>> 2
>>
>> fun(1,undefined)
>> 1
>> 0
>>
>> both work without error.
>>
>> But if either arg is typed:
>>
>> function fun(a: int, b) {
>> print(a);
>> print(b);
>> }
>>
>> In this case, the following all get TypeErrors
>>
>> fun(1)
>> fun(1, undefined)
>> fun(1,2,3,4)
>>
>> Interestingly, ASC will coerce "undefined" to 0 if supplied
>> with the correct number of arguments and they are typed as ints.
>>
>> What are the rules for ES4?
>>
>> - If you type formal arguments, it seems the caller must
>> supply the correct number and type of actual parameters
>> - If you don't type the formal arguments, you can supply too
>> few or too many arguments
>> - Should undefined be coerced to 0 if the type is an integer?
>>
>> Michael
>> _______________________________________________
>> Es4-discuss mailing list
>> Es4-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es4-discuss
>>
More information about the Es4-discuss
mailing list