(1 (4 9 (12) ))
i used this rule (cons 1 (cons (cons 4 (cons 9 (cons (cons 12()))) ()) ())) but interpreter return error

Code: Select all
(cons (cons 12 ()) )
Maybe it's easier to compose it with list first eg.Ehsan wrote:Hi every . i have question about cons in lisp . how can i make this list
(1 (4 9 (12) ))
i used this rule (cons 1 (cons (cons 4 (cons 9 (cons (cons 12()))) ()) ())) but interpreter return error
Code: Select all
(list 1 (list 4 9 (list 1 2)))
Code: Select all
(cons 1(cons (list 4 9 (list 1 2)) NIL))
This is true for Scheme. The empty list needs to be quoted since it cannot be evaluated.nuntius wrote:I think the main issue is that the empty list must be written as '(). If you write (), then it will try to evaluate the function with no name.
For Common Lisp quoting is optional. (), NIL, '() and 'NIL evaluates to NIL.nuntius wrote: In Common Lisp, '() can also be written as nil.