Hi
This error, The parameter 'Max' is bound in the context, surprised me in this code that I thought was valid. I solved it by re-writing it as commented, but I am still not sure why the first version raised the error.
implement main
open core
/*
Returns the string/frequency pairs that have the highest frequency*/classpredicates
get_max_pairs:()->tuple{string Term, integer Frequency}*.
clauses
get_max_pairs()=MaxOccurences:-Occurences=[tuple("str",20), tuple("int",10), tuple("bool",5), tuple("real",20)],/*
Get the maximum frequency*/Max= list::maximum([Frequency|| tuple(_,Frequency)inOccurences]),/*
Select all the strings with the highest frequency*/MaxOccurences= list::filter(Occurences,{(tuple(_,Max))}). /*Max raises an error here*/%MaxOccurences = list::filter(Occurences, {(tuple(_, X)):-X=Max}).
run():-
console::write(get_max_pairs()).
end implement main
goal
console::runUtf8(main::run),
console::readchar()=_.
If X is used before the anonymous predicate it is actually a bound variable and the anonymous predicate would/should perform a test. If the test is intended (as it is in your case) there is obviously no problem. But if the intension was actually to have a (plain/fresh) input parameter to the anonymous predicate then the result will be a bug. So to avoid bugs coming from accidental reuse of a variable name we have decided that all variables used in the parameter list of an anonymous predicate must be free. If you really need the test it can easily be moved to the body of the anonymous predicate as you have also figured out.