I am trying to write a function that takes two inputs X and L, the second one of which is a list, the first one may or may not be a list.The function will then search L and take out THE FIRST APPEARANCE of X in L, and will return the rest of L untouched. I wrote what I thought (after a series of revisions) was a correct solution to this simple problem:

Is this homework? I ask because there is the REMOVE function... (edit: yes, clearly I don't know what REMOVE does... )

Your code is almost correct, I think. However, I don't know why you are checking for (null x), and that last case should be (cons (car l) (take-out-first x (cdr l))) not APPEND. What does "X may or may not be a list" mean in terms of how the function works?

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 compiledwithout 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:

Regarding REMOVE, I tried to change it before it caused confusion. Just me being stupid, sorry.

I actually don't have any hints. My first suspicion is that your GCL install is screwed up. I just tried it in SBCL and it worked like a charm. I'm downloading GCL to see what's up there right now.

Sorry GCL sucks right now. Very few CL programmers use it as it has been really left in the dust by a handful of other FOSS options over the last ten (more?) years. You might be able to get more information from GCL with the right commands. For instance, you can usually get a backtrace of the call stack or inspect local variables. Refer to the GCL manual for help.

Yeah, I just installed GCL and ran your code and no errors. You will almost certainly need to reinstall GCL. Did you build from source, or download a binary? (I always say go binary if you can). If you are reinstalling your Lisp system, you might as well go with some other Lisp unless your class said GCL is the best one for the class. A CLISP install is pretty hard to screw up and is stable just about everywhere.

Just because of my curiosity. I thought what if the requirement was to modify the input list. Well, it's not possible to tell from the description. So, I tried to see what I could get, if that would be the case, but I'm not really liking what I have:

At first I also thought I had to modify the list. Then I saw there was no such requirement, just to return the resulting list after the operation is applied.I tried to modify the list received as parameter before,too, with setf, but I failed repeatedly. I'll try to look in to what you've written too.

In the meantime I'll post another problem I am facing right now. I am using my previous function takeoutFirst to implement takeoutSecond, by iterating inside takeoutSecond until i find the first occurrence of the target object, and then sending the list's cdr to takeoutFirst, yet I get a compiler run-time error.

and i got some strange error about the recurssion, I cannot tell you cause I cannot remember and now that I tried to recompile it to see the error again, it gives me a compiler error about "_" being an unbound variable @@.Any help would be appreciated.

Wait, what is a compiler runtime error? Usually you call a compile time error an error that happened because the compiler could not understand your program. Example of a compile time error - mismatched parens. Run time error is when the compiler was able to digest the program text, but the program itself was erroneous. Example - you called a multiply function with an argument which is not a number.But if that code gives you that kind of error (I'd imagine it's a compile time error), the compiler is doing something very odd. Try reinstalling or using a different version. Another guess... is your system using any locale other then English? Is it possible that while typing the program you used some Unicode characters or "high ASCII" (that is characters with codes > 128)? Because it totally looks like there is some syntax problem, where the program is interpreted entirely different from what was intended.