how to find the list element by knowing its position in clisp?

advertisements

If I know the position of an element in a list in clisp, then how could I retrieve the element knowing its position. Is there any predefined function for it?


For lists only there is NTH:

CL-USER> (nth 2 '(1 2 3 4 5))
3

For SEQUENCES (vectors, strings, lists ...) there is ELT:

CL-USER> (elt '(1 2 3 4 5) 2)
3

If you really need a lot to access element by index, I'll advice you to consider using vectors (and access elements by aref) instead of lists, especially if you have logn sequences, because accessing element by index in lists may need to travel along all list to your element.

Of course, if you have small amount of data, you wan't feel any difference, but it looks good to use things right for me.