For Programmers: Free Programming Magazines  


Home > Archive > Prolog > April 2004 > Metaprogramming question: transform assert+query to query+assert









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 Metaprogramming question: transform assert+query to query+assert
Daniel Speicher

2004-04-06, 2:37 pm


Hi all!

I'm thinking about a question, which should have been solved somewhere
out there. Up to now I wasn't able to find the whole answer. I'll state
my question by an simple example:

There is a predicate:

mypredicate(_a, _b) :- myfact(_a, _b), anotherfact(_a). (1)

Then
assert(myfact(1, 2)). (2)
followed by
mypredicate(_a, _b).

should give the same result as

mypredicate(_a, _b); _a=1,_b=2,anotherfact(1). (3)
and after
assert(myfact(1, 2)).

the fact base should be in the same state.

I generated (3) from (1) and (2). This was easy in this simple case. But
I wonder if there is a systematic way to do this. My final aim is to
have a transformation of a sequence of the form

{assert(..), query(..)}*

to a somehow equivalent sequence of the form

{modified-query(..)}*, {modified-assert(..)}*

I made some progress on this although the things become harder if
retraction of facts or recursive predicates are involved.
Can anybody answer this question or point me to some research work on
this topic. It would be even helpful to get to know the appropriate name
or keyword for this kind of question.

Thanks for any hint,
Daniel

Dave

2004-04-08, 6:37 pm

Hi!

I think you should look at something called partial
evaluation, as far as I see, that is what you need. It's
basically a preprocessing technique, where knowing certain
parameters a general program can be specialized to execute
faster.
For example if you have a code like
sum_three_lists(List1, List2, List3, Sum) :- sum(List1, S1), sum(List2, S2),
sum(List3, S3), Sum is S1+S2+S3.
With partial evalution if you have sum_three_lists([1,2,3,4],[5,6,7,8],
List, Sum)
somewhere in your code, it is automatically transformed to
Sum(List, S3), Sum is 36+S3.
Here is a little introduction:
http://compose.labri.fr/documentation/pe/

Dave

"Daniel Speicher" <dsp@iai.uni-bonn.de> wrote in message
news:c4up35$hdu$1@f1node01.rhrz.uni-bonn.de...
>
> Hi all!
>
> I'm thinking about a question, which should have been solved somewhere
> out there. Up to now I wasn't able to find the whole answer. I'll state
> my question by an simple example:
>
> There is a predicate:
>
> mypredicate(_a, _b) :- myfact(_a, _b), anotherfact(_a). (1)
>
> Then
> assert(myfact(1, 2)). (2)
> followed by
> mypredicate(_a, _b).
>
> should give the same result as
>
> mypredicate(_a, _b); _a=1,_b=2,anotherfact(1). (3)
> and after
> assert(myfact(1, 2)).
>
> the fact base should be in the same state.
>
> I generated (3) from (1) and (2). This was easy in this simple case. But
> I wonder if there is a systematic way to do this. My final aim is to
> have a transformation of a sequence of the form
>
> {assert(..), query(..)}*
>
> to a somehow equivalent sequence of the form
>
> {modified-query(..)}*, {modified-assert(..)}*
>
> I made some progress on this although the things become harder if
> retraction of facts or recursive predicates are involved.
> Can anybody answer this question or point me to some research work on
> this topic. It would be even helpful to get to know the appropriate name
> or keyword for this kind of question.
>
> Thanks for any hint,
> Daniel
>



Sponsored Links







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

Copyright 2008 codecomments.com