Post Reply 
list functions sugestion
09-23-2015, 10:52 PM
Post: #13
RE: list functions sugestion
(09-22-2015 11:06 AM)Tyann Wrote:  Hello
What would be great also:
Insert ( list , position ,value or list )
and
Delete (list, position, [ number of elements ] )
please

Here are two functions doing that:

Code:
// Insert 'value' at 'position' in 'list'. Value can be a list or a single value.
// If position is <=1, value is inserted at the beginning of the list
// If position is after the last element of the list, value is inserted at the end of the list

EXPORT InsList(list,position,value)
BEGIN
  CASE
    IF position<=1 THEN CONCAT(value,list);END;
    IF position>SIZE(list) THEN CONCAT(list,value);END;
    DEFAULT CONCAT(CONCAT(list({1,position-1}),value),list({position,SIZE(list)}));
  END;
END;

Code:
// Delete a 'qty' of elements from 'list' starting at 'position'.
// The elements to be deleted are at the intersection of [1,size(list)] and [position, position+qty-1] 
//    for ex. DelList({1,2,3,4},0,3) deletes the first and second elements of the list and returns {3,4}

EXPORT DelList(list,position,qty)
BEGIN
  LOCAL lb,le;
  IFTE(position<=1,lb:={}, lb:=list({1,position-1}));
  IFTE(position+qty>SIZE(list), le:={}, le:=list({position+qty,SIZE(list)}));
  CONCAT(lb,le);
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
list functions sugestion - hpfx - 09-20-2015, 07:55 PM
RE: list functions sugestion - komame - 09-20-2015, 08:41 PM
RE: list functions sugestion - hpfx - 09-20-2015, 08:49 PM
RE: list functions sugestion - komame - 09-20-2015, 08:53 PM
RE: list functions sugestion - hpfx - 09-20-2015, 08:59 PM
RE: list functions sugestion - douganc - 09-21-2015, 07:15 AM
RE: list functions sugestion - parisse - 09-21-2015, 09:15 AM
RE: list functions sugestion - hpfx - 09-22-2015, 08:04 AM
RE: list functions sugestion - Tyann - 09-22-2015, 11:06 AM
RE: list functions sugestion - Didier Lachieze - 09-23-2015 10:52 PM
RE: list functions sugestion - komame - 09-22-2015, 01:25 PM
RE: list functions sugestion - hpfx - 09-24-2015, 02:53 PM



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