[eclipse-users] Storing a context

From: Vicenç <vgomez_at_...58...>
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.3.0 : Wed Sep 25 2024 - 15:13:20 CEST