How to find the position of atom in the list

Discussion of Common Lisp

How to find the position of atom in the list

Postby bokshi » Mon Nov 07, 2011 11:15 am

How to find the position of an atom in the list. for eg

(position-in-list 'a (a b c d e))
-> 0

(position-in-list 'b (a b c d e) )
-> 1

(position-in-list 'Z(a b c d e) )
->nil.
bokshi
 
Posts: 2
Joined: Mon Nov 07, 2011 8:35 am

Re: How to find the position of atom in the list

Postby krzysz00 » Mon Nov 07, 2011 8:02 pm

I replied in your previous thread with a working position-in-list function. However, Common Lisp provides a standard position function which will meet your needs. In you case, you can call it by:

Code: Select all
(position 'a '(a b c d e))
-> 0

(position 'f '(a b c d e))
-> NIL
krzysz00
 
Posts: 4
Joined: Mon Nov 07, 2011 5:10 pm


Return to Common Lisp

Who is online

Users browsing this forum: Bing [Bot] and 3 guests