09-20-2013

posted Sep 20, 2013, 5:34 AM by Samuel Konstantinovich   [ updated Oct 3, 2013, 12:47 PM ]
Do Now:

1. Take out printed assignment

2. (define 
    (fugu whodoo voodoo)
    (+ whodoo (* 2 voodoo)))
Trace through the expression: (fugu 3 7)

3. Write a function that calculates the average of three values. 
   Write a function that calculates the discriminant. Ask around if you are
       not sure what that is.

Deadlines are not suggestions, askin you to print is not a suggestion. 
Regarding which language to use beginner/R5RS.
http://repl.it/ in case anything is broken you still have a way to test code.

Goal: Booleans and comparisons.

Data Types:  Integers, Floats, Booleans, Strings
- Functions can return any type
- Boolean functions are very useful: even? or isEven?
- Booleans return: #t #f
- Comparative operators: =, <, >, <=, and >=     
     *edit* removed !=, because it is not valid in scheme, see 'not' below
- Connectives: and or 
     (and (< x 1) (> x -1) )   is true when x is between 1 and -1 exclusive.
- Negation: not 
     (not (= a b)) is how you can check if something is not the same.
     (not (and a b) ) is how you negate an and statement.

Examples of using comparative operators to generate a boolean as the result of a functioin:
(define (isEven x)  ( = (remainder x 2) 0 )  )
(define (isGreaterOrEqual a b) (or (= a b) (> a b)) )


HOMEWORK: Make a function that checks if 3 values are a valid 
pythagorean triple, it should return true when it is or false when it isnt:
A)isPythtriple A B C you can assume C is the largest term
B)Challenge: isPythTriple2 A B C where the order does not matter
Comments