kiwifreak3 wrote:I think I've got rid of them now although I'm still using the setq command within the while-loop, because I can't quite figure out where I should put the end-bracket of let otherwise
Sorry, I misspoke, you shouldn't create variables with SETQ, because they will be set as global variables and leak out of your function, and it also risks changing a variable with the same name which belongs to a surrounding context. Inside a LET which establishes your own context for the variable using SETQ is fine.
You are trying to use both iteration and recursion, and modifying the list at the same time. This seems overly complicated. I suggest using a nested iteration and an accumulator variable. That is, use LET to initialize a variable to NIL, and then PUSH on it. To decide what to push use a loop over A. To check if an element of A is in B use MEMBER or implement an equivalent if you can only use primitives. Don't forget to return you accumulator (possibly REVERSE'd, if order seems important) and the end of the function.
Rather than using index and ELT to loop over lists you should probably either use DOLIST or at least a (while list-variable ... (setq list-variable (cdr list-variable))). Note that in EmacsLisp empty list is false, and so can be used as a termination condition.