How to get sequence of items from a list in Qore

Is there a Qore operator / function to get subscriptions from a list without changing the source list, i.e. equivalent substr()

. The operator extract

removes elements from the original list.

list l = (1,2,3,4,5,6,7,8,9);
list l2 = extract l, 2, 4;
printf("l:%y\nl2:%y\n", l, l2);

l:[1, 2, 7, 8, 9]
l2:[3, 4, 5, 6]

      

+3


source to share


2 answers


select

operator supports in the condition argument, the $#

macro expands as an index.



list l = (1,2,3,4,5,6,7,8,9);
list l2 = select l, $# >= 2 && $# <2+4;
printf("l:%y\nl2:%y\n", l, l2);

l:[1, 2, 3, 4, 5, 6, 7, 8, 9]
l2:[3, 4, 5, 6]

      

+2


source


The select statement is the best solution, as you said in your answer to your question.

splice and extract both operators will modify the list operand which is not what you want.



Note that Qore has a prominent feature issue ( 1781 ) - not targeted for release yet, but that may go in the next major release (0.8.13) if there is any interest.

+2


source







All Articles