Post Reply 
lib for developers : libList
10-08-2016, 09:37 PM (This post was last modified: 09-17-2017 03:06 PM by primer.)
Post: #1
lib for developers : libList
Hello,
The hpprime provide already many usefull list functions, mostly for math,
But I'm sharing with you my libList v1 that provide some basic list functions for programming.

.hpprgm  LibList.hpprgm (Size: 5.05 KB / Downloads: 30) see next post for version 2.

API list : L_GET, L_SET, L_INS, L_DEL, L_MAP, ARR2LST and LST2VECT

L_INS(lst,pos,item)
Insert an item to a list. Retruns the new list
if pos is null, insert at the end
if pos<0, count -pos from right to insert at
ex :
Code:
L_INS({11,22,33},1, 99); // returns {99,11,22,33}
L_INS({11,22,33},0,99); // returns {11,22,33,99}
L_INS({11,22,33},-1,99); // returns {11,22,99,33}
L_INS({1,2,3},2,{7}); // returns {1,{7},2,3} -- insert any kind of object


L_SET(lst,pos,item)
Set (change) an item from a list. Retruns the new list.
note : it does not add item, list size does not increase

if pos is null, change the last item
if pos<0, count -pos from right to change
ex :
Code:
L_SET({11,22,33},1, 99); // returns {99,22,33}
L_SET({11,22,33},0,99); // returns {11,22,99}
L_SET({11,22,33},-1,99); // returns {11,99,33}
L_SET({1,2,3},2,{7});  // returns {1,{7},3}


L_DEL(lst,pos)
Remove an item from a list. Returns the new list
if pos is null, remove the last item
if pos<0, remove by counting -pos from the right
ex :
Code:
L_DEL({11,22,33},1); // returns {22,33}
L_DEL({11,22,33},0); // returns {11,22}
L_DEL({11,22,33},-1); // returns {11,33}


L_GET(lst,pos)
Get an item from a list. Returns the item
if pos is null, get last item
if pos<0, count -pos from right
if pos exceed list size, return last
ex :
Code:
L_GET({11,22,33,44},2); // returns 22
L_GET({11,22,33,44},0); // returns 44
L_GET({11,22,33,44},-1); // returns 33


L_MAP(lst,userfunction)
Call a function on each list item. Returns the list of function returns
ex :
Code:
EXPORT myfct(a) // a userfunction
RETURN a*2;
END;

L_MAP({1,2,3},"myfct"); // returns {2,4,6}


ARR2LST(array)
Convert vector or matrix to list
resulting list have embeded lists in case of matrix
ex :
Code:
ARR2LST([1,2,3]); // returns {1,2,3}
ARR2LST([[1,2,3]]); // returns {{1,2,3}}
ARR2LST([[1,2][3,4]]); // returns {{1,2},{3,4}}


LST2VECT(lst)
Convert a simple list to a vector
note : list items must be numbers
ex :
Code:
LST2VECT({1,2,3}); // returns [1,2,3]

primer
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
lib for developers : libList - primer - 10-08-2016 09:37 PM
RE: lib for developers : libList - primer - 10-16-2016, 09:46 AM
RE: lib for developers : libList - primer - 09-17-2017, 05:10 PM



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