Counting elements of a list

Discussion of Common Lisp
Post Reply
ageg
Posts: 1
Joined: Sat Oct 25, 2014 7:08 pm

Counting elements of a list

Post by ageg » Sat Oct 25, 2014 7:15 pm

Hi,

I am very new in lisp and I am trying to find the "vector" of a list of lists of different depths.
For example:
((1 (1 2 3)) (2 (1 2)) (4 (1 1 1 1))) and get a result (1 3 1 2 1 4).
I tried with length and various combinations of loop but it is not possible because the 1 or 2 or 4 are not lists.
If someone can help or give some direction i will be grateful.

Thank you in advance,

Ag

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: Counting elements of a list

Post by Goheeca » Sun Oct 26, 2014 1:56 am

You have predicate functions atom, consp, listp and null at disposal in CL.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Post Reply