Post Reply 
GET - picking an element of a list
10-22-2020, 10:24 PM
Post: #1
GET - picking an element of a list
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

Thibault - not collector but in love with the few HP models I own - Also musician : http://walruspark.co
Find all posts by this user
Quote this message in a reply
10-22-2020, 10:53 PM
Post: #2
RE: GET - picking an element of a list
Good solution.
You may be interested in my collection of other List routines here.
https://www.hpmuseum.org/forum/thread-9411.html

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
10-23-2020, 09:28 PM
Post: #3
RE: GET - picking an element of a list
Widely complete!
The conversation in this thread points the problem of subdivisions or packages in the catalog view.

Thibault - not collector but in love with the few HP models I own - Also musician : http://walruspark.co
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)