Lisp Interpreter Details Main loop S input if

  • Slides: 3
Download presentation
Lisp Interpreter Details Main loop: S = input(); … if defun, add it to

Lisp Interpreter Details Main loop: S = input(); … if defun, add it to d. List, print msg. , cont. with next iteration… R = eval[S, NIL]; output(R); evlis[list, a. List] = [ null[list] NIL; | T cons[ eval[car[list], a. List], evlis[cdr[list], a. List] ] ] evcon[be, a. List] = // be is of form ((b 1 e 1). . . (bn en)) [ null[be] ***exception!*** | eval[caar[be], a. List] eval[cadar[be], a. List]; | T evcon[cdr[be], a. List] ]

Lisp Interpreter Details eval[ exp, a. List] = [ atom[exp] -->[ int[exp] -->exp; |

Lisp Interpreter Details eval[ exp, a. List] = [ atom[exp] -->[ int[exp] -->exp; | eq[exp, T] -->T ; | eq[exp, NIL] -->NIL; | in[exp, a. List] -->get. Val[exp, a. List]; |T --> ***unbound!***] | atom[car[exp]] --> [ eq[car[exp], QUOTE] --> cadr[exp]; | eq[car[exp], COND] --> evcon[cdr[exp], a. List]; | T --> apply[car[exp], evlis[cdr[exp], a. List] ] | T --> ***not a Lisp expression!*** ]

Lisp Interpreter Details (in Lisp) apply[ f, x, a. List] = [ atom[f] -->[

Lisp Interpreter Details (in Lisp) apply[ f, x, a. List] = [ atom[f] -->[ eq[f, CAR] -->caar[x]; // why? | eq[f, CDR] -->cdar[x]; | eq[f, CONS] -->cons[car[x], cdr[x]]; //? ? | eq[f, ATOM] -->atom[car[x]]; | eq[f, NULL]-->null[car[x]]; | eq[f, EQ] -->eq[car[x], cadr[x]]; … … | T -->eval[ cdr[getval[f , d. List]], addpairs[car[getval[f, d. List]], x, a. List] ]; ]; |T -->***Not a Lisp expression!***; ] Elements on d. List of form: (f. (p. List. body) ) addpairs[p. List, x, a. List]: returns new a-list