@Ben: This is not a valid setf call - the problem is that it does not update xs.
i.e.: xst is installed in xs with the item removed, but xs is not updated. If the second item needs to be removed, xst will be the first in it.
you need to bind xst to xs and replace xs in the remove call with xst. Then this will remove all x elements more. i.e:
(defun biggerElems(x xs) (let ((xst xs)) (dolist (elem xs) (when (> x elem) (setf xst (remove elem xst)))) xst))
It may be a little faster to install xst (copy-list xs) and then use delete instead of deleting (delete is destructive ... depending on your implementation, it may be faster than deleting. Since you call it several times, you can get better performance by copying the list once and destructively deleting it).
As an alternative:
(defun bigger-elems (x xs) ; I prefer hyphen separated to camelCase... to each his own (loop for elem in xs when (<= x elem) collect elem))
Looking back at your original post, this is a bit confusing ... you say that you delete all elements larger than x, but your code looks like it is trying to delete all elements x more. The solutions I wrote return all elements larger than x (i.e.: delete all elements x greater than).
source share