CSC 324: Assignment 1 clarifications
These clarafications and announcements were originally posted on the
assignments page.
- Question 1 mentions a different form of lambda which permits
a variable number of arguments to be passed to a Scheme procedure.
Here's an example:
(define f (lambda args (for-each display args)))
or, if you want to prettify it,
(define f (lambda args (for-each (lambda (x) (display x) (newline)) args)))
Try it with (f 1 2 3), and you'll get the arguments printed.
The formal parameter args is the list of arguments,
which in this example is (1 2 3).
- What exactly are 'x and 'add in question 4?
Or passed, failed, expected and got
in question 3?
They are symbols in Scheme. Just as ' (quote)
quotes a list to prevent its evaluation, 'a quotes an identifier
to prevent it from being evaluated. You can think of symbols as
like strings (only more efficient) that behave like enumerations from
other languages (like C). You can check if two expressions evaluate
to the same symbol using the eq? predicate. Symbols are ideally
suited for use as identifiers in the representation of programs, messages
passed between procedures, or labels for records.
Here are some examples:
(car '(a b c))
(list 'u 'v)
(define g (lambda (x) (if (eq? x 'go) (display "Blast off!"))))
More clarifications (1 February 2006)
- If DrScheme complains that your lambda form for variable arguments
is wrong, or you get other errors for constructions that should work,
you need to change to a more complete dialect. There are a number of
restricted teaching languages in DrScheme that prevent you from using the
full power of Scheme. Simply use the Language menu to choose a language
such as "Standard (R5RS)".
- For Question 2, square should behave as
(lambda (x) (* x x)).
- For Question 3, tester should return the test results as a list.
If we wanted to, we could use car to examine the results of the first test.
- For Question 3c, include your code testing sqrt-tester in the
file. Your .scm file can include statements other than define
statements.
- For Question 4, the 'display method should print the vector
in the form "(x,y)" and have no (return) value. None of the methods change
an existing vector, but some create new vectors.
- For Question 4, you only need one 'add method. Your 'add
method from part (b) satisfies the part (a) requirement.
- There are vector and pair types built-into Scheme. These mean very
different things than the pairs and 2d-vectors used in this assignment,
so avoid trying to use them (and avoid confusing yourself). You have seen
in class everything you need to complete this assignment.
|
|