[m-rev.] for review: avoiding the use of nondet foreign_procs

Fergus Henderson fjh at cs.mu.OZ.AU
Thu May 17 17:33:38 AEST 2001


That change looks fine.  I have one small suggestion (below).

I also think we should also change the reference manual to deprecate
the use of nondet foreign_procs.

On 17-May-2001, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> +table_nondet_return_all_ans(TrieNode, Answer) :-
> +	semipure pickup_answer_list(TrieNode, CurNode0),
> +	semipure table_nondet_return_all_ans_2(CurNode0, Answer).
> +
> +table_multi_return_all_ans(TrieNode, Answer) :-
> +	semipure pickup_answer_list(TrieNode, CurNode0),
> +	( semipure return_next_answer(CurNode0, FirstAnswer, CurNode1) ->
> +		(
> +			Answer = FirstAnswer
> +		;
> +			semipure table_nondet_return_all_ans_2(CurNode1,
> +				Answer)
> +		)
> +	;
> +		error("table_multi_return_all_ans: no first answer")
> +	).
> +
> +:- semipure pred table_nondet_return_all_ans_2(c_pointer::in,
> +	ml_answer_block::out) is nondet.
> +
> +table_nondet_return_all_ans_2(CurNode0, Answer) :-
> +	semipure return_next_answer(CurNode0, FirstAnswer, CurNode1),
> +	(
> +		Answer = FirstAnswer
> +	;
> +		semipure table_nondet_return_all_ans_2(CurNode1, Answer)
> +	).
> +

It would be slightly more concise to write that as follows:

table_nondet_return_all_ans(TrieNode, Answer) :-
	semipure pickup_answer_list(TrieNode, CurNode0),
	semipure return_next_answer(CurNode0, FirstAnswer, CurNode1),
	semipure table_multi_return_all_ans_2(FirstAnswer, CurNode1, Answer).

table_multi_return_all_ans(TrieNode, Answer) :-
	semipure pickup_answer_list(TrieNode, CurNode0),
	( semipure return_next_answer(CurNode0, FirstAnswer, CurNode1) ->
		semipure table_nondet_return_all_ans_2(FirstAnswer, CurNode1,
				Answer)
	;
		error("table_multi_return_all_ans: no first answer")
	).

:- semipure pred table_nondet_return_all_ans_2(c_pointer::in,
	ml_answer_block::out) is multi.

table_nondet_return_all_ans_2(Answer, _, Answer).
table_nondet_return_all_ans_2(_, CurNode0, Answer) :-
	semipure return_next_answer(CurNode0, FirstAnswer, CurNode1),
	semipure table_nondet_return_all_ans_2(CurNode1, Answer).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list