HP Forums
Hp prime list function - indexing into a list - Printable Version

+- HP Forums (https://archived.hpcalc.org/museumforum)
+-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html)
+--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html)
+--- Thread: Hp prime list function - indexing into a list (/thread-252283.html)



Hp prime list function - indexing into a list - Andy B (Australia) - 10-06-2013

I cannot figure out how to iterate through a list extracting individual items.

The POS function searches a list for a particular value but I don't want that - I want to get the exact 1st, 2nd etc. items of a list. I'm a bit surprised such a function doesn't exist? I mean, if you think of a list as an array, there seems no way to be able to get to item 1 or item 2 etc. which you would think are fundamental operations. Am I missing something?


Re: Hp prime list function - indexing into a list - Han - 10-06-2013

Quote:
I cannot figure out how to iterate through a list extracting individual items.

The POS function searches a list for a particular value but I don't want that - I want to get the exact 1st, 2nd etc. items of a list. I'm a bit surprised such a function doesn't exist? I mean, if you think of a list as an array, there seems no way to be able to get to item 1 or item 2 etc. which you would think are fundamental operations. Am I missing something?


listname(pos) -- an example using the built-in list name L1 would be L1(2) to get the second item in the list.


Re: Hp prime list function - indexing into a list - Tim Wessman - 10-06-2013

Also, L1(1,2,3) would access "4" in this list: {{1,{2,3,4}},5}. For a matrix, M1(3,2) would access item in 3rd row, 2nd col. Storage also functions similarly.

TW

Edited: 6 Oct 2013, 10:44 a.m.


Re: Hp prime list function - indexing into a list - cyrille de Brébisson - 10-07-2013

Quote:
Also, L1(1,2,3) would access "4" in this list: {{1,{2,3,4}},5}. For a matrix, M1(3,2) would access item in 3rd row, 2nd col. Storage also functions similarly.

and of course it also works the other way around:
L1(1):= value changes the first value of L1.
L1(1,2,3):=v does as you would expect...
L1(10):=v if L1 is of size <10 will increase the size as needed.
L1(0):= val will ADD val at the end of the list (so you do not have to do L1(SIZE(L1)+1):= val

cyrille