# Unless statement... why oh why?

"HERE" if not thr or not thr.alive? # this works!!
"HERE" unless thr or thr.alive? # doesn't work!! WHY?
"HERE" unless thr and thr.alive? # works, but why?

I dont see why the unless/and works when the unless/or should be the one short-circuting no?

Thanks,

Zach

Zach Dennis wrote:

"HERE" if not thr or not thr.alive? # this works!!
"HERE" unless thr or thr.alive? # doesn't work!! WHY?
"HERE" unless thr and thr.alive? # works, but why?

I dont see why the unless/and works when the unless/or should be the one short-circuting no?

ignore the "short-circuting" comment in reference to the or statement.

Zach

DeMorgan's theorem and operator precedence in ruby.

DeMorgan's theorem in a nutshell:

(Not A) and (Not B) == Not (A or B)

(Not A) and (Not B) == (Not A) or (B)

See the difference?

···

On 8/18/05, Zach Dennis <zdennis@mktec.com> wrote:

"HERE" if not thr or not thr.alive? # this works!!
"HERE" unless thr or thr.alive? # doesn't work!! WHY?
"HERE" unless thr and thr.alive? # works, but why?

I dont see why the unless/and works when the unless/or should be the one
short-circuting no?

Thanks,

Zach

--
Brock Weaver
[OBC]Technique

"HERE" if not thr or not thr.alive? # this works!!

(not a) or (not b) <=> not (a and b)
<=/=>
not (a or b) <=> (not a) and (not b)

"HERE" unless thr or thr.alive? # doesn't work!! WHY?
"HERE" unless thr and thr.alive? # works, but why?

I dont see why the unless/and works when the unless/or should be the one
short-circuting no?

Thanks,

Zach

brian

···

On 18/08/05, Zach Dennis <zdennis@mktec.com> wrote:

Stringed instrument chords: http://chordlist.brian-schroeder.de/

Zach Dennis wrote:

"HERE" if not thr or not thr.alive? # this works!!
"HERE" unless thr or thr.alive? # doesn't work!! WHY?
"HERE" unless thr and thr.alive? # works, but why?

I dont see why the unless/and works when the unless/or should be the one short-circuting no?

I don't think it's a matter of short-circuiting, but
a matter of DeMorgan's Theorem...

Hal

Brock Weaver wrote:

DeMorgan's theorem and operator precedence in ruby.

DeMorgan's theorem in a nutshell:

(Not A) and (Not B) == Not (A or B)

(Not A) and (Not B) == (Not A) or (B)

See the difference?

Yep, thank you for the quick response!

Zach

Or, put another way:
When you are performing boolean negation on an expression:
* Change all ANDs to ORs, and vice-versa
* Throw a NOT in front of every value
* (And then, to be clean, change "NOT NOT a" to just "a")

Your original was "(NOT a) OR (NOT b)"
Negating, you get "NOT( (NOT a) OR (NOT b) ) => NOT(NOT a) AND NOT(NOT
b) => a AND b"

If you're still not convinced, sound it out logically:

"DON'T play NFL football IF you're NOT alive OR NOT male"

Is this the opposite?
"DO play NFL football IF you're alive OR male"
No, because that means that alive women may play.