From: Chris Gehlker
Subject: Re: Cons Cells
Date: 
Message-ID: <BA0A1D28.23CF1%gehlker@fastq.com>
On 11/27/02 3:20 AM, in article
································@melontraffickers.com, "A.Melon"
<·····@melontraffickers.com> wrote:

> How can I create a function in Lisp to count the number of cons cells that a
> list is using? For
> example, (num-cons-cells '(1 2 (3 (4 5)) 6)) => 8.
> 

(defun num-cons-cells (lst)
  (if (null lst)
      0
      (if (consp (first lst))
          (+ (num-cons-cells (first lst)) (num-cons-cells (rest lst)) 1)
          (+ (num-cons-cells (rest lst)) 1))))


> Also, how can I create another function to create an associative list mapping
> a symbol to the number
> of times it occurs. For example, (map '(a)) => ((a . 1))

Just a 'sec.



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----