Error Message
Author Message
Error Message

Can anyone explain this?

{DOMAIN ERROR: _57 is 9+calc_route_cost([[3,3],[5,7],[9,9]],_52) - arg 2:
expected expression, found calc_route_cost([[3,3],[5,7],[9,9]],_52)}
{trace}

from this code;

calc_cost([X1|Y1],[X1|Y1],0).
calc_cost([X1|Y1],[X2|Y2],Ans) :-
Ans is 1 + (X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1).

calc_route_cost([],0).

calc_route_cost([H|T],Ans):-
length([H|T],2),
flatten(T,T2),
calc_cost(H,T2,Ans).

calc_route_cost([H1,H2|T],Ans) :-
calc_cost(H1,H2,Sub_ans),
Ans is Sub_ans + calc_route_cost([H2|T],Z).

thanks

geoff

Fri, 09 May 2003 03:00:00 GMT
Error Message

Quote:

> Can anyone explain this?

> {DOMAIN ERROR: _57 is 9+calc_route_cost([[3,3],[5,7],[9,9]],_52) - arg 2:
> expected expression, found calc_route_cost([[3,3],[5,7],[9,9]],_52)}
> {trace}

It says it (arg2) is not a number nor a evaluable expression (see at bottom).

Quote:
> from this code;

> calc_cost([X1|Y1],[X1|Y1],0).
> calc_cost([X1|Y1],[X2|Y2],Ans) :-
>  Ans is 1 + (X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1).

> calc_route_cost([],0).

> calc_route_cost([H|T],Ans):-
>  length([H|T],2),
>  flatten(T,T2),
>  calc_cost(H,T2,Ans).

> calc_route_cost([H1,H2|T],Ans) :-
>  calc_cost(H1,H2,Sub_ans),
>  Ans is Sub_ans + calc_route_cost([H2|T],Z).

As prolog is not a functionnal language, you must rewrite the
previous rule to this:

calc_route_cost([H1,H2|T],Ans) :-
calc_cost(H1,H2,Sub_ans),
calc_route_cost([H2|T],Z)
Ans is Sub_ans + Z.

HTH
--
Pascal

Fri, 09 May 2003 03:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages