[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: not
- From: "Russell Y. Webb" <rw20@...>
- Date: Thu, 27 Jul 2000 07:34:23 -0700
As I'm sure tons of people are about to point out
if not t.whatever then
is part of the language. The not operator is cleverly called 'not' already.
>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
> if t.whatever then
>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
> return 1
>And use it like this:
> if not(t.whatever) then
>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.