Using Lisp: Write a Common Lisp function named myList which creates the following list and returns it

275 Views Asked by At

This was the list given:

(4 (7 22) "art" ("math" (8) 99) 100)

but I'm still having trouble coming up with the correct code in order to answer this problem

all I have come up with is

(defund myList() (4 (7 22) "art" ("math" (8) 99 100) ) 

but obviously that is not correct

1

There are 1 best solutions below

5
Barmar On

You need to quote the list so it won't be treated as a function call.

defund is a typo for defun, and you were missing a close parenthesis.

(defun myList()
  '(4 (7 22) "art" ("math" (8) 99 100)))

If you need non-constant data, use the LIST function to create fresh lists at each level.

(defun myList ()
  (list 4 (list 7 22) "art" (list "math" (list 8) 99 100)))