Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please answer the following question in racket language. The template is provided below Template ;; lambda (define (lambda? node) 'todo) (define (lambda-params node) 'todo) (define
Please answer the following question in racket language. The template is provided below Template
;; lambda (define (lambda? node) 'todo) (define (lambda-params node) 'todo) (define (lambda-body node) 'todo)
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) (a) (3 points) Function lambda? takes a datum and returns a boolean whether or not the quoted term is a lambda. (check-true (lambda? (quote (lambda (x) x)))) (check-false (lambda? (quote 3))) You can check if a datum is a list of symbols with a combination of functions symbol2and andmap (check-true (andmap symbol? (quote (x y z)))) (check-false (andmap symbol? (quote (x 3 z)))) b) (1 point) Function lambda-params takes a quoted lambda and returns the list of parameters (symbols) of the given function declaration. (check-equal (equal? (list 'x) (lambda-params (quote (lambda (x) y)))) (c) (1 point) Function lambda-body takes a quoted lambda and returns a list of terms of the given lambda. (ist ) (ambda-params (quote 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) (a) (3 points) Function lambda? takes a datum and returns a boolean whether or not the quoted term is a lambda. (check-true (lambda? (quote (lambda (x) x)))) (check-false (lambda? (quote 3))) You can check if a datum is a list of symbols with a combination of functions symbol2and andmap (check-true (andmap symbol? (quote (x y z)))) (check-false (andmap symbol? (quote (x 3 z)))) b) (1 point) Function lambda-params takes a quoted lambda and returns the list of parameters (symbols) of the given function declaration. (check-equal (equal? (list 'x) (lambda-params (quote (lambda (x) y)))) (c) (1 point) Function lambda-body takes a quoted lambda and returns a list of terms of the given lambda. (ist ) (ambda-params (quoteStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started