The parameter 'Max' is bound in the context
Posted: 28 Jul 2015 7:45
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.
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.
Code: Select all
implement main
open core
/*
Returns the string/frequency pairs that have the highest frequency*/
class predicates
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) in Occurences]),
/*
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()=_.