Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

LISP: A dynamic car

Name: Anonymous 2012-01-30 20:27

I have a complex list of lists and want something to check the second element of every list of the list in the loop, any supported features like this?

Name: Anonymous 2012-01-30 20:35


CL-USER> (mapcar #'second '((a b c) (1 2 3) (9 8 7)))
(B 2 8)


You'll have to specify what you meant by "check" better, if you wanted something fancier, you could compose that second (or cadr) with your "checking" function.

Some other examples:
(loop for list in lists when (your-check (second list)) do (stuff ...))
or
(find-if #'(lambda (x) (eq x 2)) '((a b c) (1 2 9) (2 3 4)) :key #'second)

Many other functions allow transforming the elements in a list with key with :key. There's obviously dozens other ways of doing this and I just mentioned the ones that first came to mind - if you specified your problem better I might have given a more complete solution.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List