[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Syntax request (coming to terms with false)
- From: Tom Wrensch <twrensch@...>
- Date: Fri, 18 Jan 2002 14:02:14 -0800 (PST)
On Thu, 17 Jan 2002 RLake@oxfam.org.uk wrote:
>
> OK, I'm trying to come to terms with false. I've started going through my
> code looking for places where I assign the result of a boolean expression
> to a table expecting nil to delete the key (since false will no longer do
> that). Maybe I'm the only person with this problem.
>
> if t = function_which_might_return_false(x) then
> a[x] = t
> else
> a[x] = nil
> end
This, at least, could be made less painful with a function that converts
false to nil, similar to what you were discussing with the
? operator. Thus:
function ftn(x) -- False to Nil function
if x==false then
return nil
else
return x
end
end
You example then becomes:
a[x] = ftn(function_which_might_return_false(x))
You may need to make other versions when you want to handle multiple
return values of course, though I find I rarely use them.
- Tom Wrensch