For Programmers: Free Programming Magazines  


Home > Archive > Prolog > September 2006 > forall implementation









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author forall implementation
Carlo Capelli

2006-09-14, 7:01 pm

I found the following code in SWI-Prolog:

forall(A, B) :-
\+((
A,
\+B
)).

Very nice, and the predicate is worth to use, but PSharp can't compile it (I
think it goes into loop, having seen the memory footprint...).
I renamed the predicate in the following way, because PSharp use forall in
LLP context,

runall(A, B) :-
\+((
call(A),
\+B
)).

but it doesn't work.
My simple minded replacement obviously doesn't work:

runall(A, B) :-
repeat,
runall_(A, B).
runall_(A, B) :-
call(A),
call(B),
fail.
runall_(_, _).

Someone could help?
Many thanks to all.

Bye Carlo


bart demoen

2006-09-14, 7:01 pm

On Thu, 14 Sep 2006 19:26:24 +0200, Carlo Capelli wrote:

> I found the following code in SWI-Prolog:
>
> forall(A, B) :-
> \+((
> A,
> \+B
> )).
>
> Very nice, and the predicate is worth to use, but PSharp can't compile it (I
> think it goes into loop, having seen the memory footprint...).
> I renamed the predicate in the following way, because PSharp use forall in
> LLP context,
>
> runall(A, B) :-
> \+((
> call(A),
> \+B
> )).
>
> but it doesn't work.



It is not clear what you are asking: there seems to be a bug in PSharp
and you want us to find a way around it ? You should ask Jon Cook directly
about bugs in P#.


> My simple minded replacement obviously doesn't work:
>
> runall(A, B) :-
> repeat,
> runall_(A, B).
> runall_(A, B) :-
> call(A),
> call(B),
> fail.
> runall_(_, _).


Sure, your replacement obviously does not work. What do you expect ?
Prolog code that circumvents the P# bug ?
Maybe the following will work: since we know that \+ can be implemented
by

\+(G) :- call(G), !, fail.
\+(_).

try expanding (or inlining, or unfolding) this definition in the original
def of forall.
Show us what you get :-)

Cheers

Bart Demoen
Carlo Capelli

2006-09-15, 4:01 am


"bart demoen" <bmd@cs.kuleuven.be> ha scritto nel messaggio
news:pan.2006.09.14.21.10.21.516318@cs.kuleuven.be...
> On Thu, 14 Sep 2006 19:26:24 +0200, Carlo Capelli wrote:
>
it (I[color=darkred]
in[color=darkred]
>
>
> It is not clear what you are asking: there seems to be a bug in PSharp
> and you want us to find a way around it ? You should ask Jon Cook directly
> about bugs in P#.
>
>
>
> Sure, your replacement obviously does not work. What do you expect ?
> Prolog code that circumvents the P# bug ?
> Maybe the following will work: since we know that \+ can be implemented
> by
>
> \+(G) :- call(G), !, fail.
> \+(_).
>
> try expanding (or inlining, or unfolding) this definition in the original
> def of forall.
> Show us what you get :-)
>
> Cheers
>
> Bart Demoen


Many thanks Bart, I will try...

In the meanwhile, I think a possible solution could be

runall(A,B) :- findall((A,B), call((A,B)), _).

that seems to work.

Bye Carlo


Carlo Capelli

2006-09-15, 4:01 am


"bart demoen" <bmd@cs.kuleuven.be> ha scritto nel messaggio
news:pan.2006.09.14.21.10.21.516318@cs.kuleuven.be...
> On Thu, 14 Sep 2006 19:26:24 +0200, Carlo Capelli wrote:
>
it (I[color=darkred]
in[color=darkred]
>
>
> It is not clear what you are asking: there seems to be a bug in PSharp
> and you want us to find a way around it ? You should ask Jon Cook directly
> about bugs in P#.
>
>
>
> Sure, your replacement obviously does not work. What do you expect ?
> Prolog code that circumvents the P# bug ?
> Maybe the following will work: since we know that \+ can be implemented
> by
>
> \+(G) :- call(G), !, fail.
> \+(_).
>
> try expanding (or inlining, or unfolding) this definition in the original
> def of forall.
> Show us what you get :-)
>
> Cheers
>
> Bart Demoen


Many thanks again.
Your suggestion works fine! Here the code:

runall(A, B) :-
not_((
call(A),
not_(B)
)).
not_(G) :- call(G), !, fail.
not_(_).

Bye Carlo


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com