On Thu, Oct 10, 2019 at 08:54:08 -0300, Soni L. wrote:
> it'd be nice to have a limit() function companion to select() where select
> skips the first n and limit skips everything after n.
> e.g. limit(1) --> nothing, limit(1, 1, 2, 3) --> 1, etc
In most languages this would be called "take" and it is indeed a useful
thing to be able to do.
Daniel> For your first example, the stack is  on input, so n_items
Daniel> is set to MIN(1, 1 - 1) which will be 0. We remove the 1, set
Daniel> top to 0 and return 0 items, matching your limit(1) -->
Daniel> For your second example, the stack is [1 1 2 3] on input, so
Daniel> n_items is set to MIN(1, 4 - 1) which will be 1. Remove the 1,
Daniel> truncate to 1 items, return it. Works again.
You don't actually need to remove the count, just truncate the stack to
n+1 items and return n.