avoiding unwanted partial responses

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

avoiding unwanted partial responses

Ross Boylan
The code below attempts to generate a single set of Results with all its elements.
When run it instead gives multiple answers with a partially unresolved set; it seems to simply
increase the number of unknown elements each time.

First, I'd like to understand why it's behaving as it does.
Second, more importantly, what is the idiomatic way to achieve the result I want?

% -Results has all occurrence of multiple mounts with same device and path
% Results is a list, each element of which is m(Dev, Path)-Whens
% where Whens is a sorted list of mount times.
dup_mounts(Results):-
        findall(m(Dev, Path), (mount(Dev, Path, W1), mount(Dev, Path, W2), W1 \= W2), DupMounts0),
        list_to_ord_set(DupMounts0, DupMounts),
        dm1(DupMounts, Results).

dm1([], _Results).
dm1([m(Dev, Path) | Rest], Results) :-
            setof(When, mount(Dev, Path, When), Whens),
            member(m(Dev, Path)-Whens, Results),
            dm1(Rest, Results).

When run produces
?- dup_mounts(R).
R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], m(pdd5, oscorn1~/ms/ntfs)-[2006-2-6 #40, 2007-12-1 #110]|_G703] ;
R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702, m(pdd5, oscorn1~/ms/ntfs)-[2006-2-6 #40, 2007-12-1 #110]|_G706] ;
R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702, _G705, m(pdd5, oscorn1~/ms/ntfs)-[2006-2-6 #40, 2007-12-1 #110]|_G709] ;
R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702, _G705, _G708, m(pdd5, oscorn1~/ms/ntfs)-[2006-2-6 #40, 2007-12-1 #110]|_G712] ;
R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702, _G705, _G708, _G711, m(pdd5, oscorn1~/ms/ntfs)-[2006-2-6 #40, 2007-12-1 #110]|_G715] ;
R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702, _G705, _G708, _G711, _G714, m(pdd5, oscorn1~/ms/ntfs)-[2006-2-6 #40|...]|_G718] ;
R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702, _G705, _G708, _G711, _G714, _G717, m(..., ...)-[...|...]|_G721] ;
R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702, _G705, _G708, _G711, _G714, _G717, _G720, ... - ...|...] .
% I stopped it here because it wasn't getting more helpful.

I've accomplished similar things by having a list of partial results that gets appended to at each iteration, but I was hoping
for something more elegant.

BTW, printing out each solution like
m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120]
is in some ways better, but I'm also interested in getting the results into a structure I could work with further.

Ross Boylan

P.S.  Thanks, Richard, for answering my earlier question.  Should I file a bug report or tag the relevant pages in the online
manual?
_______________________________________________
SWI-Prolog mailing list
[hidden email]
https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: avoiding unwanted partial responses

Carlo Capelli-2
member(E,L) with unbound L it's the cause of those always longer lists. I
think you can simplify the code, maybe in this way

/* added for test

mount('Dev', 'Path', 'W1').

mount('Dev', 'Path', 'W2').

*/


dup_mounts(Results):-

  findall(m(Dev, Path), (mount(Dev, Path, W1), mount(Dev, Path, W2), W1 \=
W2), DupMounts0),

  list_to_ord_set(DupMounts0, DupMounts),

  maplist(dup_mount, DupMounts, Results).


dup_mount(m(Dev, Path), Whens) :-

  setof(When, mount(Dev, Path, When), Whens).






2014-08-26 4:54 GMT+02:00 Ross Boylan <[hidden email]>:

> The code below attempts to generate a single set of Results with all its
> elements.
> When run it instead gives multiple answers with a partially unresolved
> set; it seems to simply
> increase the number of unknown elements each time.
>
> First, I'd like to understand why it's behaving as it does.
> Second, more importantly, what is the idiomatic way to achieve the result
> I want?
>
> % -Results has all occurrence of multiple mounts with same device and path
> % Results is a list, each element of which is m(Dev, Path)-Whens
> % where Whens is a sorted list of mount times.
> dup_mounts(Results):-
>         findall(m(Dev, Path), (mount(Dev, Path, W1), mount(Dev, Path, W2),
> W1 \= W2), DupMounts0),
>         list_to_ord_set(DupMounts0, DupMounts),
>         dm1(DupMounts, Results).
>
> dm1([], _Results).
> dm1([m(Dev, Path) | Rest], Results) :-
>             setof(When, mount(Dev, Path, When), Whens),
>             member(m(Dev, Path)-Whens, Results),
>             dm1(Rest, Results).
>
> When run produces
> ?- dup_mounts(R).
> R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], m(pdd5,
> oscorn1~/ms/ntfs)-[2006-2-6 #40, 2007-12-1 #110]|_G703] ;
> R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702,
> m(pdd5, oscorn1~/ms/ntfs)-[2006-2-6 #40, 2007-12-1 #110]|_G706] ;
> R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702,
> _G705, m(pdd5, oscorn1~/ms/ntfs)-[2006-2-6 #40, 2007-12-1 #110]|_G709] ;
> R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702,
> _G705, _G708, m(pdd5, oscorn1~/ms/ntfs)-[2006-2-6 #40, 2007-12-1
> #110]|_G712] ;
> R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702,
> _G705, _G708, _G711, m(pdd5, oscorn1~/ms/ntfs)-[2006-2-6 #40, 2007-12-1
> #110]|_G715] ;
> R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702,
> _G705, _G708, _G711, _G714, m(pdd5, oscorn1~/ms/ntfs)-[2006-2-6
> #40|...]|_G718] ;
> R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702,
> _G705, _G708, _G711, _G714, _G717, m(..., ...)-[...|...]|_G721] ;
> R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702,
> _G705, _G708, _G711, _G714, _G717, _G720, ... - ...|...] .
> % I stopped it here because it wasn't getting more helpful.
>
> I've accomplished similar things by having a list of partial results that
> gets appended to at each iteration, but I was hoping
> for something more elegant.
>
> BTW, printing out each solution like
> m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120]
> is in some ways better, but I'm also interested in getting the results
> into a structure I could work with further.
>
> Ross Boylan
>
> P.S.  Thanks, Richard, for answering my earlier question.  Should I file a
> bug report or tag the relevant pages in the online
> manual?
> _______________________________________________
> SWI-Prolog mailing list
> [hidden email]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
-------------- next part --------------
HTML attachment scrubbed and removed
_______________________________________________
SWI-Prolog mailing list
[hidden email]
https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: avoiding unwanted partial responses

Ross Boylan
On Tue, Aug 26, 2014 at 07:52:37AM +0200, Carlo Capelli wrote:

> member(E,L) with unbound L it's the cause of those always longer lists. I
> think you can simplify the code, maybe in this way
>
> /* added for test
>
> mount('Dev', 'Path', 'W1').
>
> mount('Dev', 'Path', 'W2').
>
> */
>
>
> dup_mounts(Results):-
>
>   findall(m(Dev, Path), (mount(Dev, Path, W1), mount(Dev, Path, W2), W1 \=
> W2), DupMounts0),
>
>   list_to_ord_set(DupMounts0, DupMounts),
>
>   maplist(dup_mount, DupMounts, Results).
>
>
> dup_mount(m(Dev, Path), Whens) :-
>
>   setof(When, mount(Dev, Path, When), Whens).

Thanks; that worked great.

Apparently there were only 2 duplicates, and so if I had just stopped
with the first response from the old code I would have had the answer.

Ross

>
>
>
>
>
>
> 2014-08-26 4:54 GMT+02:00 Ross Boylan <[hidden email]>:
>
> > The code below attempts to generate a single set of Results with all its
> > elements.
> > When run it instead gives multiple answers with a partially unresolved
> > set; it seems to simply
> > increase the number of unknown elements each time.
> >
> > First, I'd like to understand why it's behaving as it does.
> > Second, more importantly, what is the idiomatic way to achieve the result
> > I want?
> >
> > % -Results has all occurrence of multiple mounts with same device and path
> > % Results is a list, each element of which is m(Dev, Path)-Whens
> > % where Whens is a sorted list of mount times.
> > dup_mounts(Results):-
> >         findall(m(Dev, Path), (mount(Dev, Path, W1), mount(Dev, Path, W2),
> > W1 \= W2), DupMounts0),
> >         list_to_ord_set(DupMounts0, DupMounts),
> >         dm1(DupMounts, Results).
> >
> > dm1([], _Results).
> > dm1([m(Dev, Path) | Rest], Results) :-
> >             setof(When, mount(Dev, Path, When), Whens),
> >             member(m(Dev, Path)-Whens, Results),
> >             dm1(Rest, Results).
> >
> > When run produces
> > ?- dup_mounts(R).
> > R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], m(pdd5,
> > oscorn1~/ms/ntfs)-[2006-2-6 #40, 2007-12-1 #110]|_G703] ;
> > R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702,
> > m(pdd5, oscorn1~/ms/ntfs)-[2006-2-6 #40, 2007-12-1 #110]|_G706] ;
> > R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702,
> > _G705, m(pdd5, oscorn1~/ms/ntfs)-[2006-2-6 #40, 2007-12-1 #110]|_G709] ;
> > R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702,
> > _G705, _G708, m(pdd5, oscorn1~/ms/ntfs)-[2006-2-6 #40, 2007-12-1
> > #110]|_G712] ;
> > R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702,
> > _G705, _G708, _G711, m(pdd5, oscorn1~/ms/ntfs)-[2006-2-6 #40, 2007-12-1
> > #110]|_G715] ;
> > R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702,
> > _G705, _G708, _G711, _G714, m(pdd5, oscorn1~/ms/ntfs)-[2006-2-6
> > #40|...]|_G718] ;
> > R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702,
> > _G705, _G708, _G711, _G714, _G717, m(..., ...)-[...|...]|_G721] ;
> > R = [m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120], _G702,
> > _G705, _G708, _G711, _G714, _G717, _G720, ... - ...|...] .
> > % I stopped it here because it wasn't getting more helpful.
> >
> > I've accomplished similar things by having a list of partial results that
> > gets appended to at each iteration, but I was hoping
> > for something more elegant.
> >
> > BTW, printing out each solution like
> > m(pdd1, oscorn1~/ms/win32)-[2006-2-6 #50, 2007-12-1 #120]
> > is in some ways better, but I'm also interested in getting the results
> > into a structure I could work with further.
> >
> > Ross Boylan
> >
> > P.S.  Thanks, Richard, for answering my earlier question.  Should I file a
> > bug report or tag the relevant pages in the online
> > manual?
> > _______________________________________________
> > SWI-Prolog mailing list
> > [hidden email]
> > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
> >
_______________________________________________
SWI-Prolog mailing list
[hidden email]
https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
Loading...