Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -1,15 +1,18 @@
|
|||
# (sort keep compare xs) sorts the list xs using the three-way comparison
|
||||
# function. It keeps duplicates if the keep flag is true, otherwise it
|
||||
# discards them and returns only the unique entries.
|
||||
|
||||
\sort ==
|
||||
(\keep\compare\xs
|
||||
xs end \x\xs
|
||||
|
||||
\lo = (filter (\y compare y x T F F) xs)
|
||||
\hi = (filter (\y compare y x F keep T) xs)
|
||||
|
||||
append (sort keep compare lo);
|
||||
item x;
|
||||
sort keep compare hi
|
||||
# (sort xs) is the ordered list of all elements in list xs.
|
||||
# This version preserves duplicates.
|
||||
\sort==
|
||||
(\xs
|
||||
xs [] \x\xs
|
||||
append (sort; filter (gt x) xs); # all the items less than x
|
||||
cons x; append (filter (eq x) xs); # all the items equal to x
|
||||
sort; filter (lt x) xs # all the items greater than x
|
||||
)
|
||||
|
||||
# (unique xs) is the ordered list of unique elements in list xs.
|
||||
\unique==
|
||||
(\xs
|
||||
xs [] \x\xs
|
||||
append (unique; filter (gt x) xs); # all the items less than x
|
||||
cons x; # x itself
|
||||
unique; filter (lt x) xs # all the items greater than x
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue