Sam Roberts
1/30/2005 4:15:00 AM
Quoteing brian@brianandkate.com, on Sun, Jan 30, 2005 at 12:57:20PM +0900:
> I am a bit new to this, so please be gentle. I was wondering about the
> rational of using 'nil' to represent not only 'nothing' but also
> 'false' in a conditional expression. In the very few other languages I
> am familiar with, nil (null) is nothing wile 0 is the return for false.
Could this be perl?
In C (exprs evaling to) zero is false, anything else is true, including
empty strings, "".
In perl, zero is false, but also the empty string is false, and don't
you get an error if you try to test undef?
In ruby, zero and empty strings are true, and nil kinda means what undef
does, except you can test it.
I *think* that in Pascal, only booleans (true/false) can be tested for
truth, numbers, ptrs, funs, these things are not allowed to be used
as if they were booleans. Don't quote me, I haven't done any pascal.
So, I'd say there isn't anything particularly the same about any of
those 4 languages.
> Could this be an area that may cause some problems for those
> inexperienced in ruby (like myself)?
If it was exactly like some other language (that you have
experienced), it will be unlike some other language that somebody
else has experienced.
How languages treat booleans is one of the things usually different, and
a src of much flame wars, so when moving between languages you shouldn't
assume anything, you need to ask.
Have fun,
Sam