CSC151.02 2003F, Class 8: Numeric Values in Scheme
Admin:
* Homework due. Email me your URLs. We may spend some time on Thursday looking at your homework (then again, we may not).
* Read "Defining Your Own Procedures in Scheme"
* EBoards linked
Topics:
* Are there questions from yesterday's lab?
* Data types
* Numbers in Scheme
* Lab
* Reflection
Reflection on Lists and Symbols Labs:
Q: Why join lists?
A: Supppose I had a list of all my students in CSC151 and a list of all my students in CSC297. If I wanted to send mail to "all my students", I'd join the two lists together first.
Q: Can one use append to join more than two lists?
A: I dunno, let's try it.
A: Yes, you can append 0, 1, 2, 3, or more lists
Q: Did anyone try the complex list with only cons
(a (b c) (d (e)))
A: Hmmm ... that sounds like a good exam question.
New topic: Types
* Types are ways of classifying values
* 23 is an integer
* 'a is a symbol
* (1 2 3) is a list
* cons is a function
* Why bother?
* It's easier to catch errors in a program
* It reminds us what we can do with our data
* Scheme has a lot of types
* It even has lots of kinds of numbers
* integers
* rational numbers (expressible as the ratio of two integers)
* real numbers (potentially a fractional component)
* imaginary numbers (potentially include an imaginary component)
* Some languages check "type safeness" as soon as possible (when you write your code)
* Scheme checks "type safeness" when you run the program
* Scheme can represent some numbers in two different ways: exactly or inexactly
* The inexact? and exact? predicates let you determine whether a number is exact or inexact
Try the Lab
Reflection:
* Yes, you may have to review the reading (e.g., for really large numbers, for exact numbers, for inexact numbers) #i1/3
* Also for info on the procedures
* Intended moral: There are a variety of ways you explore the "meaning" of a procedure
* Experimentally
* By reading documentation intended for experts
* By reading documentation intended for novices
* By asking someone else
* By some combination
* So, what do you know about the following procedures?
* floor, ceiling, truncate, round
* Convert numbers with a decimal part to integers (but in different ways)
* floor rounds down
* ceiling rounds up
* truncate chops of the decimal part and is therefore just like floor for positive numbers and ceiling for negative numbers
* round is like what we learned in grade school
* if the decimal part is above 0.5, rounds up
* if the decimal part is below 0.5, rounds down
* if the decimal part is 0.5, rounds toward even
* quotient, remainder, modulo
* max, min
* numerator, denominator
* gcd, lcm