SICP OpenCourse 10 : L7B-Metacir

2020-08-13  本文已影响0人  牛头酋长

SICP OpenCourse (Structure and Interpretation of Computer Programs)

PART 1

1.POINT: ADD FEATURE BY CHANGE EVAL&APPLY

    - We can focus on the modification of the meta-interpreter to test the new feature in lisp.

    - Root of the tree. 

2.WAHT IS THE VALUE OF METACIRCULAR EVALUATOR?

    - In fact, these metacircular interpreters are an excellent medium for people exchanging ideas about language design.

3.ADD FEATURE IN LIST:

    -Old version:

(LAMBDA (X Y Z)
        ...)

    - New feature version:

(LAMBDA (X . Y)     //Y LIKE THE LIST OF MANY ARGS
    (MAP (LAMBDA (U)(* X U))
                Y))

    - We have the syntax then ,How to get the semantics ? Modify the metacircular interpreter to do it .

PART 2

4.A FAMOUS "BUG"

    - Dynamic binding -- a free variable in a procedure has its value defined in the chain of callers, rather than where the procedure is defined

    - Easy to implement -- but ...

    - Problem, Modularity crisis that involved Dynamic binding.  If two people are working together on some big system, then an important thing to one is that the names used by each one don't interfere with the names of the other.

    - FIX THE BUG

(DEFINE PGEN
    (LAMBDA (N)
        (LAMBDA (X)(EXPT X N))))

    - USE IT

(DEFINE SUM-POWERS
    (LAMBDA (A B N)
        (SUM (PGEN N) A 1+ B)))

PART 3

5.ADD NEW FEATURE: BY NAME PARAMETERS OR DELAYED PARAMETERS

    - WHY? Why we need the new feature?

    - Because, in fact, the default in our Lisp System is by the value of a pointer, a pointer is copied but the data structure it points at is not.

    - Old version

(DEFINE (UNLESS P C A)
    (COND ((NOT P) C)
                  (ELSE A)))

(UNLESS (= 1 0) 2 (/ 1 0)
=> (COND ((NOT (= 1 0)) 2)
                    (ELSE (/ 1 0)))

    - New version : want C and A to be delayed automatically:

(DEFINE (UNLESS P (NAME C)(NAME A)))
    (COND ((NOT P) C)
                    (ELSE A)))

    - Need to change Eval & Apply.

上一篇下一篇

猜你喜欢

热点阅读