Quote:

> Hi there:

Hi

not much help but anyway :

(response not written in textual order)

Quote:

> Consider a predicate such as member(X,[1,2,3,4]),X==2 ->

> write(a);write(b). It has exactly one solution that outputs 'a'.

> However, what I'm looking for are 4 solutions b,a,b,b.

> One problem is the implicit cut in this kind of conditionals. Replacing

> it by a version with no cuts, e.g., if/3 in Sicstus or Eclipse, yields

> the same solution 'a'.

> The obvious solution is to remove the member statement from the

> condition, i.e.,

> member(X,[1,2,3,4]), (X==2->write(a);write(b)).

> I can't use this one, however, since the member predicate actually is an

> arbitrary predicate that may fail, resulting in a failure of the whole

> expression.

how , arbitrary ?

is it a totally unknown predicate argument ?

or can you enforce some structure/invariants on it ?

maybe you can use findall/setof/bagof and test

specifically for null list case (corresponding to failure)

Quote:

> The second solution is ugly:

> Statements (C1,...,Cn->T;E) are replaced by

> if(C1,if(C2,if(...,if(Cn,T,E),E),E),...,E)

hmm , ... (maybe a solution)

(i haven't looked close that the above transformation really works but if so)

maybe one can put C1,...,Cn in a list

and make a higher-order-predicate which transforms and executes in just

that way :

(that way some of the ugliness would go away)

Statements (C1,...,Cn->T;E) are replaced by

nondet_multi_list_if( [C1,...,Cn] ,T ,E )

%predicate with too long name

nondet_multi_list_if( Cs ,T ,E ) :-

nondet_multi_list_if_transform( Cs ,T ,E ,Pred ),

call( Pred ).

nondet_multi_list_if_transform( [C ] ,T ,E ,if(C,T ,E) ).

nondet_multi_list_if_transform( [C|Cs] ,T ,E ,if(C,Pred,E) ):-

is_cons(Cs),

nondet_multi_list_if_transform( Cs ,T ,E ,Pred ).

cons([X|Xs],X,Xs).

is_cons([_|_]).

then you could do

:- op(1101,xfy,=->). %one step higher than ; (is this ISO compliant ?)

Cs =-> T ; E :-

!,

nondet_multi_list_if( Cs ,T ,E ).

Cs =-> T :-

nondet_multi_list_if( Cs ,T ,true ).

and you could instead write :

[C1,...,Cn] =-> T ; E

or

[ member( X ,[1,2,3,4] ) ,X==2 ] =-> write( a ) ; write( b )

or something like that

(i have *not* tested this so beware !)

Quote:

> I'm looking for a solution that is more elegant/direct/efficient.

> Any hints will be appreciated.

> Thanks,

> Alex

i think in mercury (/= prolog but ~= prolog with type,mode,determinism system),

the test (A) in the if-else-construct (A->B;C) can succeed many times.

maybe this is not exactly what you need ?

(perhaps one could translate that construct from mercury to prolog

, but i doubt it)

otherwise you can try to rewrite the problem/program so that the nondet

generator is not in the test ?

(like you say , with member it's easy , but maybe it can be done in your

program too ?)

end of rant

md9slj

Stefan Lj