CS 5010: Guided Practice 4.1 — Solution
The question was:
Consider the following data definition:
;; A ListOfStrings (LOS) is one of ;; -- empty ;; -- (cons String LOS)
Which of the following expressions has a value that is a LOS ?
Here are the answers:
-
(cons "abc" empty)
Answer: Yes.
empty
is a LOS and"abc"
is a string, so(cons "abc" empty)
is a LOS. -
(cons "bcd")
Answer: No.
This expression has no value, becausecons
is given a wrong number of arguments. -
(cons "cde" (cons "ef" empty))
Answer: Yes.
This is a LOS. -
(cons "3" (cons "4" empty))
Answer: Yes.
This too is a LOS. -
(cons 3 (cons 4 empty))
Answer: No.
3
and4
are numbers, not strings.