Page 1 of 1

List indexing

Posted: Mon Jan 09, 2012 7:06 pm
by didi
; implicit indexing from "Code Patterns"

(set 'L '(a b (c d (e f) g) h i))

(L 2 2 1) → f
(L 2 2) → (e f)

Is there a reverse function to get the vector of an element in a nested list ?
Is it right, that the find function principally does this, but only in the highest level ?

For example
(find 'a L ) -> 0
(find 'b L ) -> 1
(find 'c L ) -> nil ?

Re: List indexing

Posted: Mon Jan 09, 2012 10:41 pm
by johu
from newLISP Manual and Reference
To find expressions in nested or multidimensional lists, use the ref and ref-all functions.
Then,

Code: Select all

> (set 'L '(a b (c d (e f) g) h i))
(a b (c d (e f) g) h i)
> (ref 'b L)
(1)
> (ref 'c L)
(2 0)
> (ref 'f L)
(2 2 1)
> 

Re: List indexing

Posted: Tue Jan 10, 2012 6:08 am
by didi
Super, thankyou !