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:
What are your tricks?
Regards, Thibault
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