CSC 207: Extra Session 3 (Thursday, 18 Sept. 2014)
check-equal? work in Scheme?
- Step one: Check that types match. No? Then the values aren't equal.
- Step two: Compare using a type-specific approach
- Booleans: Easy
- Symbols: Easy
- Strings: Compare character by character.
- Numbers: Easy (?)
- Fixed precision: Bits!
- Arbitrary precision: Length + Digits (or equivalent)
- Vectors or lists:
- Compare lengths
- Compare elements recursively
- But, um, it appears to be a bit more complex than that to deal with
String.equal in Java comparing memory location or character by
- Look at the Javadoc.
- Run experiments!
Can you as programmer find out the location of an object?
- ((Object) obj).toString() may give the "identifier" associated with
an object. That may or may not be the memory location.
- Even if you know the memory location, there is no Java command that takes
a memory location as a parameter. So it's useless.
For the new calculator, what are the registers for?
When you say "rewrite this recursive algorithm iteratively", what do you
- Use the same general idea as that algorithm, but expressed iteratively.
- Your result should still take time proportional to the log_2 of the
Have we done user input yet?
- Um. kinda. But you've read about it. And maybe a few small problems.
How do we make a prompt?
PrintWriter pen = new PrintWriter(System.out, true);
BufferedReader eyes = new BufferedReader(new InputStreamReader(System.in));
result = eyes.readLine(); // I think
What is the relationship between
- One works for multithreaded computation, the other doesn't.
What do you mean by "Make a template class"?
- Include a constructor so that you can have multiple calculators.
- The registers will be fields of the calculator.
Can you explain the difference between functional, imperative/procedural,
and object-oriented programming?
- Note: Almost everything we do mixes paradigms.
- Each has an emphasis/model.
- We can do "pure" functional or oop, but we rarely do.
Functions are first-class values.
- Traditionally: Operations don't have side effects, so order of
evaluation doesn't matter too much.
eval - Code and data are interchangable
> (define exp (list '+ 1 2))
'(+ 1 2)
> (eval exp)
- Programs are collections of interacting objects that send
messages to each other.
- Three characteristics
- Explicit sequencing of operations
- Basic operations are calculation, input, output, and changing memory
Can you give a concrete example that suggests the difference?
- Two points in n-space. Find their distance.
- Imperative programmer
int temp = 0;
for (i = 0; i < n; i++)
temp += square(p1[i] - p2[i]);
"square root of the sum of squares of differences"
(sqrt (reduce + (map square (map - p1 p2))))
Can you tell us about Exceptions?
- no. it's a topic for tomorrow.
When building an array on the fly, should I use a linked list or an
array list or a vector or ...?
- Think about the way in which you are using it.
Can you help me with the homework that I got an extension on and everyone
else is done with?
- if there's time left at the end of class. but there's not. sorry.