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 
Maybe it's easier to compose it with list first eg.
(list 1 (list 4 9 (list 1 2)))
Then (list a b c) is an abbrivation for (cons a (cons b (cons c NIL)))
So translating the first list would get you:
(cons 1(cons (list 4 9 (list 1 2)) NIL))
Then do the same with the rest. Note that I'm using NIL here to keep away the the extra parenthesis. If you're using Scheme you need to use '()
It's quite difficult to get it right so before list and quasiquoting it must have been a source of many errors
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.
This is true for Scheme. The empty list needs to be quoted since it cannot be evaluated.
nuntius wrote:
In Common Lisp, '() can also be written as nil.
For Common Lisp quoting is optional. (), NIL, '() and 'NIL evaluates to NIL.
I'm the author of
two useless languages that uses
BF as target machine.
Currently I'm planning a Scheme compiler :p