List-Editing softcode
Submitted by JulesLetters on Fri, 2007-08-10 17:38.
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.
»
- Printer-friendly version
- Login or register to post comments

Click 

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.