Question: Question 27 In classroom examples and projects, closures were used to implicitly construct parse trees. Which of the following statements are true? A) Programs that

Question 27

In classroom examples and projects, closures were used to implicitly construct parse trees. Which of the following statements are true?

A) Programs that encapsulate parse trees within closures can be written with substantially fewer lines of code than similar programs implemented using multiple classes and instances to encapsulate nodes in a parse tree.

B) It is possible to construct a parse tree composed of closures and then interpret the entire program represented by the parse tree by invoking the closure at the root of the parse tree.

C) It is better to construct the entire parse tree for a program (or compilation unit) prior to interpreting any portion of the parse tree. In other words, "don't interpret the tree while constructing it." It is difficult to implement looping constructs and conditional code execution if interpretation happens during parsing.

D) A parse tree can only be interpreted in any predefined order such as pre-order, in-order, or post-order.

E) Backus Naur Form (BNF) is itself a functional programming language that emphasizes recursion, and the syntax (BNF) can be expressed in BNF.

Question 27 options:

a-

A, B, C, D, and E

b-

A, C, and E

c-

B and D

d-

A, B, D, and E

Question 28

Racket compilers handle tail recursion very efficiently, as efficiently as a program that just uses loops instead of recursion. (In particular, tail recursive functions don't use stack space for every recursive call.) Which of the following statements are true?

A) The following function uses tail recursion: (define (my-member e x) (cond ((null? x) #f) ((equal? e (car x)) #t) (else (my-member e (cdr x)))))

B) The following function uses tail recursion and implements a version of the standard "filter" function: (define (my-func f s) (if (null? s) '() (cons (f (car s)) (my-func f (cdr s)))))

C) The following function uses tail recursion and implements a version of the standard "filter" function: (define (my-func f s) (cond ((null? s) '()) ((f (car s)) (cons (car s) (my-func f (cdr s)))) (else (my-func f (cdr s)))))

D) First class functions are an alternative to using recursion in functional programming languages like Racket.

Question 28 options:

a-

B and C

c-

B and D

d-

A, B, C and D

e-

A and C

Question 29

Using only functions you write and the following built-in/library functions (define, cons, car, cdr, cond/else, empty?) write your own function named skipper that returns every third element in a list starting with the first item, then skip two items, then the next item, etc.

(skipper '(A B C D E F G H)) should return

'(A D G)

Your implementation must fit within the 6 lines allowed for the answer to this question. [Hint: You may implement a helper function to use within your skipper function]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!