Re: member and findall or setof don't get along?
Jan Wielemaker <[email protected]> Tue, 15 Apr 2014 09:07:26 +0200
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 15-04-14 08:52, Ross Boylan wrote:
> The following fails on the first recursion at the findall:
> cd1([Disk | Ds], SoFar, Names, WithDates) :-
> format("Ancestor Graph ~p: ", Disk),
> deep_ancestors(Disk, now, Graph),
> format(atom(FileName), "ancestors-~p.svg", [Disk]),
> u_plot(Graph, FileName),
> pgraph(Graph, WithDates), nl, nl,
> vertices(Graph, Vs),
> %setof(Name, W^member(nw(Name, W), Vs), Names),
> findall(Name, member(Name, Vs), Names),
> append(SoFar, Names, SoFar2),
> cd1(Ds, SoFar2, Names, WithDates).
On the second iteration, Names is already bound, so setof/findall
only succeeds if the result set is exactly the same as for the first
iteration. That is probably not what you want. Maybe findall/4?
Mode analysis would be a nice thing to have ...
Cheers --- Jan
> It also failed with the setof. So on the first call it works; then it
> recurses and fails. In the debugger it simply fails immediately at the
> line, even if I try to step in. But see below for a variant in which it
> succeeds only if stepped into with the debugger.
>
> When I try to reproduce with a small example, using the value of Vs
> showing in the debugger just before the failure, everything works:
> weird(Names) :-
> Vs = [ nw(littleboy,now),
> nw(pdb,now),
> nw(pdb5,now),
> nw(dpath([lv(backup,littleboy)]),now),
> nw(path([oscorn1, usr, local, var, spool, bacula]),now),
> nw(lv(backup,littleboy),now)
> ],
> setof(Name, W^member(nw(Name, W), Vs), Names).
>
> Also, using
> setof(Name, cd1a(Vs, Name), Names),
>
> with the helper
> cd1a(Vs, Name) :-
> member(nw(Name, _), Vs).
>
> fails at the same spot if I step over ('s') setof. But if I trace into
> it (' '), the entire operation succeeds. Then the next u_plot fails.
>
> commenting out u_plot and pgraph did not help. Vs is not empty and
> consists entirely of nw(_,_) items according to the debugger.
>
> Running 6.4.1.
>
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>