On Wed, 23 Feb 2005 03:54:16 +0900, Michael Neumann <mneumann / ntecs.de> wrote:
> Brian Mitchell wrote:
> > On Wed, 23 Feb 2005 03:00:03 +0900, Michael Neumann <mneumann / ntecs.de> wrote:
> >
> >>Caio Tiago Oliveira wrote:
> >>
> >>>Michael Neumann, 22/2/2005 11:25:
> >>>
> >>>>100% agree. I especially cannot understand (at least mathematically)
> >>>>why 0 would be empty and 1 not.
> >>>>(...)
> >>>
> >>>
> >>>Binary logic, 0 is false, 1 is true.
> >>
> >>In fact, those are actual symbols and not numbers!
> >
> >
> > exactly! This issue seems to come up on the ML from time to time. I
> > voiced my opinion that Smalltalk conditionals (depending on behavior)
> > are much better than depending on value (check for nil or false). It
> > can be tailored to fit any object easily... but I think the idea lost
> > out to people who would rather keep ruby more of that same and
> > probably a little faster (though there are some things ruby can't do
> > because of this). My vote is still up for .true?  {} and .false? {}
> >
> > ;-)
> >
> > I really don't care if you guys agree or not but it sure is elegant.
> > Ruby is already a very good language so I am happy anyhow.
> 
> At least for .nil? I agree. I am not sure whether I'd like to write
> "if a.true?" all the time. Nevertheless I believe that

Not quite what I meant... I left my post short as I have posted this a
few times before...

if a
  puts "true"
end

would be what you write but it would be the equivalent of

a.true? {
  puts "true"
}

but not actually written that way (syntax sugar).

This seems messy and confusing but is really nice when meta
programming. One area that could easily benefit from this is DSLs in
Ruby. Another would be creation of higher order logic like fuzzy logic
or lazy evaluation logic and so on. You could even write some bad code
with this but Ruby has never been a watch over your sholder language
as plenty of things like this already exists. It is up to the
porgrammer to use it right. Now to confuse some people:

class Both
  def true?
    yield
  end
  def false?
    yield
  end
end

a = Both.new

a? 1 : 2 # What does this return? probably 2 but it is one grey area
to be aware of.
# or what if a was changed to yield on false? while executing part "1"
but it was not that way before the test.

This is extremely dynamic so it would probably slow ruby down rather
than speed ruby up.

> 
>    if a.false?
> 
> is clearer to read and understand than:
> 
>    if not a
> 
> Just because human mind if very bad at negating conditions (proven by
> studies of some psychologists).
> 
> Regards,
> 
>    Michael
> 
> 

Brian.