newbie exploring better ways



The following function removes only the first occurrence of an element
from a list. Is this very different than how experienced Lispers do
things? The function is part of my homework assignment. However, my
homework is just to write a function that does its job. I am trying to
learn if there are better ways to do it.

(defun remv (item l)
"a function to remove (without modifying the list) the FIRST
occurrence of a given element"
(let ((result-list nil)(flag 0))
(dolist (curr l)
(if (equalp curr item)
( if(equalp flag 1) (push curr result-list) (setq flag 1))
(push curr result-list)))
(reverse result-list)))
.



Relevant Pages

  • Re: newbie exploring better ways
    ... Is this very different than how experienced Lispers do ... The function is part of my homework assignment. ... (if (equalp curr item) ... OK, presuming you were under orders to roll your own implementation from more basic stuff, Griff has given you excellent guidance on how to create a neater solution. ...
    (comp.lang.lisp)
  • Re: newbie exploring better ways
    ... The function is part of my homework assignment. ... (if (equalp curr item) ... Did your teacher suggest EQUALP for the comparison of curr with item? ... EQUALP is not the normal predicate Lisp uses. ...
    (comp.lang.lisp)
  • Re: Reverse a linked list
    ... # while (curr) { ... # /* else empty list is its own reverse; ... # return root; ... list = prev; ...
    (comp.lang.c)