HP Forums

Full Version: GET - picking an element of a list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Good solution.
You may be interested in my collection of other List routines here.
https://www.hpmuseum.org/forum/thread-9411.html
Widely complete!
The conversation in this thread points the problem of subdivisions or packages in the catalog view.
Reference URL's