[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: nil isn't as unique in Lua 4.1
- From: Victor Bogado da Silva Lins <bogado@...>
- Date: Thu, 10 Jan 2002 09:20:16 -0200 (BRST)
On Thu, 10 Jan 2002, Peter Shook wrote:
>
> I'd rather not have the boolean type because then there will be a need
> for functions like Perl's 'defined' (to tell if a variable is not nil)
> and 'exists' (to tell if a table has a value for a particular key). How
> else with you be able to tell if a variable is false or nil?
>
> In Lua 4.0, it is simple to delegate to another table:
>
> x = t1[i] or t2[i]
>
In perl it works the same way, undefined variables "return" nil
values, but there is a diference between undefined variable and variables
that were defined with a nil value.
for instance (in lua syntax):
a = nil
print (a)
print (b)
if (a) then print ("a isn't nil\n") else print ("a is nil\n")
if (b) then print ("b isn't nil\n") else print ("b is nil\n")
if (defined(a)) then print ("a is defined\n") else print ("a is undefined\n")
if (defined(b)) then print ("b is defined\n") else print ("b is undefined\n")
----
this program if it were perl would printout the following:
a is nil
b is nil
a is defined
b is undefined
--
[]'s Victor Bogado da Silva Lins
victor@visgraf.impa.br