[eclipse-users] Storing a context

From: VicenÁ <vgomez_at_iua.upf.edu>
Date: Thu, 24 May 2007 09:38:02 +0200
Hello,

I was wondering what is the best method to store a "context" during the
execution of a Prolog program. For instance, suppose I have the
following rule:

main(Cost) :-
    color(Color), size(Size), ...,
    cost(Cost).

and predicate *cost* uses the value of *color* and *size*, for instance:

cost(C) :- color(green), size(Size), C is Size*2.
cost(C) :- color(black), size(Size), C is Size/2.
...

My current solution is to parse the original rules creating predicates
with two more arguments which are an input list and an output list. For
instance, this would be my parsed code:

main(C, L, L) :- member(main(C), L).
main(C, L, [main(C)|LN]) :- not member(main(_), L),
    color(Color, L, L1),
    size(Size, L2, L3),
    ...
    cost(C, LM, LN).

and:

cost(C, L, L) :- member(cost(C), L).
cost(C, L, [C|L2]) :- not member(cost(_), L),
    color(green, L, L1),
    size(Size, L1, L2),
    C is Size*2.
cost(C, L, [C|L2]) :- not member(cost(_), L),
    color(black, L, L1),
    size(Size, L1, L2),
    C is Size/2.

As you can see, there exists a "context" (the input/output lists) where 
the different values for the different vales are being added (color, 
size, cost, ...) and replaced properly after backtracks.

My goal is to use as a context all (uninstantiated) variables which 
domains will be constrained during the execution of the program. The 
number of variables is large, which prevents passing all of them as 
different arguments in all the predicates.

Obviously, this does not seem the best solution so far. Another (more
elegant) would be to use asserts/retracts but I found that very 
inefficient...

Hope it is clear, thanks in advance...



    VicenÁ
Received on Thu May 24 2007 - 08:38:12 CEST

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET