### non-linear list conversion to linear

Posted:

**Wed Oct 29, 2008 12:45 am**Hello again, can you please help me with this? I've been working on it all night. What I want to do is to take a non-linear list and to convert it to linear. For example the list: (1 (2 (1 3 (2 4) 3) 1) (1 4)) should be made: (1 2 1 3 2 4 3 1 1 4). So far I've managed to produce half a result: (1 2 1 3 2 4) and I really don't know where I'm going wrong since the code seems valid to me.

Here is the code:

Also, if you figure out how to do it can you please tell me how to get each atom only once in the resulting list since I fear my approach on this last bit is a bit blunt.

Here is the code:

- Code: Select all
`(defun lin(x)`

(cond

((null x) nil)

((listp (car x)) (cons NIL (lin (car x))))

((atom (car x)) (cons (car x) (lin (cdr x))))

)

)

Also, if you figure out how to do it can you please tell me how to get each atom only once in the resulting list since I fear my approach on this last bit is a bit blunt.