sorting a list #94
-
hello, I would like to sort a list. I could almost do it like this: @prefix list: <http://www.w3.org/2000/10/swap/list#> .
@prefix math: <http://www.w3.org/2000/10/swap/math#> .
@prefix : <hrttp://ex.org/> .
{ (3 5 8 3 4) :sorted ?result} => { :result :is ?result } .
() :sorted () .
{
?list :sorted ?sorted
}
<=
{
?list math:min ?min .
(?list ?min) list:remove ?rest .
?rest :sorted ?sortedRest .
?sorted list:firstRest (?min ?sortedRest) .
}
. except for the duplicates and the fact that it works only backwards (why?). Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
There is a built-in
which gives
|
Beta Was this translation helpful? Give feedback.
-
The general motivation for backward rules is given by TimBL in https://www.w3.org/2000/10/swap/doc/tutorial-1.pdf page 20
Euler is now eye but it needs a hint to know when to do backward chaining and this is when it sees a |
Beta Was this translation helpful? Give feedback.
There is a built-in
list:sort
in eye but it removes duplicates.If you don't want the remove duplicates, here is a possible implementation