CS 5010: Guided Practice 4.1 — Solution
The question was:
Consider the following data definition:
;; A StringList is one of ;; -- empty ;; -- (cons String StringList)
Which of the following expressions has a value that is a StringList ?
Here are the answers:
-
(cons "abc" empty)
Answer: Yes.
empty
is a StringList and"abc"
is a string, so(cons "abc" empty)
is a StringList. -
(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 StringList. -
(cons "3" (cons "4" empty))
Answer: Yes.
This too is a StringList. -
(cons 3 (cons 4 empty))
Answer: No.
3
and4
are numbers, not strings.