Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer the following question in racket language. The template is provided below Template ;; apply (define (apply? l) 'todo) (define (apply-func node) 'todo) (define

Please answer the following question in racket language. The template is provided below image text in transcribed image text in transcribed Template ;; apply (define (apply? l) 'todo) (define (apply-func node) 'todo) (define (apply-args node) 'todo)

image text in transcribedimage text in transcribed

4. (9 points) Your goal is to check if a datum is syntactically valid, uith respect to the specification we intro- duced in Lecture 1 and Lecture 2. Recall function quote from Lecture 3. This function produces a logical representation of the code given as parameter. The serialized code that results from quote is known as a datum, or a quoted term. In the following exercises, the quoted term shall not include boolean expressions and conditionals. A quoted expression will include numbers, define, lambda, and function application. For the sake of simplicity, there is no need to recursively check the syntactic validity (eg, you do not need to check the if the body of a lambda is syntactically valid). For instance, given a lambda are the parameters symbols? Does the body of a lambda has expected number datums as we discussed in class? You do not need to check the semantic validity of the datum (eg, check if a variable is defined) d) (1 point) Function apply? takes a datum and returns a boolean whether or not the quoted term is a function application (check-false (apply? (quote (lambda (x) x)))) (check-true (apply? (quote (x y))) e) (1 point) Function apply-func takes a quoted function application expression and returns the function being called. (f) (1 point) Function apply-args takes a quoted function application expression and should return the arguments (expressions) of the function being called. Quoting: a specification Function (quote e) serializes expression e. Note that expression e is not evaluated. UM BO A variable x becomes a symbol x. You can consider a symbol to be a special kind of string in Racket. You can test if an expression is a symbol with function symbol? . A function application (e1 en) becomes a list of the serialization of each expression e Serializing (doi i ( e ields a list with symbol 'def ine followed by a nonempty list of symbols xi followed by serialized e . Serializi ng (lambda (z.."n) e) yields a list with symbol 'lambda, followed by a possibly- empty list of symbols i, and the serialized expression e. Serializing a (cond (bi ei).-. (bn en)) becomes a list with symbol 'cond followed by a serialized branch. Kach branch is a list with two components: serialixed expresion bi and serialized expression ej Quote example #lang racket (require rackunit) (check-equal? 3 (quote 3))Serializing a number returns the number itself (check-equal? 'x (quote x)) ; Serializing a variable named x yields symbol 'x (check-equal? (list '+ 1 2) (quote (+1 2))); Serialization of function as a list (check-equal? (list 'lambda (list 'x) 'x) (quote (lambda (x) x))) 4. (9 points) Your goal is to check if a datum is syntactically valid, uith respect to the specification we intro- duced in Lecture 1 and Lecture 2. Recall function quote from Lecture 3. This function produces a logical representation of the code given as parameter. The serialized code that results from quote is known as a datum, or a quoted term. In the following exercises, the quoted term shall not include boolean expressions and conditionals. A quoted expression will include numbers, define, lambda, and function application. For the sake of simplicity, there is no need to recursively check the syntactic validity (eg, you do not need to check the if the body of a lambda is syntactically valid). For instance, given a lambda are the parameters symbols? Does the body of a lambda has expected number datums as we discussed in class? You do not need to check the semantic validity of the datum (eg, check if a variable is defined) d) (1 point) Function apply? takes a datum and returns a boolean whether or not the quoted term is a function application (check-false (apply? (quote (lambda (x) x)))) (check-true (apply? (quote (x y))) e) (1 point) Function apply-func takes a quoted function application expression and returns the function being called. (f) (1 point) Function apply-args takes a quoted function application expression and should return the arguments (expressions) of the function being called. Quoting: a specification Function (quote e) serializes expression e. Note that expression e is not evaluated. UM BO A variable x becomes a symbol x. You can consider a symbol to be a special kind of string in Racket. You can test if an expression is a symbol with function symbol? . A function application (e1 en) becomes a list of the serialization of each expression e Serializing (doi i ( e ields a list with symbol 'def ine followed by a nonempty list of symbols xi followed by serialized e . Serializi ng (lambda (z.."n) e) yields a list with symbol 'lambda, followed by a possibly- empty list of symbols i, and the serialized expression e. Serializing a (cond (bi ei).-. (bn en)) becomes a list with symbol 'cond followed by a serialized branch. Kach branch is a list with two components: serialixed expresion bi and serialized expression ej Quote example #lang racket (require rackunit) (check-equal? 3 (quote 3))Serializing a number returns the number itself (check-equal? 'x (quote x)) ; Serializing a variable named x yields symbol 'x (check-equal? (list '+ 1 2) (quote (+1 2))); Serialization of function as a list (check-equal? (list 'lambda (list 'x) 'x) (quote (lambda (x) x)))

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

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

More Books

Students also viewed these Databases questions