Folks, could anyone provide an example of how to use "removeAllBy". There is no such example in the programs provided under examples and I don't understand the arguments that need to be included.
Thanks in advance
Dave Plummer MD
-
- VIP Member
- Posts: 81
- Joined: 18 Jul 2006 17:18
Example for removeAllBy
Dave Plummer
Re: Example for removeAllBy
Code: Select all
implement main
open core
clauses
run() :-
X = "abc",
List = [ "ABC", "aBc", "cba", "abc", "AbC", "abC" ],
L = list::removeAllBy(string::compareIgnoreCase, List, X),
% L = list::removeAllEq({(A, B) :- equal = string::compareIgnoreCase(A,B)}, List, X),
% L = list::filter(List, {(A) :- equal <> string::compareIgnoreCase(A,X)}),
console::write(L),
_ = console::readLine().
end implement main
goal
console::runUtf8(main::run).
-
- VIP Member
- Posts: 81
- Joined: 18 Jul 2006 17:18
Re: Example for removeAllBy
Thank you for the example.
There is some stuff here I don't understand but I'll work through it using debug to learn.
Again, thanks for your reply.
There is some stuff here I don't understand but I'll work through it using debug to learn.
Again, thanks for your reply.
Dave Plummer
-
- VIP Member
- Posts: 81
- Joined: 18 Jul 2006 17:18
Re: Example for removeAllBy
Gukalov
is it possible to do this same thing with different domains?
For example if x=1 and List=[1,2,3] in your example? What is the comparator to be used?
dave
is it possible to do this same thing with different domains?
For example if x=1 and List=[1,2,3] in your example? What is the comparator to be used?
Code: Select all
X=1,
List=[1,2,3],
L = list::removeAllBy(somecomparitor, List, X),
Dave Plummer
Re: Example for removeAllBy
Code: Select all
class predicates
somecomparItor : core::comparator{PofigChyo}. % define your own domain here instead of "PofigChyo"
clauses
somecomparItor(A, B) = less :- A < B, !. % define your own "less" here instead of "A < B,".
somecomparItor(A, B) = greater :- A > B, !. % define your own "greater" here instead of "A > B,".
somecomparItor(_, _) = equal.
I think that using list::removeAllBy is not the best way to clean the lists.
- Thomas Linder Puls
- VIP Member
- Posts: 1424
- Joined: 28 Feb 2000 0:01
Re: Example for removeAllBy
The predicate removeAllBy is used when you want to supply your own comparison routine.
For strings it could for example (as above) be a comparison that consider uppercase and lowercase letters the same.
But for numbers it would (almost always) be natural to use the normal number comparison.
However, that is exactly what the predicate removeAll does:
For strings it could for example (as above) be a comparison that consider uppercase and lowercase letters the same.
But for numbers it would (almost always) be natural to use the normal number comparison.
Code: Select all
clauses
run() :-
L1 = [1, 2, 3, 4, 5],
L2 = list::removeAllBy(compare, L1, 4),
stdio::writef("L2 = %\n", L2).
Code: Select all
clauses
run() :-
L1 = [1, 2, 3, 4, 5],
L2 = list::removeAll(L1, 4),
stdio::writef("L2 = %\n", L2).
Regards Thomas Linder Puls
PDC
PDC