Simply Scheme Exercises. Chapter 06 True and False.
Posted: Sun Apr 21, 2013 9:09 pm
Hey Schemers, new Scheme user here. Looking for enlightenment on an exercise I'm doing at the end of Simply Scheme chapter 06 True and False.
Boring exercise 6.1 has the following cond expression:
(cond (empty? 3)
(square 7)
(else 9))
In my head, this should return the value of (square 7). But in the interpreter, it returns the value of (empty? 3).
(Tested the return of (empty?) by changing the '3' to other atoms and lists).
Why is this?
What I understand:
1. Any non false value is true in Scheme.
2. The first statement is evaluated and if true the interpreter returns #t, what is specified or #unspecified dependent on context then exits the cond.
What I don't understand:
1. If the result of (empty? 3) is #f, wouldn't it evaluate the next cond argument?
2. If the interpreter evaluates (empty? 3), why doesn't it return #t in this case? (as when the expression is evaluated on its own?)
Using SCM with Slib and the libraries that come with the book (simply.scm functions.scm ttt.scm match.scm database.scm) loaded.
Boring exercise 6.1 has the following cond expression:
(cond (empty? 3)
(square 7)
(else 9))
In my head, this should return the value of (square 7). But in the interpreter, it returns the value of (empty? 3).
(Tested the return of (empty?) by changing the '3' to other atoms and lists).
Why is this?
What I understand:
1. Any non false value is true in Scheme.
2. The first statement is evaluated and if true the interpreter returns #t, what is specified or #unspecified dependent on context then exits the cond.
What I don't understand:
1. If the result of (empty? 3) is #f, wouldn't it evaluate the next cond argument?
2. If the interpreter evaluates (empty? 3), why doesn't it return #t in this case? (as when the expression is evaluated on its own?)
Using SCM with Slib and the libraries that come with the book (simply.scm functions.scm ttt.scm match.scm database.scm) loaded.