Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 24 Which of the following statements is true: A) Scheme is a functional programming language and one of the two main dialects of the

Question 24

Which of the following statements is true:

A) Scheme is a functional programming language and one of the two main dialects of the programming language Lisp.

B) In Scheme, the behavior of (car (car (car '((a b) (c d))))) is undefined or produces and error because (car '((a b) (c d))) is (a b), (car '(a b)) is a, and (car 'a) is undefined.

C) (car (car '((a b) (c d)))) yields 'a and (car (car (cdr '((a b) (c d))))) yields 'b.

D) All of the following are valid ways to write an abs(x) function that returns the absolute value of x:

(define abs (lambda (n) (if (< n 0) (- 0 n) n) ) )

(define abs (lambda (n) ((if (>= n 0) + -) 0 n) ) )

(define abs (lambda (n) (if (>= n 0) n (- 0 n)) ) )

Question 24 options:

a-

A, B, and D

b-

A, B, and C

c-

B and D

d-

C and D

e-

B and C

Question 25

Which of the following statements is true:

A) Python is a multi-paradigm programming language that supports functional programming.

B) In Python, the behavior of [['a', 'b'],['c', 'd']][:-1][0][1] is undefined or an error.

C) In Python, [['a', 'b'],['c', 'd']][1][:-1] yields ['c'].

D) In Python, [x[:-1] for x in [['a', 'b'],['c', 'd']]] yields ['a', 'c']

E) All of the following are valid ways to write an Python abs(x) function that returns the absolute value of x:

abs = lambda x: -x if x < 0 else x

abs = lambda x: [-x, x][0 if x < 0 else 1]

def abs(x): return [lambda y: 0 - y, lambda y: y - 0][0 if x < 0 else 1](x)

F) Extended BNF notation is used to describe the syntax of Python expressions at https://docs.python.org/2/reference/expressions.html

Question 25 options:

a-

C and D

b-

B and D

c-

A and F

d-

B, D, and F

e-

A, C, E, and F

f-

A, B, C, D, E, and F

Question 26

In examples and projects, it was emphasized that a Turing-Complete programming language like Racket/Scheme can be implemented without using any mutable variables at all. Python provides immutable types as well. Which of the following are benefits of side-effect-free programming using immutable types:

A) Side-effect-free functions may be safely called from any thread within a multi-threaded program as long as care is taken regarding accumulation and use of returned values if the calling thread differes from the thread executing the function.

B) Algorithms for iterating through every item of an immutable collection can be faster than similar algorithms applied to mutable collections. In particular, it is problematic to allow mutation of a collection while interacting through items in the mutable collection. As a defense against incorrect program execution, some programming languages implicitly copy mutable collections as a side-effect of iteration algorithms so that the original collection may be mutated while iteration proceeds using the implicit copy of the collection.

C) Writing functions/methods without side effects makes it easier to reason about the correctness of programs. It also makes it easier to compose those functions to create new behavior. Certain optimizations are possible where the compiler can for instance memorize the results of functions or use common subexpression elimination.

D) Side effects are operations that change the global state of a computation. Formally, all assignments and all input/output operations are considered side-effects. The term functional programming (or more accurately purely functional programming) refers to a style of programming where functions have no side effects. While it is impossible to write any real applications without any side effects (you could never write anything to the user, and you could never save anything to disk), functional programming is still a very important way of programming large parts of an application. We can get most of the benefits of functional programming while still allowing some kinds of side effects, for instance:

input/output that does not effect the global state of the system, for instance output to the screen,

assignments to local variables that do not survive the execution of the function in which they are located.

In other words, we want the execution of a function to have no effect on the global state of the system. If, in addition, the function is autonomous, we can be sure that repeated executions of the same function with the same arguments gives exactly the same result.

Question 26 options:

a-

A and D

b-

B and C

c-

B, C, and D

d-

A, B, C, and D

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

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

Define the one-person-band syndrome.

Answered: 1 week ago