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?
|
|||
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; My website: ried.cl |
|||
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? |
|||
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 : 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 |
|||
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 HP, the views and opinions I post here are my own. |
|||
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?
|
|||
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 HP, the views and opinions I post here are my own. |
|||
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); |
|||
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 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)