Page 1 of 1

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

PostPosted: Sat Aug 18, 2018 1:14 am
by Pytty55
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:
Code: Select all
(remove 'n '(nose naked retired art friend)) ==> (art friend retired)


What I did so far :

Code: Select all
(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 :
Code: Select all
(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

PostPosted: Sat Aug 18, 2018 3:55 am
by nuntius
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.