HP Forums
GET - picking an element of a list - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: GET - picking an element of a list (/thread-15777.html)



GET - picking an element of a list - pinkman - 10-22-2020 10:24 PM

Hi,
The list object is a good paradigm to return more than a value in a program, eventually of various types.
Well because the Prime is not a RPL calculator, there cannot be an OBJ-> function.

My question is: how to pick an element of a list, in the Home view ?

First approach: manually edit the given list, to copy or isolate the needed element.
Not really clever.

Second approach: assign the list to a var, then use direct addressing on that var.
LL:={2,4,6,8}
LL(3)
(Result: 6)

This is a good approach, but most of the time we don’t need a persistent var to handle a single value.

Third approach (my favorite, but... see #4): using Ans
{1,2,3,4}*2
Ans(3)
(Result: 6)

Good approach also, but your list is not always in Ans.

Fourth approach, object of this post: using the GET function, if Ans doesn’t handle your list, and you just want to pick the list in the history.
GET({2,4,6,8},3)
(Result: 6)

Well good but... there is no GET function!
Don’t panic, here it is:

Code:

EXPORT GET(L,I)
BEGIN
 RETURN L(I);
END;

What are your tricks?
Regards, Thibault


RE: GET - picking an element of a list - StephenG1CMZ - 10-22-2020 10:53 PM

Good solution.
You may be interested in my collection of other List routines here.
https://www.hpmuseum.org/forum/thread-9411.html


RE: GET - picking an element of a list - pinkman - 10-23-2020 09:28 PM

Widely complete!
The conversation in this thread points the problem of subdivisions or packages in the catalog view.