List indexing

Q&A's, tips, howto's
Locked
didi
Posts: 166
Joined: Fri May 04, 2007 8:24 pm
Location: Germany

List indexing

Post 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 ?

johu
Posts: 143
Joined: Mon Feb 08, 2010 8:47 am

Re: List indexing

Post 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)
> 

didi
Posts: 166
Joined: Fri May 04, 2007 8:24 pm
Location: Germany

Re: List indexing

Post by didi »

Super, thankyou !

Locked