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:

(load "\~cs61a/lib/meta.scm")

(load "\~cs61a/lib/traced-eval.scm")

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:

 (car pair)

 (car1 pair)

 (car2 pair)

 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

for help.

print 2 + 3

print 2+3

print sum 2 3

print (sum 2 3 4 5)

print sum 2 3 4 5

2+3

print "yesterday

print "julia"

print revolution

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

end

second "something

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

end

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]]

          [first "help]

print ifelse 3=1+2

          [strawberry fields forever]

          [penny lane]

print ifelse 4=1+2

          ["flying]

          [[all you need is love]]

}

to greet :person

say [how are you,]

end

to say :saying

print sentence :saying :person

end

greet "ringo

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

end

to describe :person

print se :person :sent

end

who [sells out]

print :bass

make "bass "paul

print :bass

print bass

to bass

output [johnny cymbal]

end

print bass

print :bass

print "bass

to countdown :num

if :num=0 [print "blastoff stop]

print :num

countdown :num-1

end

countdown 5

to downup :word

print :word

if emptyp bl :word [stop]

downup bl :word

print :word

end

downup "rain

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).