lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

>using a trailing comma here would fix both:
>    return 1,2,
>would return one value only

The idea that “1,2,” (and presumably “1,2,3,” etc.) would generate code that evaluates to “1” does not meet my definition of “clarity” :-) Presumably, given that this all started with a function that returned zero values being confused with one that returned exactly one value, your notation would also neee to work so that:

return ,

would generate the same code as:

return nil

and not the same as just:


which seems needlessly peculiar to the point of confusion, if you ask me.

I simply don’t see any problem that needs solving here. 

string.byte() is clearly documented to return zero or more values. So string.byte(‘A’,2) clearly should return zero values. If you wish to use a function that can return zero, one or more values in a place where exactly one value is required, just be explicit:

local val = string.byte(‘A’,2)
return val

If you want a variant of string.byte() that always returns exactly one value, or else reports an error, create a function wrapper that is defined to do just that and document (say) that it returns a single numeric code, or nil,error. (Or should I be writing “fail,error” these days?)