[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: not
- From: "John Miley" <mileyj@...>
- Date: Thu, 27 Jul 2000 09:38:13 -0500
Why can't you do:
if(t.whatever == nil)
blah blah
end
?
--jsm
John S. Miley
Programmer/Analyst
Public Systems Associates
mileyj@publicsystems.org
225-709-2666
----- Original Message -----
From: John Passaniti <jmp@pt.com>
To: Multiple recipients of list <lua-l@tecgraf.puc-rio.br>
Sent: Thursday, July 27, 2000 9:11 AM
Subject: not
>
> Maybe there is a trick here I don't see, but.....
>
> Many times in my Lua code, I'll test that a key appears in a table and do
> something:
>
> if t.whatever then
> do_something()
> end
>
> But today was the first time that I found I needed to test for the
opposite
> case-- that of t.whatever not existing. It's then I realized that Lua
> doesn't have a logical "not".
>
> It's easy enough to create a function that implements a logical "not":
>
> function not(x)
> if x then
> return nil
> else
> return 1
> end
> end
>
> And use it like this:
>
> if not(t.whatever) then
> do_something()
> end
>
> But is forcing a functional syntax and having the cost of of a function
> call what the designers of Lua intended? I admire the minimalism in Lua,
> but this seems like a pretty basic need for most any language. Without
it,
> you're either forcing the programmer to come up with their own logical
> "not" or forcing them to have an empty "then" clause in an "if," doing the
> work in the "else" clause.