;;; ;;; This file contains the data access functions for the ;;; s-lisp representation of Small Lisp programs as data objects ;;; as described in chapter 4 of the text. ;;; ;;; ------------------------------------- ;;; The recognizers for Small Lisp expressions. ;;; identifier-p[expr] = symbolp[expr] numeric-atom-expr-p[expr] = numberp[expr] symbolic-atom-expr-p[expr] = [listp[expr] --> [eq[first[expr]; "quote"] --> symbolp[second[expr]]; otherwise --> F]; otherwise --> F] list-expr-p[expr] = [listp[expr] --> [eq[first[expr]; "quote"] --> listp[second[expr]]; otherwise --> F]; otherwise --> F] fn-call-p[expr] = [listp[expr] --> [eq[first[expr]; "quote"] --> F; eq[first[expr]; "cond"] --> F; eq[first[expr]; "let"] --> F; otherwise --> T]; otherwise --> F] cond-expr-p[expr] = [listp[expr] --> eq[first[expr]; "cond"]; otherwise --> F] let-expr-p[expr] = [listp[expr] --> eq[first[expr]; "let"]; otherwise --> F] ;;; ;;; The converter functions for identifiers and numeric-atom-exprs. ;;; id-name[ident] = ident make-identifier[id-name] = id-name numeric-val[num-atom] = num-atom make-numeric-atom-expr[val] = val ;;; ;;; The access and constructor functions for symbolic-atom-exprs and ;;; list-exprs. ;;; symbolic-val[sym-atom-expr] = second[sym-atom-expr] make-symbolic-atom-expr[sym] = list2["quote"; sym] list-val[list-expr] = second[list-expr] make-list-expr[list] = list2["quote"; list] ;;; ;;; The access and constructor functions for function calls. ;;; make-fn-call[func; args] = cons[func; args] callee[fn-call] = first[fn-call] arguments[fn-call] = rest[fn-call] ;;; ;;; The functions for conditional expressions and their clauses. ;;; make-cond-expr[clauses] = cons["cond"; clauses] clauses[cond-expr] = rest[cond-expr] make-clause[pred; result] = list2[pred; result] predicate[clause] = first[clause] result[clause] = second[clause] ;;; ;;; The functions for let-expressions and their local definitions. ;;; local-defs[let-expr] = second[let-expr] final-expr[let-expr] = third[let-expr] make-let-expr[defs; expr] = list3["let"; defs; expr] local-var[local-def] = first[local-def] local-val[local-def] = second[local-def] make-local-def[var; val] = list2[var; val] ;;; ;;; The recognizers for Small Lisp definitions (i.e., function ;;; and constant definitions). ;;; fn-def-p[def] = eq[first[def]; "defun"] const-def-p[def] = eq[first[def]; "setc"] ;;; ;;; The access functions for function definitions. ;;; fn-name[fndef] = second[fndef] parameters[fndef] = third[fndef] body[fndef] = fourth[fndef] make-fn-def[name; parms; body] = list4["defun"; name; parms; body] ;;; ;;; The access functions for constant definitions. ;;; const-name[constdef] = second[constdef] const-val[constdef] = third[constdef] make-const-def[name; value] = list3["setc"; name; value]