lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


If It is possible, How can I make the operations with the nil value?


=================
>De:Luis Carvalho <carvalho@fritz.cfm.brown.edu>
>Para:Lua list <lua@bazar2.conectiva.com.br>
>Assunto:Re: NIL in arith. and string op.
>
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>> Is it possible - if nil used in arithmetic or
>> string (concat.) operations set it's value
>> to 0 or empty string, not raising error?
>> 
>> Eg., 10 + nil == 10; "ab"..nil.."c" == "abc"
>
>I think it is, but why? A simpler solution is:
>
>a = 2 + (nil or 0) + 5 	 -- a = 7
>c = "Merry " .. (nil or "") .. "Christmas!"
>
>Cheers,
>Luis.
>
>- -- 
>Mathematicians practice absolute freedom.
>		 -- Henry Adams
>
>- -- 
>Luis Carvalho
>Applied Math PhD Student
>Brown University
>carvalho at dam dot brown dot edu
>
>PGP Key: E820854A <carvalho@dam.brown.edu>
>Available at:
>http://www.dam.brown.edu/people/carvalho/pgp-key
>
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.2.1 (GNU/Linux)
>
>iD8DBQE/6u9Z1zi/pugghUoRAikQAKCcj3KWkSXt0I21o2Qg
>hlceP6ISUwCg5duE
>kE5jKKIrJmB9ioTsKish8lw=
>=aZhb
>-----END PGP SIGNATURE-----