list functions sugestion
|
09-20-2015, 07:55 PM
(This post was last modified: 09-20-2015 08:40 PM by hpfx.)
Post: #1
|
|||
|
|||
list functions sugestion
Hello,
I've functions suggestion, it's related to list in programs. GET(L1,n) get n-th item of the list ex :GET({1, 2, 3},2) -> 2 FOREACH L1 AS var; END; to iterate lists items. ex: FOREACH {1,2} AS it; PRINT(it);END; note : or with alternative syntax (less block style) : FOREACH(L1,var); END; Arr2List() and List2Arr() convert array (vectors, matrix) to list and reverse.. ex:Arr2List([1, 2]) -> {1, 2} Arr2List([[1, 2][3,4]]) -> {{1, 2}{3,4}} Let me know your feeling about such suggestion, I do really like to have a foreach function like in many modern language, it makes life simplier to iterate into lists. And please, add a Lists menu in Cmds (program editing), to show existing list command like SIZE, SUB, POS ... Otherwise it's not obvious o guess such functions does exists... |
|||
09-20-2015, 08:41 PM
(This post was last modified: 09-20-2015 08:44 PM by komame.)
Post: #2
|
|||
|
|||
RE: list functions sugestion
Hi,
To get n-th item of the list you can use index: local l; //declare variable for the list l:={1, 2, 3} l(2) -> 2 you can also store values in the n-th item of list that way: l(2):=4 PRINT(l) => {1, 4, 3} FOREACH? => there is the ITERATE function, but not for all purposes. Arr2List and List2Arr? => Check list2mat and mat2list. BR |
|||
09-20-2015, 08:49 PM
(This post was last modified: 09-20-2015 08:56 PM by hpfx.)
Post: #3
|
|||
|
|||
RE: list functions sugestion
thank you konamz,
In the mean time, I got found for SIZE (I edited my post) but you helped me for other. Indeed, most did already exist, that's nice! (09-20-2015 08:41 PM)komame Wrote: FOREACH? => there is the ITERATE function, but not for all purposes.ITERATE is related to an expression. I would like to suggest a FOREACH function, not to extend existing ITERATE. in case you don't know foreach (like in php for example), it's nothing related to hp prime interate. First, it's a block function (like a while), it goes throu each item on that way : Code: FOREACH {1, 2, 3 } AS var; example Code: L1:={4, 6, 9, 3}; |
|||
09-20-2015, 08:53 PM
(This post was last modified: 09-20-2015 08:54 PM by komame.)
Post: #4
|
|||
|
|||
RE: list functions sugestion
Yes, FOREACH is very modern function and there is no equivalent in HP PRIME, but you can do workaround using FOR:
Code: local list = {1, 2, 3 }; |
|||
09-20-2015, 08:59 PM
Post: #5
|
|||
|
|||
RE: list functions sugestion | |||
09-21-2015, 07:15 AM
Post: #6
|
|||
|
|||
RE: list functions sugestion
Hello,
It should be possible to write a User Function for the FOREACH list function using a few lines of code. Could some kind person write such a function and place it in the library here for the benefit of all. Thank You Colm |
|||
09-21-2015, 09:15 AM
Post: #7
|
|||
|
|||
RE: list functions sugestion
Inside CAS, you can do e.g.
l:=[1,2,4]; for j in l do print(j); end; |
|||
09-22-2015, 05:46 AM
Post: #8
|
|||
|
|||
RE: list functions sugestion
Hello,
It depends on what you are trying to achieve, but on Prime, you can do: function(list) and function will apply to each element of the list. This acts like a FOREACH. But it is limited to math functions... Cyrille Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP. |
|||
09-22-2015, 08:04 AM
(This post was last modified: 09-22-2015 08:05 AM by hpfx.)
Post: #9
|
|||
|
|||
RE: list functions sugestion
Hello,
(09-22-2015 05:46 AM)cyrille de brébisson Wrote: Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.You probably work on hp prime calculators at hp (let's hope), wowww... (09-22-2015 05:46 AM)cyrille de brébisson Wrote: Hello,I didn't know that. That's already interresting, but it was more to cover programming stuff. Here is a (stupid) example: Code: L1:={4, 6, 9, 3}; Of course, I know it can be achieved by Code:
As well as all loops (FOR...) can be replaced by a simple WHILE cmd. But we all find it conenient to use proper syntax for each loops. If you at hp, you think it could be convenient to add this loop type, it would be nice, and I would like it. And it would make the hp-basic more modern, btw. Of course, it's just an idea that can be extented to matrix, strings... Thank you for your attention. |
|||
09-22-2015, 11:06 AM
(This post was last modified: 09-22-2015 11:07 AM by Tyann.)
Post: #10
|
|||
|
|||
RE: list functions sugestion
Bonjour
Ce qui serait bien aussi : Insert(Liste,position,liste ou valeur) et Delete(liste,position,[nombre d'éléments]) S'il vous plait Hello What would be great also: Insert ( list , position ,value or list ) and Delete (list, position, [ number of elements ] ) please Sorry for my english |
|||
09-22-2015, 01:25 PM
(This post was last modified: 09-23-2015 04:54 AM by komame.)
Post: #11
|
|||
|
|||
RE: list functions sugestion
If you want insert a value for a vector you can use the ADDCOL:
ADDCOL([1,2,3,4],9,3) => [1,2,9,3,4] But there is no equivalent command for lists. I agree that INSERT and DELETE commands should be added for lists and vectors, and also strings. BR, Piotr |
|||
09-23-2015, 05:48 AM
Post: #12
|
|||
|
|||
RE: list functions sugestion
hello
>L1:={4, 6, 9, 3}; >FOREACH L1 AS it if(it MOD 2 == 0) it=it-1; END; >// now L1 is { 3, 5, 9, 3 } L1-((L1 MOD 2)==0) does that L1 MOD 2 does a modulo 2 of each element of L1 the ==0 will return a list of 0 and 1, with 1 for every element of L1 that is 0 and the final - removes that 1 in cases of equality mod 0 from L1 Cyrille Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP. |
|||
09-23-2015, 10:52 PM
Post: #13
|
|||
|
|||
RE: list functions sugestion
(09-22-2015 11:06 AM)Tyann Wrote: Hello Here are two functions doing that: Code: // Insert 'value' at 'position' in 'list'. Value can be a list or a single value. Code: // Delete a 'qty' of elements from 'list' starting at 'position'. |
|||
09-23-2015, 11:14 PM
Post: #14
|
|||
|
|||
RE: list functions sugestion
I would like to see a LOOKUP function
So given a list like ((Fred, England),(Armstrong,USA)) I can do entry := lookup(1,"Fred") or ...lookup(2,"USA"). maybe returning position rather the list entry. It would be useful for both lists and spreadsheets. Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz |
|||
09-23-2015, 11:54 PM
(This post was last modified: 09-23-2015 11:56 PM by Didier Lachieze.)
Post: #15
|
|||
|
|||
RE: list functions sugestion
With L1:={{"Fred", "England"},{"Armstrong","USA"}}
you can do entry := POS(L1(1),"Fred") or ...POS(L1(2),"USA") |
|||
09-24-2015, 02:53 PM
(This post was last modified: 09-24-2015 02:53 PM by hpfx.)
Post: #16
|
|||
|
|||
RE: list functions sugestion | |||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)