For each of the following lists, give an expression (using
only the symbols a, b, c),
and d; the procedure cons); and the empty list
()) that evaluates to it.
For example, (a b c)) can be constructed as:
(cons 'a (cons 'b (cons 'c ())))
(Note: For the purpose of this question, the answer (cons 'a
'(b c))) would be considered incorrect, because it fails
the above criteria.)
(a (b) c d)
((a b) c d)
(a (b (c)) d)
(a (b (c (d))))
(((a) b) (c (d)))
a from each of the following lists,
using only car, cdr, and
their hybrid forms (e.g., caddr).
For example, a can be exracted from (b (a
c)) using
(car (car (cdr '(b (a c))))) or
the abbreviated (caadr '(b (a c))).
(b c d a)
((b c) (a d))
(c ((a)) b)
(b (d (a c)))
(d (c (b) a))
(define thing-one '(1 (a . 2) (((z)))) ) (define thing-two '(((b 3) #t) w (x y (z)) (4 . 6)) )Draw pictures (as in lecture and Dybvig Exercise 2.2.5) of the internal list structures for both
thing-one and thing-two.
(7 points) Write a Scheme
procedure allPositive? that takes three integers
and returns #t if all three are poitive; it
should return #f otherwise.
(17 points) Write a Scheme
procdure pythTriple? that takes three integers
(x, y, and z and
determines whether or not x, y,
and z form a Pythagorean triple.
Your procedure should work correctly regardless of the order of the arguments or their sign. For example,
(pythTriple 3 5 4) (pythTriple 4 5 3)should both return
#t, whereas (pythTrple 3 -4 5)should return
#f.
cond to write a Scheme procedure identify that takes a
single argument and determines whether it is:
> (identify 6/7) "number" > (identify car) "procedure" > (identify 'car) "symbol" > (identify '(3 . 5)) "dotted pair" > (identify #\a) ;; #\a is a char "unknown"