[mercury-users] hash_table module bug?

Dominique de Waleffe ddw at miscrit.be
Fri Sep 7 01:15:02 AEST 2001


The  small program below fails for me with the following output:
[168]>./xx
> some values
> create a table
> initialise its contents
Mercury runtime: array__set: array index out of bounds

Have I done anything wrong?

Version seems to be:
Mercury Compiler, version 0.10-mc, configured for i686-pc-cygwin

D.

:- module xx.
:- interface.

:-import_module io.
:- pred main(io__state::di,io__state::uo) is det.

:- implementation.
:-import_module string,list,int,hash_table.

% fold list over a hash_table  
:-pred foldl_with_dictionary(pred(T,D,D),list(T),D,D).
:-mode foldl_with_dictionary(pred(in,hash_table_di,hash_table_uo) is det,
	     in,hash_table_di,hash_table_uo) is det.
foldl_with_dictionary(_P,[],D,D).
foldl_with_dictionary(P,[X|R],D0,D):-
	P(X,D0,D1),
	foldl_with_dictionary(P,R,D1,D).

main-->
	io__format("> some values\n",[]),
	{L=[{"k2",3},{"k21",3},{"k22",3},{"k23",3},{"k24",3}]},
	io__format("> create a table\n",[]),
	{H1=hash_table__new_default(string_double_hash)},
	io__format("> initialise its contents\n",[]),
	{foldl_with_dictionary((pred(KV::in,
				     DD0::hash_table_di,
				     DD::hash_table_uo) is det:-
				KV={K,V},
				DD=hash_table__det_insert(DD0,K,V)),
			      L,H1,H2)},
	io__format("> Done table has %d elems\n",[i(num_occupants(H2))]).

:- end_module xx.

--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list