item of a list

Martin (archive)

Usenet Archive
Joined
Aug 1, 2000
Messages
245
Reaction score
0
how can i get an item at a certain index in a list (5th for example) i usually use foreach to get the items one by one....
martin
 
Check out the "nth" function:

e.g.:
(setq FOO (list 0 1 2 3 4 5 6)); FOO euqals (0 1 2 3 4 5 6)
(nth 5 FOO)

returns 5 ;nth starts counting from 0
 
Or, if you want to know whether/where an item is in a list, then (vl-position <item> <list>). nil means it ain't there 'tall.
 
_$ (setq liststring (list "A" "B" "C" "D" "E"))
("A" "B" "C" "D" "E")
_$ (setq nlist (nth 3 liststring))
"D"
_$ (vl-position "D" liststring)
3
# Conclusion >> (vl-position symbol list) >< (nth n lst)
 
True. The (nth) function will return whatever value is in the specified index position in a list, or nil if the list is shorter than the index position supplied. The (vl-position) function returns the first position (as an integer) of a specific item in a list or nil if not found. These functions are not identical, but rather complimentary.

John Uhden, Cadlantic
<the e-mail address is bogus>
http://www.cadlantic.com
Sea Girt, NJ
 

Latest threads

Back
Top