Re: [eclipse-users] Storing a context

From: Joachim Schimpf (Independent Contractor) <"Joachim>
Date: Thu, 24 May 2007 10:22:01 +0100
Vicenç wrote:
> 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.
> ...


Remember that you are using a logic programming language, and think about
the declarative meaning of your code.  A predicate is something that is
true or false.  So what is the meaning of cost(C)?  It means
"cost(C) is true iff C is a cost" or in other words "C is a cost".
But the cost of what?  You see it makes no sense declaratively.

What you probably want it a predicate like cost(Color,Size,Cost), which
means "Cost is the cost of something with color Color and size Size",
and it could be defined as

cost(green, Size, Cost) :- Cost is Size*2.
cost(black, Size, Cost) :- Cost is Size/2.
...


-- Joachim
Received on Thu May 24 2007 - 10:22:16 CEST

This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:20 CEST