Simplifying the defined api

Question: A recent suggestion to ruby was to have all
defined?
method's return true or nil.
So my question is...does anybody ever use "defined?" for anything
besides true/nil?

I also wonder if the complex defined? api explains why this code:
assert(defined?(a) and defined?(b))
throws a syntax error for some reason.
Any thoughts welcome.
Take care.
-Roger

···

--
Posted via http://www.ruby-forum.com/.

I also wonder if the complex defined? api explains why this code:
assert(defined?(a) and defined?(b))

I use defined? but I never had the need to use assert.

···

--
Posted via http://www.ruby-forum.com/\.

I also wonder if the complex defined? api explains why this code:
assert(defined?(a) and defined?(b))
throws a syntax error for some reason.

No. That's an unfortunate situation with the "and" and "or" in Ruby:

def foo?(ob)
  ob.to_s == "foo"
end

=> nil

foo?("foo") and foo?("bar")

=> false

def baz(truth)
  puts "You can't handle the truth."
end

=> nil

baz(foo?("foo") and foo?("bar"))

SyntaxError: compile error
(irb):8: syntax error, unexpected kAND, expecting ')'
baz(foo?("foo") and foo?("bar"))
                   ^
(irb):8: syntax error, unexpected ')', expecting $end
        from (irb):8

baz(foo?("foo") && foo?("bar"))

You can't handle the truth.

-austin

···

On 10/13/07, Roger Pack <rogerpack2005@gmail.com> wrote:
--
Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/
               * austin@halostatue.ca * You are in a maze of twisty little passages, all alike. // halo • statue
               * austin@zieglers.ca

Roger Pack wrote:

Question: A recent suggestion to ruby was to have all
defined?
method's return true or nil.
So my question is...does anybody ever use "defined?" for anything
besides true/nil?

It looks like I'm missing something... What's the "defined? api"?

mortee

Question: A recent suggestion to ruby was to have all
defined?
method's return true or nil.

Let me turn this around.

Why care that it returns truth values other than literal true?

The interpretation of objects as truth values is consistent within
ruby, defined? is one of cases in which that is used to advantage to
convey additional information.

So my question is...does anybody ever use "defined?" for anything
besides true/nil?

Sure, it's useful to know that the syntactic properties of an
expression are dynamically.

···

On 10/13/07, Roger Pack <rogerpack2005@gmail.com> wrote:

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

I use defined? but I never had the need to use assert.

Did anyone ever use defined? for anything other than 'true/nil'
(true/false)?
That's what I wonder...:slight_smile:
-Roger

···

--
Posted via http://www.ruby-forum.com/\.

in ruby you can do
defined? local_variable_name
or defined? ClassName
or what not and it tells you if those things exist.

mortee wrote:

···

Roger Pack wrote:

Question: A recent suggestion to ruby was to have all
defined?
method's return true or nil.
So my question is...does anybody ever use "defined?" for anything
besides true/nil?

It looks like I'm missing something... What's the "defined? api"?

mortee

--
Posted via http://www.ruby-forum.com/\.

Let me turn this around.

Why care that it returns truth values other than literal true?

I think the rationale was it would make Ruby simpler and therefore one
less thorn in the side for interpreters to implement. Good point,
though.

Sure, it's useful to know that the syntactic properties of an
expression are dynamically.

question: allocated dynamically?

···

--
Posted via http://www.ruby-forum.com/\.

So is this a parser bug or a feature?

···

baz(foo?("foo") and foo?("bar"))
                   ^
(irb):8: syntax error, unexpected ')', expecting $end
        from (irb):8

baz(foo?("foo") && foo?("bar"))

You can't handle the truth.

-austin

--
Posted via http://www.ruby-forum.com/\.