Re: How to return clause in findall/3
From: reader (no-spam_at_sonic.net)
Date: 08/14/04
- Previous message: Pere Montolio: "Re: How to return clause in findall/3"
- In reply to: Pere Montolio: "Re: How to return clause in findall/3"
- Next in thread: Pere Montolio: "Re: How to return clause in findall/3"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 13 Aug 2004 22:46:53 GMT
Pere Montolio wrote:
> In addition to the previous (and very nice) solution, you can also
> test something like:
>
> clause2term(sc(A,B,C)) :- sc(A,B,C).
>
> followed by:
>
> findall(A,clause2term(A),L).
>
> (written without test: no visual prolog available).
I like this idea better but I purposely omitted 'findall' because I
am not sure it a good idea to expose Prolog newcomers to 'findall' early
on.
That said, SWI-Prolog allows
clause2term(X) :- X.
[ or clause2term(X) :- call(X). ]
which allows
clauses2list(Template,List) :-
findall(Template,clause2term(Template),List).
Given
p(1).
p(cat).
p([mouse,mole,bird]).
we have
?- clauses2list(p(_X),L).
L = [p(1), p(cat), p([mouse, mole, bird])] ;
--
sequitur AT sonic DOT net
Maximize end-user autonomy.
- Previous message: Pere Montolio: "Re: How to return clause in findall/3"
- In reply to: Pere Montolio: "Re: How to return clause in findall/3"
- Next in thread: Pere Montolio: "Re: How to return clause in findall/3"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]