The Scheme interpreter evaluates each of these expressions. Write down the value that Scheme returns.
(+ 1 3)
(* 3 (+ 1 3))
For all parts in this questions, assume the following definitions have been executed:
(define s '(a b c d))
(define t '((a b) c d))
The Scheme interpreter evaluates each of these expressions. Write down the value that Scheme returns.
s
(car s)
(cdr s)
(cons 'a '(b c d))
(cons (car s) (cdr s))
(car (cdr s))
t
(car t)
(cdr t)
(cons '(a b) '(c d))
(list '(a b) '(c d))
(append '(a b) '(c d))
For all parts in this question, assume that a procedure named
add-1
has been defined. It takes a number as an
argument, and returns the number that is one greater than the
argument. For example (add-1 3)
evaluates to
4
.
The Scheme interpreter evaluates each of these expressions. Write down the value that Scheme returns.
(map add-1 '(1 2 3))
(map (lambda (x) (* 2 x)) '(1 2 3))
Define a Scheme variable named x
that has the value 3.
This table shows the number of electoral votes allocated to several states:
Washington | 11 |
Oregon | 7 |
Iowa | 7 |
California | 54 |
Florida | 25 |
Define a Scheme variable named electoral-votes
to encode
this table. Represent the table by an association list: a list of
sublists, one for each state, where each sublist has two elements.
The first element of each sublist is the name of the state and the
second element is the number of electoral votes for that state.
Define a Scheme procedure named add-1
that takes a number as an argument,
and returns the number that is one greater than the argument.
Define a Scheme procedure named phase
that takes a number
as an argument. If the number is less than zero, it returns the
symbol ice
. If the number is greater than one hundred,
it returns the symbol steam
. Otherwise it returns the
symbol water
.
This definition is executed:
;; Like Scheme length (define (len lst) (if (null? lst) 0 (+ 1 (len (cdr lst)))))
Then this expression is typed into the Scheme interpreter and evaluated. It returns the result shown:
> (len '(x y z)) 3
The following questions all concern what happens when the
expression (len '(x y z))
is evaluated.
len
return when the base case is reached?
len
called?
lst
bound to when len
is called the first time?
(cdr lst)
when len
is called the
first time?
(len (cdr lst))
when len
is called the
first time?
(+ 1 (len (cdr lst)))
when len
is called the first time?