Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

?This assignment is done in Scheme R5RS using DrRacket. The factorial function to be used is: (define fac (lambda (x) (if (= x 0) 1

image text in transcribedimage text in transcribed ?This assignment is done in Scheme R5RS using DrRacket. The factorial function to be used is: (define fac (lambda (x) (if (= x 0) 1 (* x (fac (- x 1)))))) The bind function to be used is: (define (bind k v al) (cons (list k v) al)) The lookup function to be used is: (define (lookup k al) (cond ((null? al) #f) ((equal? k (caar al)) (car al)) (else (lookup k (cdr al)))))

Submission: Please submit a DrRacket file via Canvas 1. (5 points) In this task, we define a function called fac.mem, which is the memoized version of the factorial function; it takes an integer n as input and returns the factorial of n e Define the factorial function fac as usual. Define the bind and lookup functions for association lists, as we discussed in class. Recall that an association list in Scheme is just a list of pairs and each pair contains a key and a value. - (bind k v al) returns a new association list, which is the result of adding a new entry (k,v) to the beginning of asso- -(lookup k al) returns the value for key k in al if there is . Define a global variable al for the association list used in fac mem. ciation list al an entry for k and returns #f otherwise. (define alO) . Finally, define fac.mem. When given n, it checks whether there is an entry for n in al. If there is, it returns the value in the entry if not, it invokes (fac n adds the entry (n, (fac n)) in the association list, and returns (fac n) Notes: - To distinguish the two cases in fac.mem, add the following ut n is in the display command for the case when the in current association list. It displays the string on screen. (display memoization hit ') Submission: Please submit a DrRacket file via Canvas 1. (5 points) In this task, we define a function called fac.mem, which is the memoized version of the factorial function; it takes an integer n as input and returns the factorial of n e Define the factorial function fac as usual. Define the bind and lookup functions for association lists, as we discussed in class. Recall that an association list in Scheme is just a list of pairs and each pair contains a key and a value. - (bind k v al) returns a new association list, which is the result of adding a new entry (k,v) to the beginning of asso- -(lookup k al) returns the value for key k in al if there is . Define a global variable al for the association list used in fac mem. ciation list al an entry for k and returns #f otherwise. (define alO) . Finally, define fac.mem. When given n, it checks whether there is an entry for n in al. If there is, it returns the value in the entry if not, it invokes (fac n adds the entry (n, (fac n)) in the association list, and returns (fac n) Notes: - To distinguish the two cases in fac.mem, add the following ut n is in the display command for the case when the in current association list. It displays the string on screen. (display memoization hit ')

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

Oracle 11G SQL

Authors: Joan Casteel

2nd Edition

1133947360, 978-1133947363

More Books

Students also viewed these Databases questions

Question

=+what kinds of policies and practices should be developed?

Answered: 1 week ago