Hp prime list function - indexing into a list



#2

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?


#3

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.


#4

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.


#5

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  HP50g: Writing a function that returns a function Chris de Castro 2 2,141 12-10-2013, 06:49 PM
Last Post: Han
  IFERR function on HP Prime Mic 2 1,850 12-02-2013, 01:33 AM
Last Post: cyrille de Brébisson
  Milestones:List of IEEE Milestones -> HP-35 AlbertTocarLoseggs 4 2,148 11-27-2013, 08:52 AM
Last Post: Massimo Gnerucci (Italy)
  HP Prime: Dirichlet's eta function recognized but not numerically evaluated Helge Gabert 0 1,155 11-16-2013, 03:41 PM
Last Post: Helge Gabert
  HP-Prime : Extracting elements from a list in RPN Miguel Toro 0 1,628 11-15-2013, 06:44 PM
Last Post: Miguel Toro
  Possible bug with sqrt function in the HP prime Michael de Estrada 6 2,542 11-15-2013, 12:49 PM
Last Post: Michael de Estrada
  [HP-Prime] Picking elements from a List in a program Jean-Michel 3 2,027 11-15-2013, 04:16 AM
Last Post: dg1969
  Hp PRIME - how to send a list to the connectivity Kit giancarlo 1 1,347 11-10-2013, 11:50 AM
Last Post: Tim Wessman
  How do I decompose a list with the HP Prime. Hal Bitton in Boise 4 2,063 11-08-2013, 02:07 PM
Last Post: Patrice
  HP-41 MCODE: The Last Function - at last! Ángel Martin 0 1,076 11-08-2013, 05:11 AM
Last Post: Ángel Martin

Forum Jump: