Fork me on GitHub
#beginners
<
2019-11-02
>
Stoic004:11:53

Hi all. I am having a tough time understanding "and", "or". For example, why is (and true true) true , (or false false) false, (or false true) false etc

seancorfield04:11:52

@stoic0

user=> (or false true)
true
user=>
^ not false. Can you explain what is confusing you?

Stoic004:11:31

@seancorfield oops sorry, i wrote that from memory

Stoic004:11:43

I am just confused as to why those values evaluate to what they do

seancorfield04:11:01

Why true and true is true?

seancorfield04:11:23

Um, I'm not sure how to answer that... it seems so... obvious to me... so what's your background that such expressions seem weird?

Stoic004:11:43

i have a bit of python but nothing spectacular

kenj04:11:46

The reason they are defined that way comes out of math/logic: https://en.m.wikipedia.org/wiki/Boolean_algebra

Stoic004:11:22

@risinglight ok thanks, i will read up further

seancorfield04:11:56

OK. Python:

>>> True and True
True
>>> True and False
False
>>> False or False
False
>>> False or True
True
>>>

didibus04:11:36

There's no real reason. It's mathematics. You have to learn it the same way you learn how to count and why 1+1 = 2

seancorfield04:11:02

I'm just puzzled because it seems the same in Python as Clojure...

Stoic004:11:17

@seancorfield yeah i guess i never really understood it there either

Stoic004:11:27

and i havent coded in a while so havent had to use it

seancorfield04:11:37

Ah, OK. That gives me good context.

Stoic004:11:40

i was just doing the Brave Clojure book and ran across it

Stoic004:11:46

so thought I would ask

didibus04:11:22

The important part is more that it's all combinations of something that can be one of two things.

didibus04:11:18

So the idea is just to have operators that given two things of two possible values, you combine them in different ways. And you want an operator for each possible combination.

seancorfield04:11:21

Maybe the tables will help:

and | True | False
--------------------
True | True | False
False| False| False

or  | True | False
-------------------
True | True | True
False | True | False
` Does that help at all?

didibus04:11:32

Then people just tried to give them name that somewhat were relatable

didibus04:11:48

So if you have one of two things, we can call those possible values 0 and 1 or false and true. And then, if you create the combination you see

Stoic004:11:02

so (if (and (= :alarm "failure) (= :light red)) (println "problem") "ok"))

Stoic004:11:22

would be (if true "problem" "ok")

didibus04:11:59

1 ? 1 = 1 1 ? 1 = 0 0 ? 0 = 1 0 ? 0 = 0 1 ? 0 = 1 1 ? 0 = 0 Etc. For each of those possible combinations, you want an operator to replace the ?. Or, And, and Not are those operators. And then you have higher level ones that combine those together.

seancorfield04:11:04

I suspect alarm would be a symbol and :failure would be a value, similarly for light and :red

Stoic004:11:45

oh yeah, i just missed the quotes in both "failure" and "red" ...sorry for the confusion

seancorfield04:11:46

But, given that, yes, that condition could print problem if both of those conditions were true.

didibus04:11:41

In your case, (= :alarm "failure") is false

didibus04:11:57

Because :alarm is not equal to "failure"

didibus04:11:30

Same for (= :light "red")

didibus04:11:53

So now you have (and false false)

didibus04:11:15

And the result of that is false

didibus04:11:54

So that expression would actually be (if false "problem" "ok")

Stoic004:11:45

oh ...so the eval would be "ok"

Stoic004:11:47

in that case

Stoic004:11:55

thanks! will do further reading and playing in the repl

Stoic004:11:20

it feels like a huge mountain to climb :S i already got lost in the syntax of multi functions etc

didibus04:11:17

Ya, I'm trying to remember when I first learned mathematical logic

seancorfield04:11:55

I guess I was lucky that I learned it in high school as an elective, back in the 70's...

didibus04:11:10

I think I learned my in university to be honest

didibus04:11:27

I don't think I had any prior math class that covered it

seancorfield04:11:34

My school had a bunch of weird electives... I did Russian and Propositional Calculus and, would you believe, Algol 60 via correspondence...

seancorfield04:11:06

Some of my friends did Chinese (Mandarin) as an elective. I think Greek was offered too. Can't remember what else.

didibus04:11:31

That's cool

kenj04:11:52

In college I took a philosophy elective which taught it along with propositional and predicate logic as applied to English.

8
didibus04:11:14

I think it does help to learn about mathematical logic from a math angle first. Maybe there's some YouTube videos you could watch that are not programming related. Do a few exercise on that first.

kenj04:11:55

A bunch of CS/EE student took it to fulfill an elective requirement, and kind of annoyed the philosophy students by throwing the grading curve off

seancorfield04:11:19

An interesting combination!

kenj04:11:07

Your HS experience sounded kinda awesome @seancorfield

seancorfield04:11:38

In some ways, yeah. In other ways, it was awful. But it definitely had shades of Harry Potter... four houses, 400 year old stone spiral stairs, big dining hall with masters on the stage and boys on the long benches... and we called everyone by their surname...

seancorfield04:11:16

(both of those look like good videos @didibus!)

kenj04:11:03

I went to a tiny religious HS that was saving money to buy a new campus instead of spending it on education. I definitely left with some major knowledge gaps...

seancorfield04:11:47

The original school was built in 1540 🙂

seancorfield04:11:52

The exposure to Algol 60 really did ignite my interest in computing. Algol 68 in university, and Lisp. Then three years researching ML-style FP languages. Nice to get back to it with Clojure in 2010...

Stoic014:11:40

Hi all... what site would you recommend for coding exercises for a beginner? I think there are a bunch like koans, exercism etc....i am a novice with little experience

Stoic014:11:06

more context....working through the Brave/True Clojure book

metehan14:11:01

@stoic0 one of the first tutorial I've followed was this-> https://www.youtube.com/watch?v=pIiOgTwjbes and it was really helpful.

👍 12
Stoic015:11:04

@m373h4n thanks! I will check it out