Re: [eclipse-clp-users] Resume - permanent variables

From: Kish Shen <kisshen_at_...5...>
Date: Fri, 13 Feb 2009 21:55:01 +0000
Hi Giuseppe,


Giuseppe Di Guglielmo wrote:
> Dear all,
> please consider the following file:
> ---
> % clp_utils.ecl
> 
> :- lib(ic).
> :- lib(ic_search).
> 
> % integer type
> % X is the identifier
> % L is the left bound
> % R is the right bound
> integer_t(X,L,R) :- X :: L .. R.
> 
> constraint_1 :- integer_t(VAR1,0,127), (VAR1 #= 0).
> ---
> 
> I compile it in ECLiPSe and I execute the predicate 'constraint_1'. In the
> following I'd like to look at the result in VAR1:
> 
> $ eclipse 
> ...
> [eclipse 1]: [clp_utils].
> ...
> clp_utils.ecl compiled 1504 bytes in 0.09 seconds
> 
> Yes (0.23s cpu)
> [eclipse 2]: constraint_1.
> 
> Yes (0.00s cpu)
> [eclipse 3]: writeln(VAR1).
> VAR1
> 
> VAR1 = VAR1
> Yes (0.00s cpu)
> 
> If I write the predicate as: 
> constraint_2 :- integer_t(VAR1,0,127), (VAR1 #= 0), writeln(VAR1).
> 
> [eclipse 4]: constraint_2.
> 0
> 
> Yes (0.00s cpu)
> 
> The output is correct 0. 
> 
> How can I create "permanent variables" between each resume?

By between each resume I guess you mean between each query. It is not 
possible to perserve any logical variable state between queries. Each
execution of a query is independent of other queries (you can think of 
it as backtracking is done after each query).

It is possible to create non-logical storage that will store some value
that is perserved through backtracking, but these are not logical, and 
any unbound variables are copied and become independent of the original 
variable, and it may not always be possible to copy everything if the 
variable has attributes.

If you need to interact with the user (or another program) during the 
execution of your query, you should use ECLiPSe's I/O facilities, rather 
than returning to the toplevel.

Cheers,

Kish

-- 
This e-mail may contain confidential and privileged material for the
sole use of the intended recipient. Any review, use, distribution or
disclosure by others is strictly prohibited. If you are not the intended
recipient (or authorized to receive for the recipient), please contact
the sender by reply e-mail and delete all copies of this message.
Cisco Systems Limited (Company Number: 02558939), is registered in
England and Wales with its registered office at 1 Callaghan Square,
Cardiff, South Glamorgan CF10 5BT.
Received on Fri Feb 13 2009 - 23:02:47 CET

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:29 CEST