Deleting items – remove and take

To delete the first item in a series, use remove:

remove [10 11 12] ;== [11 12]

The take word does the same, but returns that item instead of the changed series:

take [10 11 12] ;== 10

To delete an item at a certain position, use at, the same way as we did with insert:

s: [0 1 2 3 4 5]   ;== [0 1 2 3 4 5]remove at s 2      ;== [2 3 4 5] s                  ;== [0 2 3 4 5]   ; item 1 at position 2 is deleted

To delete the last item of a series, you could use remove at s length? s, but take/last does the same thing and returns that last item as well:

take/last [10 11 12] ;== 12

To delete a certain number of items, use /part:

remove/part [10 11 12] 2    ;== [12]

The take/part phrase has the same effect on a series, but returns ...

Get Learn Red - Fundamentals of Red now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.