There is a remove function, correct, but as far as I understand REMOVE will remove all occurrences of the object with the value you described, right?
I need to remove only THE FIRST occurrence of X.
I stated that X may be a list(actually i checked again and it is a cons structure.. for sure), and so I check for null X (I guess I may as well skip that line), but this has no effect over the compiler message, I already compiled
without this line, the result is the same.
YES, this is homework (but im not cheating! I wrote this but the T.A. is as helpful is the gcl compiler or less with those comments.).
The homework problem is this exactly:
Define a function takeoutFirst ( X L ) which takes out the first occurrence of the cons
structure X from a list L.
For exà̃˿e: ( takeoutFirst ‘(a b) ‘( ( b b) (a b) ( b a) (a b) (c c) ))
( ( b b) ( b a) (a b) (c c) )
Now, thinking that maybe I was having a problem using the COND macro, I reorganized the code into an if-else code:
- Code: Select all
(defun takeoutFirst2(X L)
(if (null L)
(if(equal X (car L))
(append (car L)
(takeoutFirst X (cdr L))))))
But this was to no avail... compiler's message was exactly the same; no more, no less.