Yahya Mowiena wrote: > Dear Eclipse-Prolog users > > I am having a problem of getting a variable value out of the foreach loop > here's my code > > (foreach(city_windArea{number_built: Ni}, WindACVars) do > (foreach(Ni, List), param(Ni,List,Sum) do true), > sum1(List, Sum) > > ). I assume you have a list of city_windArea structures, and you want to make a list of their number_built fields. You do that using a single loop with 2 foreachs. After the loop, you can use the new list: ( foreach(city_windArea{number_built: Ni}, WindACVars), foreach(Ni, List) do true ), % now we are ready to use List > > %Cost $= 2000000 * Sum. > > > > sum1(List, Sum):- > (foreach(X,List), > fromto(0, In, Out, Sum) do > Out $= In + X > ). You don't need the sum1 auxiliary. Just write directly Cost $= 2000000 * sum(List). > > I want to retrieve the sum calculated in the foreach loop to calculate > the cost but when I uncomment the cost function, an error appears > > any help is highly appreciated > > Thanks a lot > Best Regards > > mowiena_at_gmail.com <mailto:mowiena_at_gmail.com> > > -- > Yahya MowienaReceived on Mon Jun 08 2009 - 05:48:19 CEST
This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET