CS61A Summer 2011 Lab 12
1. List all the procedures in the metacircular evaluator
that call eval
2. List all the procedures in the metacircular evaluator
that call apply..
3. Explain why make-procedure does not call eval.
4. Abelson and Sussman, exercises 4.1, 4.2, 4.4, 4.5
We have added a tracing feature to the metacircular evaluator. To use it,
you'll need two files:
To activate tracing, evaluate the expression (mini-trace #t). To
turn off the trace, evaluate (mini-trace #f). To include default bindings
in the environments produced by the trace, evaluate (mini-trace 'all).
The following lab exercises will involve the use of this feature.
5. Load the metacircular evaluator, enable tracing,
then call initialize-lisp
and evaluate the following expressions:
(define car1 car)
(define (car2 x) (car x))
(define pair (cons 1 2))
Then evaluate the following expressions:
Interpret the trace results by describing what the evaluator
does when evaluating each of the expressions.
Which of the three expressions requires the most work?
Which expression requires the least work?
5. In this lab exercise you will become familiar with the Logo programming
language, for which you'll be writing an interpreter in project 4.
To begin, type logo at the Unix shell prompt --- NOT from
Scheme! You should see something like this:
Welcome to Berkeley Logo version 5.5
? [THIS is where you’ll enter stuff]
The question mark is the Logo prompt, like the > in Scheme. (Later, in
some of the examples below, you'll see a > prompt from Logo, while in
the middle of defining a procedure.)
5a. Type each of the following instruction lines and note the results. (A few
of them will give error messages.) If you can't make sense of a result, ask
print 2 + 3
print sum 2 3
print (sum 2 3 4 5)
print sum 2 3 4 5
print [blue jay way]
show [eight days a week]
show first [golden slumbers]
print first bf [she loves you]
pr first first bf [yellow submarine]
to second :stuff
output first bf :stuff
print second "piggies
pr second [another girl]
pr first second [carry that weight]
pr second second [i dig a pony]
to pr2nd :thing
print first bf :thing
pr2nd [the 1 after 909]
print first pr2nd [hey jude]
repeat 5 [print [this boy]]
if 3 = 1+1 [print [the fool on the hill]]
print ifelse 2=1+1
[second [your mother should know]]
print ifelse 3=1+2
[strawberry fields forever]
print ifelse 4=1+2
[[all you need is love]]
to greet :person
say [how are you,]
to say :saying
print sentence :saying :person
show map "first [paperback writer]
show map [word first ? last ?]
[lucy in the sky with diamonds]
to who :sent
foreach [pete roger john keith] "describe
to describe :person
print se :person :sent
who [sells out]
make "bass "paul
output [johnny cymbal]
to countdown :num
if :num=0 [print "blastoff stop]
to downup :word
if emptyp bl :word [stop]
downup bl :word
5b. Devise an example that demonstrates that Logo uses dynamic scope
rather than lexical scope.
Your example should involve the use of a variable
that would have a different value if Logo used lexical scope.
Test your code with Berkeley Logo.
5c. Explain the differences and similarities among the Logo operators
“ (double-quote), [ ] (square brackets) and : (colon).