6.001 Metacircular Evaluator Representing Expressions (define (tagged-list? exp tag) (and (pair? exp)(eq? (car exp) tag))) (define (self-evaluating? exp) (or (number? exp)(string? exp)(boolean? exp))) (define (quoted? exp)(tagged-list? exp ' quote)) define (text-of-quotation exp)(cadr exp)) (define (variable? exp)(symbol? exp)) (define (assignment? exp)(tagged-list? exp 'set)) (define (assignment-variable exp)(cadr exp)) define (assignment-value exp)(caddr exp)) (define (definition? exp)(tagged-l xp 'define)) (define(definition-variable exp) (if (symbol?(cadr exp)) (cadr (caad exp))) (define(definition-value exp) (if (symbol?(cadr exp)) (cadd exp) (make-lambda (cdadr exp)(cddr exp)))) formal params, body (define (lambda? exp)(tagged-list? exp 'lambda)) (define (lambda-parameters lambda-exp)(cadr lambda-exp)) (define (lambda-body lambda-exp)(cddr lambda-exp)) (define (make-lambda parms body)(cons "lambda (cons parms body))) (define (if? exp)(tagged-list? exp 'if)) (define (if-predicate exp)(cadr exp)) (define (if-consequent exp)(caddr exp)) (define (if-alternative exp (if (not (null? (cdddr exp)))(cadddr exp)false)) (define (make-if pred conseq alt) (list 'if pred conseq alt)) (define (cond? exp)(tagged-list? exp 'cond)) P)) (define (begin? exp)(tagged-list? exp 'begin)) (define (begin-actions begin-exp)(cdr begin-exp)) ast-e )(n dr seq))) (define (first-exp seq)(car seq)) (define (rest-exps seq)(cdr seq)) (define(sequence->exp seq) cond ((null? (last-exp? seq (first-exp seq)) (else (make-begin seq)))) (define (make-begin exp)(cons 'begin exp)) (define (operators app)(car app)) (define (operands app)(cdr app)) (define (no-operands? args)(null? args)) (define (first-operand args)(car args)) (rest-operands args)(cdr6.001 Metacircular Evaluator 2 Representing Expressions (define (tagged-list? exp tag) (and (pair? exp) (eq? (car exp) tag))) (define (self-evaluating? exp) (or (number? exp) (string? exp) (boolean? exp))) (define (quoted? exp) (tagged-list? exp ’quote)) (define (text-of-quotation exp) (cadr exp)) (define (variable? exp) (symbol? exp)) (define (assignment? exp) (tagged-list? exp ’set!)) (define (assignment-variable exp) (cadr exp)) (define (assignment-value exp) (caddr exp)) (define (definition? exp) (tagged-list? exp ’define)) (define (definition-variable exp) (if (symbol? (cadr exp)) (cadr exp) (caadr exp))) (define (definition-value exp) (if (symbol? (cadr exp)) (caddr exp) (make-lambda (cdadr exp) (cddr exp)))) ; formal params, body (define (lambda? exp) (tagged-list? exp ’lambda)) (define (lambda-parameters lambda-exp) (cadr lambda-exp)) (define (lambda-body lambda-exp) (cddr lambda-exp)) (define (make-lambda parms body) (cons ’lambda (cons parms body))) (define (if? exp) (tagged-list? exp ’if)) (define (if-predicate exp) (cadr exp)) (define (if-consequent exp) (caddr exp)) (define (if-alternative exp) (if (not (null? (cdddr exp))) (cadddr exp) ’false)) (define (make-if pred conseq alt) (list ’if pred conseq alt)) (define (cond? exp) (tagged-list? exp ’cond)) (define (cond-clauses exp) (cdr exp)) (define (begin? exp) (tagged-list? exp ’begin)) (define (begin-actions begin-exp) (cdr begin-exp)) (define (last-exp? seq) (null? (cdr seq))) (define (first-exp seq) (car seq)) (define (rest-exps seq) (cdr seq)) (define (sequence->exp seq) (cond ((null? seq) seq) ((last-exp? seq) (first-exp seq)) (else (make-begin seq)))) (define (make-begin exp) (cons ’begin exp)) (define (application? exp) (pair? exp)) (define (operators app) (car app)) (define (operands app) (cdr app)) (define (no-operands? args) (null? args)) (define (first-operand args) (car args)) (define (rest-operands args) (cdr args))