Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Metacircular Evaluator ( Racket Language ) Implement let * expressions. Pay careful attention to the following details of the semantics of let * :

The Metacircular Evaluator (Racket Language)
Implement let* expressions.
Pay careful attention to the following details of the semantics of let*:
The expressions that determine the values of the variables bound by the let* must be evaluated.
The body of a let* is a sequence of expressions.
If you are unclear on the semantics of let*:
Read the R5RS standard or try out examples in DrRacket.
Hint: How can you desugar a let* expression? That is, how can let* be implemented as a derived expression?
(define (true? x)
(not (eq? x false)))
(define (false? x)
(eq? x false))
(define (make-procedure parameters body env)
(list 'procedure parameters body env))
(define (compound-procedure? p)
(tagged-list? p 'procedure))
(define (procedure-parameters p)(cadr p))
(define (procedure-body p)(caddr p))
(define (procedure-environment p)(cadddr p))
(define (enclosing-environment env)(cdr env))
(define (first-frame env)(car env))
(define the-empty-environment '())
(define (make-frame variables values)
(mcons variables (list->mlist values)))
(define (frame-variables frame)(mcar frame))
(define (frame-values frame)(mcdr frame))
(define (add-binding-to-frame! var val frame)
(set-mcar! frame (cons var (mcar frame)))
(set-mcdr! frame (mcons val (mcdr frame))))
(define (extend-environment vars vals base-env)
(if (=(length vars)(length vals))
(cons (make-frame vars vals) base-env)
(if ((length vars)(length vals))
(error "Too many arguments supplied" vars vals)
(error "Too few arguments supplied" vars vals))))
(define (lookup-variable-value var env)
(define (env-loop env)
(define (scan vars vals)
(cond ((null? vars)
(env-loop (enclosing-environment env)))
((eq? var (car vars))
(mcar vals))
(else (scan (cdr vars)(mcdr vals)))))
(if (eq? env the-empty-environment)
(error "Unbound variable" var)
(let ((frame (first-frame env)))
(scan (frame-variables frame)
(frame-values frame)))))
(env-loop env))
(define (set-variable-value! var val env)
(define (env-loop env)
(define (scan vars vals)
(cond ((null? vars)
(env-loop (enclosing-environment env)))
((eq? var (car vars))
(set-mcar! vals val))
(else (scan (cdr vars)(mcdr vals)))))
(if (eq? env the-empty-environment)
(error "Unbound variable -- SET!" var)
(let ((frame (first-frame env)))
(scan (frame-variables frame)
(frame-values frame)))))
(env-loop env))
(define (define-variable! var val env)
(let ((frame (first-frame env)))
(define (scan vars vals)
(cond ((null? vars)
(add-binding-to-frame! var val frame))
((eq? var (car vars))
(set-mcar! vals val))
(else (scan (cdr vars)(mcdr vals)))))
(scan (frame-variables frame)
(frame-values frame))))
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions