-> -----Original Message-----
-> From: Pit Capitain [mailto:pit@capitain.de]
-> Sent: Wednesday, May 19, 2004 9:53 PM
-> To: ruby-talk@ruby-lang.org
-> Subject: Re: Zero is true … whoda thunk?
->
-> To summarize in other words: there are the obvious tests for
-> boolean conditions
-> including predicates (true / false) and an implicit test for
-> success / no
-> success (not-nil / nil).
->
I agree. I might say it just a little differently. The obvious tests are
real boolean-like situations. Anything implicit, however, says that we
prefer a language with shortcuts. But if we accept shortcuts, why not the
shortcut 0 == false?
I’m okay with no shortcuts, too. But I find the argument saying, “‘0 ==
false’ is a programming cultural thing” to be a weak argument. There are
lots of shortcuts that make sense, once you allow for shortcuts.
-> Does this make more sense? Maybe not, it’s 03:50 AM…
->
In C, unless you declare them extern[1], variables are private to the
file they’re declared in. Using the $a notation is equivalent to
declaring the variable extern. It indicates you’re using a global
variable instead of a local one.
Perhaps the better question, though, is why do you need a global
variable? Every time I feel the urge to use a global variable, I ask
myself that question.
[1] E.g.: extern a = 1;
···
On May 20, 2004, at 9:08 AM, Dave Baldwin wrote:
This behaviour has rather surprised me:
file a.rb
a = 10
file b.rb
require “a.rb”
puts a
dave 123% ruby b.rb
b.rb:2: undefined local variable or method `a’ for main:Object
(NameError)
dave 124% ruby -v
ruby 1.8.1 (2003-10-31) [powerpc-darwin]
Using $a fixes this but I don’t want to do this or I could join the
two files at run time and eval them.
I didn’t expect the scope of a to be private to a.rb and can find no
mention in pickaxe about this.