134k views
2 votes
Which of the following forms will return an error when run? Select all that apply. Group of answer choices

a. (+ 2 '2)
b. ('+ 2 3)
c. '(+ 2 3)
d. (define a a)
e. (define a 'a)

1 Answer

0 votes

Final answer:

The Lisp-like expressions (b) '+ 2 3 and (d) (define a a) will return errors, due to incorrect use of quotation and an undefined recursive definition, respectively.

Step-by-step explanation:

The question appears to relate to the evaluation of expressions in a Lisp-like programming language. When considering which forms will return an error when run, one needs to understand the syntax and evaluation rules of that language:

  • (a) (+ 2 '2) will not return an error; it will try to add 2 to the quoted symbol '2, which may not be what is intended, but not an error per the language's syntax.
  • (b) ('+ 2 3) will return an error because the quote prevents the evaluation of + as a function.
  • (c) '(+ 2 3) will not return an error; it is a valid quoted list, meaning it doesn't evaluate the expression inside but returns it as a list.
  • (d) (define a a) will return an error as it attempts to define 'a' in terms of itself without an existing definition for 'a'; this is a recursive definition without a base case.
  • (e) (define a 'a) will not return an error; it defines 'a' with the value of the quoted symbol 'a'.

To summarize, the expressions (b) ('+ 2 3) and (d) (define a a) are the ones that will return an error when run.

User RvanDalen
by
8.6k points