Whats the point of bool?

P

Phil Carmody

BartC said:
So? In C you can write:

int a=36, b=49;

if ( (a==36) == (b==49)) puts("A=36 and B=49 are both true");

It doesn't mean that a=36 and b=49 are equivalent.

Why have you dropped an '=' from the predicates under discussion?

Phil
 
P

Phil Carmody

Chris Dollin said:
The context is Scheme ("sceme" is a typo, the name appeared untypoed
earlier in the post). Scheme follows the Lisp pattern where `(or A B ...)`
returns the value of the first non-false A B ...; whether or not you
think this overloading of the meaning of `or` is wise, it's certainly
a convenient operation to have. Scheme differs from traditional and Common
Lisp in that 'nil and the empty list are not false.

That's weird. I'm sure I got top marks in my B9 course at uni.
with the presumption that the empty list was indeed false in
scheme. Who cares, I got top marks and presumably the markers
were idiots. That's good enough for me, they can't recall my
degree.

Phil
 
C

chad

     It doesn't, so your vision is fine.  ;-)

     Suggestion: Fill in a little truth table for `x = (!a == !b)'.
I've added a helpful extra row and column, and filled in a few
of the question marks to get you started:

                        |  b = 0 |  b = 1 | b = -3 |
                        | !b = 1 | !b = 0 | !b = ? |
                        |        |        |        |
        a = 0  | !a = 1 |  x = 1 |  x = 0 |  x = ? |
               |        |        |        |        |
        a = 1  | !a = 0 |  x = ? |  x = ? |  x = ? |
               |        |        |        |        |
        a = 42 | !a = ? |  x = ? |  x = ? |  x = ? |
               |        |        |        |        |

Academics was never one my strong points. Anyhow, here is what I came
up with

| b = 0 | b = 1 | b = -3 |
| !b = 1 | !b = 0 | !b = 0 |
| | | |
a = 0 | !a = 1 | x = 1 | x = 0 | x = 0 |
| | | | |
a = 1 | !a = 0 | x = 0 | x = 1 | x = 1 |
| | | | |
a = 42 | !a = 0 | x = 0 | x = 1 | x = 1 |
| | | | |
 
E

Eric Sosman

chad said:
Academics was never one my strong points. Anyhow, here is what I came
up with

| b = 0 | b = 1 | b = -3 |
| !b = 1 | !b = 0 | !b = 0 |
| | | |
a = 0 | !a = 1 | x = 1 | x = 0 | x = 0 |
| | | | |
a = 1 | !a = 0 | x = 0 | x = 1 | x = 1 |
| | | | |
a = 42 | !a = 0 | x = 0 | x = 1 | x = 1 |
| | | | |

Excellent! A gold star for Chad, and he gets to clean
the erasers!

Now: Can you describe your results in a few simple words,
as a rule that might extend to other possible values of `a'
and `b'?
 
C

chad

     Excellent!  A gold star for Chad, and he gets to clean
the erasers!

     Now: Can you describe your results in a few simple words,
as a rule that might extend to other possible values of `a'
and `b'?

--

I would venture to say that !a == !b for any non-zero values of a and
b.
 
G

Guest

a truth table seems like the height of pracicality to me...

I would venture to say that !a == !b for any non-zero values of a and
b.

and if both "a" and "b" are zero?
 
G

Guest

That's weird. I'm sure I got top marks in my B9 course at uni.
with the presumption that the empty list was indeed false in
scheme. Who cares, I got top marks and presumably the markers
were idiots. That's good enough for me, they can't recall my
degree.

It may depend when you got your degree. From
"Revised5 Report on the Algorithmic Language Scheme" 1988

"Language changes
[...]
o The empty list is now required to count as true."

though apparently the IEEE standard first introduced this (and I can't
be
arsed to hunt down when *that* was published!
 
R

Richard Bos

BartC said:
Get a better dictionary. In my Chambers it explains it under 'equal(s)
sign'.

You didn't write "a equal sign 36" or even "b equals 49", though.

You are a programmer. Would a little precision hurt you?

Richard
 
J

James Kuyper

chad said:
The result would still be the same?

I get the impression that you don't understand the point of these
questions. (!a == !b) doesn't test whether a and b are both true, and no
one suggested that it does. What it does test is whether a and b both
have the same truth value, keeping in mind that in C, any non-zero value
counts as true. Is that clear to you now?

Bringing this back to the original topic, one of the key advantages of
_Bool as compared to an ordinary integer type is that you could replace
(!a == !b) with the simpler and more obvious (a == b), since the only
non-zero value allowed for a _Bool variable is 1.
 
P

Phil Carmody

That's weird. I'm sure I got top marks in my B9 course at uni.
with the presumption that the empty list was indeed false in
scheme. Who cares, I got top marks and presumably the markers
were idiots. That's good enough for me, they can't recall my
degree.

It may depend when you got your degree. From
"Revised5 Report on the Algorithmic Language Scheme" 1988

"Language changes
[...]
o The empty list is now required to count as true."

though apparently the IEEE standard first introduced this (and I can't
be arsed to hunt down when *that* was published!

That's more modern than the text book we were using back in the late
80s. Then again, we were using 't' rather than 'scheme' itself.
I think they broke things in 1988, IMHO.

Phil
 
C

chad

I get the impression that you don't understand the point of these
questions. (!a == !b) doesn't test whether a and b are both true, and no
one suggested that it does. What it does test is whether a and b both
have the same truth value, keeping in mind that in C, any non-zero value
counts as true. Is that clear to you now?

Bringing this back to the original topic, one of the key advantages of
_Bool as compared to an ordinary integer type is that you could replace
(!a == !b) with the simpler and more obvious (a == b), since the only
non-zero value allowed for a _Bool variable is 1.

Okay, I'll admit that I wasn't seeing it right away. I actually had to
sit down and think about it after I read your post.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top