Re: [eclipse-users] bug in lib(hash), compile_term/1 and/or handling of arguments

From: Kish Shen <kisshen_at_cisco.com>
Date: Wed, 11 Jul 2007 01:40:14 +0100
Hi Stephan,

Stephan Schiffel wrote:
> 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?
>   

Yes, this appears to be a bug with compile_term/1. If you look at the 
compiled code for f/2 generated by compile_term/1, it fails if the first 
argument is a list -- this is wrong.

I am not sure what exectly is causing the problem, so I can't really 
suggest how you can work around this, except for the suggestions you 
found yourself.

There are some problems with the existing compiler, which in general we 
are unable to fix directly. For this reason, we are replacing this 
compiler with one written in ECLiPSe itself (and not C like the existing 
compiler), which should be much easier to maintain (and to extend). We 
plan to replace the compiler in the next release of ECLiPSe. Your 
program compiles and work correctly with this new compiler.

Cheers,

Kish


> 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.
>
> ============
>
> _______________________________________________
> ECLiPSe-Users mailing list
> ECLiPSe-Users_at_crosscoreop.com
> http://www.crosscoreop.com/mailman/options/eclipse-users
>   
Received on Wed Jul 11 2007 - 01:40:36 CEST

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET