Post Reply 
List commands and functions in HP program language
04-21-2014, 05:37 PM
Post: #1
List commands and functions in HP program language
Is there a way to extract or insert an element from or into a list using HP prime programming language? Eg in a list {1,2,3,4,5,6} how would you extract element 4 and put it into a variable?
Find all posts by this user
Quote this message in a reply
04-21-2014, 05:46 PM (This post was last modified: 04-21-2014 05:47 PM by eried.)
Post: #2
RE: List commands and functions in HP program language
Code:
local new_variable;
new_variable:=variable[item_number];

My website: erwin.ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
04-21-2014, 08:08 PM
Post: #3
RE: List commands and functions in HP program language
I tried this :
local var;
var:={1,2,3,4,5,}[4]

There is Syntax error?
Find all posts by this user
Quote this message in a reply
04-21-2014, 08:29 PM (This post was last modified: 04-21-2014 08:29 PM by Han.)
Post: #4
RE: List commands and functions in HP program language
(04-21-2014 08:08 PM)Alfon Wrote:  I tried this :
local var;
var:={1,2,3,4,5,}[4]

There is Syntax error?

Well, you do have an extra comma after the 5. Try this:

local var:={1,2,3,4,5};
local item:=var(4);

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
04-21-2014, 08:49 PM
Post: #5
RE: List commands and functions in HP program language
As for the reasoning as to why it only works once inside a variable, how would one distinguish between "multiply your list times a number" {1,2,3,4,5}*(4) and "get the 4th item in the list" {1,2,3,4,5}(4)?

When it has a name it then becomes a named setter/getter function internally.

TW

Although I work for the HP calculator group, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
04-21-2014, 08:57 PM
Post: #6
RE: List commands and functions in HP program language
Yes this works! Thanks. Looks like you need the () around the element number and the list in a variable. Now how would you insert an element?? Is that possible?
Find all posts by this user
Quote this message in a reply
04-21-2014, 09:02 PM
Post: #7
RE: List commands and functions in HP program language
Try the store operator...

var(4):="store"

Or if you prefer, you can use the "store"â–¶var(4) variant.

TW

Although I work for the HP calculator group, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
04-21-2014, 11:02 PM
Post: #8
RE: List commands and functions in HP program language
You may also like to check out the POS command:

nv:={1,2,3,4,5,6};
a:=POS(nv,4);
Find all posts by this user
Quote this message in a reply
04-22-2014, 04:16 PM
Post: #9
RE: List commands and functions in HP program language
You may also have nested lists, and can access them as follows:

list:={1,2,3,{4,5}};
item:=list(4,2); this stores 5 into the variable 'item'.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 




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