Hello ECLiPSe users, I ran into a problem with a project of mine and managed to reduce it to a fairly small program (see below). It just puts two values in a hash table, makes facts from the hash table and compiles the facts. If the facts are then called with instantiated first argument (e.g., f([a],_)) they fail, but f(A,_),A=[a] succeeds. Can anyone confirm this as a bug or am I doing something stupid here? Best regards, Stephan =============== % the program: :- lib(hash). test :- make_facts(Facts), compile_term(Facts), testf([a]), testf([b]). testf(Key) :- (f(Key, _) -> printf("f(%w, _) succeeds\n",[Key]) ; printf("f(%w, _) fails\n",[Key]), (f(Key2, _), Key2=Key -> printf(" but f(Key2, _), Key2=%w succeeds!\n",[Key]) ; true ) ). make_facts(Facts) :- % add two entries in a hash table hash_create(Hash), my_hash_set(Hash, p([a], 1)), % line x % hash_set(Hash, [a], 1), % line y hash_set(Hash, [b], 1), hash_list(Hash, Keys, Values), (foreach(Key, Keys), foreach(Value, Values), foreach(Fact, Facts) do ( Fact=f(Key, Value), writeq(Fact), writeln(".") )), nl. my_hash_set(Hash1, p(X, Y)) :- hash_set(Hash1, X, Y). % The expected output is % f([a], 1). % f([b], 1). % f([a], _) succeeds % f([b], _) succeeds % The output I get: % f([a], 1). % f([b], 1). % f([a], _) fails % but f(Key2, _), Key2=[a] succeeds! % f([b], _) fails % but f(Key2, _), Key2=[b] succeeds! % If "line x" is replaced by "line y" it works. % If [a] and [b] are replaced by 'a' and 'b' % respectively, it also works. ============Received on Tue Jul 10 2007 - 18:29:16 CEST
This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:20 CEST