Re: [eclipse-clp-users] About operations over Lists, search space function and something about indicators

From: Kish Shen <kisshen_at_cisco.com>
Date: Thu, 09 Oct 2008 20:23:57 +0100
Hi,

(it looks like I forgot to send this reply to the mailing list 
originally...)

Danilo Santander wrote:
 > Hello everyone, i've a problem with list... i need change a specific 
value on list, for example,
 >
 > X=[5,4,3,2,1]... how can i change the 2nd value (4) for another one 
(7) whitout change any more over list?.
 >
 > NewX=[5,7,3,2,1]

What you want to do suggest that lists are not the data structure you 
want to use. This is not specific to ECLiPSe, but applies to Prolog in 
general -- lists are best used when you do not know the number of data 
elements you need (and/or if your data can grow dynamically), *and* you 
do not want random access to the data (e.g. if you need to process all 
the data).

If you know the size of your data (e.g. 5 in your example), and you want 
to access the data randomly (e.g. the 2nd value in your example), you 
should use structures (which is what ECLiPSe arrays maps to).

Secondly, Prolog is a declarative language, and variables are like 
variables in mathematics, so wanting 'to change a specific value' does 
not really make sense. Often, this suggest you are not approaching the 
problem in the right way. If you really need to do this, and want to 
stay logical, you would need to make a copy of your data structure, and 
replacing the element you want to change.

ECLiPSe does provide a `non-logical' way to change the value of an 
element in a data structure -- setarg/3, but you should avoid this if at 
all possible -- it can have surprising side effects if you are not sure 
of what you are doing.

 > 
-------------------------------------------------------------------------------------
 > about search space... is this function
 >
 > search_space(Vars, Size) :-
 >     ( foreach(V,Vars), fromto(1,S0,S1,Size) do
 >         S1 is S0*get_domain_size(V)
 >     ).
 >  correct to get the search space?, i saw another one like this
 >
 > search_space(Vars, Size) :-
 >     ( foreach(V,Vars), fromto(1,S0,S1,Size) do
 >         get_domain(V,D),
 >         S1 is S0*get_domain_size(D)
 >     ).
 >
 > but i get errors on get_domain_size (/type error/)...
 > 
-------------------------------------------------------------------------------------
 > and last... wich indicators do you think are more important or 
relevant when i get a snapshot?
 >
 > i was thinking about backtracks, search space... but need more 'cos 
this are not enought for my investigation.
 >
 > thanks a lot.
 >
 >
 >
 > -------------------------------------------------------------------------
 > This SF.Net email is sponsored by the Moblin Your Move Developer's 
challenge
 > Build the coolest Linux based applications with Moblin SDK & win 
great prizes
 > Grand prize is a trip for two to an Open Source event anywhere in the 
world
 > http://moblin-contest.org/redirect.php?banner_id=100&url=/
 > _______________________________________________
 > ECLiPSe-CLP-Users mailing list
 > ECLiPSe-CLP-Users_at_lists.sourceforge.net
 > https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users


-- 
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 Thu Oct 09 2008 - 19:24:51 CEST

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