[mercury-users] Problem with state variable

valery at freesurf.fr valery at freesurf.fr
Mon Jun 19 19:04:02 AEST 2006


Hello,

I have defined a range_foldl which is pretty much a for-loop

:- func range_foldl(func(int, T) = T, int, int, T) = T.
:- mode range_foldl(func(in, in) = out is det, in, in, in) = out is det.
:- mode range_foldl(func(in, di) = uo is det, in, in, di) = uo is det.
range_foldl(F, From, To, X) =
 (if From > To then X else range_foldl(F, From + 1, To, F(From, X))).

and used it to print a board line by line

main(!IO) :-
 N = 3,
 some [!B] (
  !:B = init(N*N, 0),
  !:B = (!.B ^ elem(1) := N),
  !:IO = range_foldl(func(J::in, !.IO::di) = (!:IO::uo) is det :-
   !:IO = range_foldl(func(I::in, !.IO::di) = (!:IO::uo) is det :-
    (io.format("%d\t", [i(!.B ^ elem(I + N * J))], !IO) % !! ERROR !!
    ,io.format("\n", [], !IO)),
   0, N - 1, !.IO),
  0, N - 1, !.IO)
 ).

but the compiler complains that !.B in not visible in the first io.format.
I also get a mode error there ; I hope it'll go away with the visibility
error.

What's wrong ?

-- Valery




--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list