[mercury-users] Problem with state variable

valery at freesurf.fr valery at freesurf.fr
Tue Jun 20 20:01:54 AEST 2006


> BTW, I think that above program would be written more idiomatically in
> Mercury as:
>
> 	main(!IO) :-
> 	     N = 3,
> 	     some [!B] (
> 		 !:B = init(N * N, 0),
> 		 set(1, N, !B),
> 		 Tmp = !.B,
> 		 PrintCol = (pred(J::in, !.IO::di, !:IO::uo) is det :-
> 		    PrintRow = (pred(I::in, !.IO::di, !:IO::uo) is det :-
> 			io.format("%d\t", [i(Tmp ^ elem(I + N * J))], !IO)
> 		    ),
> 		    int.fold_up(PrintRow, 0, N - 1, !IO),
> 		    io.nl(!IO)
> 		),
> 		int.fold_up(PrintCol, 0, N - 1, !IO)
> 	    ).

It works. Thanks for the nice piece of code.

As far a lambda expressions are concerned, I don't understand why local
predicates are not allowed, since naming a variable pointing to an
anonymous predicate like above is the same, except that it is more
convoluted and AFAIK there is no way to declare the type of arguments.
BTW, the examples in section 2.13.5 of the reference manual have typos
("is Det" instead of "is det") ; this should be fixed because the
resulting error message is quite puzzling for a newcomer ;)

-- 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