This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

function which builds, from a list, a list without the eleme

2 posts · 1402 views

I'm trying to write a function which builds, from a list, a list without the elements
that begin with a given letter, and by using char and string; example:
(remove 'n '(nose naked retired art friend)) ==> (art friend retired)
What I did so far :
(defun my-remove (r list)
(cond
((not list) nil)
((equal (char (string (car list))0)#R)(my-remove r(cdr list)))
(t (cons (car list) (my-remove r(cdr list)))) ) )
But keeps returning :
(remove 'n '(nose naked retired art friend)) ==> (NOSE NAKED ART FRIEND)
What did I miss ?

Re: function which builds, from a list, a list without the e

Things to look at / fix:
  • called REMOVE instead of MY-REMOVE
  • hard-coded #\R instead of using the passed parameter
  • pass a character to remove instead of a quoted symbol (#\r vs 'r)
  • run (string 'nose) and look at the capitalization of the result
P.S. The forum strips backslashes. Double-backslash is converted to single backslash. Every preview or submit does another strip, so be careful.