List commands and functions in HP program language - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: List commands and functions in HP program language (/thread-1134.html) |
List commands and functions in HP program language - Alfon - 04-21-2014 05:37 PM 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? RE: List commands and functions in HP program language - eried - 04-21-2014 05:46 PM Code: local new_variable; RE: List commands and functions in HP program language - Alfon - 04-21-2014 08:08 PM I tried this : local var; var:={1,2,3,4,5,}[4] There is Syntax error? RE: List commands and functions in HP program language - Han - 04-21-2014 08:29 PM (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); RE: List commands and functions in HP program language - Tim Wessman - 04-21-2014 08:49 PM 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. RE: List commands and functions in HP program language - Alfon - 04-21-2014 08:57 PM 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? RE: List commands and functions in HP program language - Tim Wessman - 04-21-2014 09:02 PM Try the store operator... var(4):="store" Or if you prefer, you can use the "store"â–¶var(4) variant. RE: List commands and functions in HP program language - DrD - 04-21-2014 11:02 PM You may also like to check out the POS command: nv:={1,2,3,4,5,6}; a:=POS(nv,4); RE: List commands and functions in HP program language - Han - 04-22-2014 04:16 PM 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'. |