数据库代写|INFR11199 – Advanced Database Systems (Spring 2023)

本次美国作业案例分享是一个编程语言及翻译器相关的编程代写限时测试

For problems 1 through 9 circle the single best answer. Each of these questions is worth 1 point.

1. Given below is some code written in a programming language that we did not study this
semester. It evaluates to 10. Semantically, this code would be most equivalent to
____________.

(\fluffy -> 1 + fluffy) 9

a. If (!x) x + 1 else 9
b. f(Fluffy, Result) :- \+ Fluffy, Result is 1 + Fluffy. f(_, 9).
c. (funcall #'(lambda (x) (+ 1 x)) 9)
d. All of the above

2. In the Prolog relation given below, the first argument is a list and the second argument is
intended to be the last element of the list (e.g., atTheEnd([1,2,3], 3)). In order for this to
work, the underlined portion in the second rule should be:

atTheEnd([X], X).
atTheEnd( _______________ ) :- atTheEnd(L, X).

a. [ ], X
b. [ L ], X
c. L + 1, X
d. [ _ | L ], X
e. None of the above is correct

3. The Prolog expression f(X, Y) :- g(X, Y). is semantically equivalent to saying:

a. there exists some X and Y (where X and Y must be different values) such that f(X, Y) and
g(X, Y) are both true
b. if g(X, Y) is true, then f(X, Y) is true
c. if f(X, Y) is true, then g(X, Y) is true
d. all of the above

4. Which of these Prolog list expressions is NOT equivalent to [ A, B, C, D ]?

a. [ A, B, C | [ D ] ]
b. [ A | [ B, C, D ] ]
c. [ [ A, B, C, D ] | [ ] ]
d. [ A, B | [ C, D ] ]
e. None of the above (i.e., all of the above are the same list)

5. In the Prolog program shown below, what kind of cut is being used?

d(3).
d(1).
b(1).
b(2).
b(3).
c(1).
c(2).
a(X) :- b(X), c(X), !, d(X).

a. green cut
b. red cut
c. black cut

6. The Python programming language supports lambda expressions. Even though you may not
know Python, you should be able to figure out that the Python function given below is
semantically equivalent to which of the Lisp expressions listed below:

def foo(n) : return lambda a : a + n # This is a python function

a. (defun foo (a n) (+ a n))
b. (defun foo (n) #'(lambda (a) (+ a n)))
c. (defun foo ( ) #'(lambda (a n) (+ a n)))
d. (funcall #'(lambda (n) (+ a n)) a)
e. None of the above