[DGD] Re: casting nil (another idea...)

Par Winzell zell at skotos.net
Tue Mar 23 18:49:29 CET 2004


> I'd go for something like this:
> 
>     int nil_to_int(mixed v)
>     {
> 	return v == nil ? 0 : v;
>     }
> 
>     ...
> 
>     luck -= nil_to_int(query_property("luck_reduction"));
> 
> If you put the nil_to_int() in an inheritable it doesn't look so bad?

For every library that I've worked with in the past many years, I define 
  Int(), Str(), Arr(), etc, something like nil_to_int() above. Also 
useful is a Empty() macro/function that returns true for nil, empty 
strings, empty arrays, empty mappings, integer zero, ...

Zell

_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list