The expression (read)
reads one Scheme expression from
the terminal and returns that expression (it does not evaluate the
expression). What does (read)
return when you type
each of the following inputs?
x
x
(x)
(x)
x y z
x
x
is a single expression."x y z"
"x y z"
(x y z)
(x y z)
(x) (y) (z)
(x)
(x)
is a single expression.(x y
z)
(x y z)
"x y
z"
"x y
z"
(x (y (z)))
(x (y (z)))
(x (y (z))))
(x (y (z)))
Given these definitions:
(define (read-three) (read) (read) (read)) (define (read-xyz) (let ((x (read))) (let ((y (read))) (let ((z (read))) (list x y z))))) (define (read-list) (list (read) (read) (read)))
What does (read-three)
return when you type this input?
x y z
z
Scheme only returns the value of the last expression in the body
of the procedure. See page 347 in Simply Scheme.
What does (read-xyz)
return when you type this input?
x y z
(x y z)
The nested let
s force Scheme to evaluate
the three read
s in order. See page 361 in Simply Scheme.
What might (read-list)
return when you type this input?
Give two different correct answers.
x y z
(x y z)
If the Scheme implementation evaluates expressions
left-to-right.
(z y x)
If the Scheme implementation evaluates expressions
right-to-left. See page 362 in Simply Scheme.