[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Parameter completition
- From: "Eric Ries" <eries@...>
- Date: Thu, 10 Jan 2002 16:25:46 -0800
I don't understand this example. What output do you desire? Would having
functions with "optional default" arguments (as in C++) solve your problem?
Something like:
NotGiven = -1
function foo( a, b = NotGiven )
if b == NotGiven then
-- b was not passed in
else if b == nil then
-- b was passed in as "nil"
else
-- b was passed in with a non-nil value
end
end
Eric
> -----Original Message-----
> From: owner-lua-l@tecgraf.puc-rio.br
> [mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of Markus Huber
> Sent: Thursday, January 10, 2002 4:13 PM
> To: Multiple recipients of list
> Subject: Parameter completition
>
>
> The following example shows, why I need boolean:
>
> false = 0
> true = 1
>
> function Complete(Parameter,Value)
>
> if Parameter==nil then
> Parameter=Value
> end
>
> return Parameter
>
> end
>
>
> function Test(Parameter1,Parameter2)
>
> Parameter2=Complete(Parameter2,true)
>
> print(Parameter1)
> print(Parameter2)
>
> end
>
> Test(3) -- prints 3 1
> Test(3,nil) -- prints 3 1
>
> Test(3,false) -- prints 3 0
> Test(3,true) -- prints 3 1
>
>
> In this example if Parameter2 not given then it should be used the
> default. Is it possible to give the parameter as a reference instead of
> a copy? Then I could write much shorter: Complete(Parameter2,true)
> instead of typing the variable name twice.
>
> Its impossible to use "nil" or "not nil" for Parameter2 as a flag.
> Because "nil" is interpreted as a non given parameter.
>
> Thanks for any comments.
>
> --
> Markus
>