S-EXPRESSION | Prediction | Scheme Says |
(+ 7 2) | ||
(7 + 2) | ||
(7 2 +) | ||
+ 7 2 | ||
'( + 7 2) | ||
(quote (+ 7 2) ) | ||
(eval '(+ 7 2) ) | ||
(eval (+ 7 2)) | ||
19 | ||
(19) | ||
'(19) | ||
'() | ||
(car '(1 2 3)) | ||
(cdr '(1 2 3)) | ||
(car '((1 2 3)
(4 5 6) (7 8 9) ) |
||
(cdr '((1 2 3)
(4 5 6) (7 8 9) ) |
||
(car (car '((1 2 3)
(4 5 6) (7 8 9) )) |
||
(cdr (cdr '((1 2 3)
(4 5 6) (7 8 9) )) |
||
(car '() ) | ||
(cdr '() ) | ||
(reverse '((1 2 3)
(4 5 6) (7 8 9) )) |
||
(list 1 2 3) | ||
(log 3) | ||
(sqrt 3 2 1) | ||
(remainder 3 1.7) | ||
(map sqrt '(16 4 2)) |
QUESTION 2: Write Scheme espressions that do the following:
EXAMPLE: To extract the middle row of the array
"( (1 2 3) (4 5 6) (7 8 9))", how about: "(car (cdr '(
(1 2 3) (4 5 6) (7 8 9)) ))"
or simple "(cadr '( (1 2 3) (4 5 6) (7 8 9)) )"
(A) Extract the last element ("9") from the array "( (1 2 3) (4
5 6) (7 8 9))"
(B) Remove the last two rows of the matrix "( (1 2 3) (4
5 6) (7 8 9))". In other words, "( (1 2 3)
(4 5 6) (7 8 9))" becomes "( (1 2 3) )".
(C) Define a function square, that squares it's argument. When you're done I should be able to say (square 3) and get 9.