counting nils in a list
- From: david <notmas@xxxxxxxxx>
- Date: Sat, 14 Mar 2009 10:58:41 -0700 (PDT)
hello lispers,
i was inspired by this code from graham's acl:
(defun compress (x)
(if (consp x)
(compr (car x) 1 (cdr x))
x))
(defun compr (elt n lst)
(if (null lst)
(list (n-elts elt n))
(let ((next (car lst)))
(if (eql next elt)
(compr elt (+ n 1) (cdr lst))
(cons (n-elts elt n)
(compr next 1 (cdr lst)))))))
(defun n-elts (elt n)
(if (> n 1)
(list n elt)
elt))
to write a little program to generate forsythe edward notations.
i changed it a bit to make it work for my program.
now i try to write my own compress function to just
handle my particular case. thinking this will be easy
since i believe i understand the code above. and
also that will be simpler than a general compress
function. i also want to learn to design the recursive
function with car, cdr, and cons. so given a list like
'(nil nil B nil nil nil |k| nil)
i want it to return (2B3k1)
my usual approach of typing at the repl until something
works has failed me. i need a better design methodology.
all thoughts, comments, flames appreciated.
thanks, david
.
- Follow-Ups:
- Re: counting nils in a list
- From: Pascal J. Bourguignon
- Re: counting nils in a list
- Prev by Date: Re: Opinion about Lisp
- Next by Date: Re: counting nils in a list
- Previous by thread: Re: 2nd RFD: comp.lang.lisp.newlisp
- Next by thread: Re: counting nils in a list
- Index(es):
Relevant Pages
|