List-Editing softcode

This is a topic made to include commonly-asked-for functions such as those that edit lists but without sorting or duplicates.

munge(#lambda/%0,setdiff(%0,%1),setdiff(%0,%1))

This takes %0, and removes duplicate items and items in %1.

It works by creating a list comprised of the non-duplicated items of %0 without the items from %1 (This is the setdiff() in the second argument).
This list is then passed to the munge(), which has the list in original order (%0).
The items of the third argument (a copy of the second) are rearranged according to the order of the original list supplied in the first.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Non-sorting, duplicate-keeping

fold(#lambda/remove(\%0,\%1),%1,%0)

Base list: %0
Items to remove: %1
Inner function: remove(%0,%1)

--> The remove()'s %0 and %1 are not the fold()'s %0 and %1. <--
First, the inner function of fold() is evaluated with "Base list" as %0, and the first item of the "Items to remove" as %1.

The result of evaluating the inner function is used as %0 on the next pass through fold(). So in this second pass, the inner function's %0 is the result of the first pass, and %1 is the second item of "Items to remove". This cycle repeats for each item of the "Items to remove" list.

In short: remove() is fed each item of the "Items to remove" list, and removes that word (if it exists) from the "Base list"--one by one.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.