[m-rev.] for review: io__action_sequenceN

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri May 25 14:09:52 AEST 2001


For review by anyone.

library/io.m:
	Add some predicates that execute several I/O actions in a sequence.

Zoltan.

Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.224
diff -u -b -r1.224 io.m
--- library/io.m	2001/05/02 14:44:26	1.224
+++ library/io.m	2001/05/25 03:55:41
@@ -837,6 +837,163 @@
 
 %-----------------------------------------------------------------------------%
 
+% I/O "combinators".
+
+% Each of these predicates takes is inputs N I/O actions, and a predicate that
+% combines the results of these actions into a single result.
+%
+% They return ok if all the actions succeeded. They return error if an action
+% resulted in an error after the previous ones succeeded, and they return eof
+% if one of the actions found eof after the previous ones succeeded. In either
+% case, the inputs of those earlier successful actions have already been
+% consumed, but their results are not returned.
+
+:- pred io__action_sequence2(
+	pred(io__result(T1), io__state, io__state),
+	pred(io__result(T2), io__state, io__state),
+	pred(T1, T2, io__result(T)),
+	io__result(T), io__state, io__state).
+:- mode io__action_sequence2(
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(in, in, out) is det,
+	out, di, uo) is det.
+
+:- pred io__action_sequence3(
+	pred(io__result(T1), io__state, io__state),
+	pred(io__result(T2), io__state, io__state),
+	pred(io__result(T3), io__state, io__state),
+	pred(T1, T2, T3, io__result(T)),
+	io__result(T), io__state, io__state).
+:- mode io__action_sequence3(
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(in, in, in, out) is det,
+	out, di, uo) is det.
+
+:- pred io__action_sequence4(
+	pred(io__result(T1), io__state, io__state),
+	pred(io__result(T2), io__state, io__state),
+	pred(io__result(T3), io__state, io__state),
+	pred(io__result(T4), io__state, io__state),
+	pred(T1, T2, T3, T4, io__result(T)),
+	io__result(T), io__state, io__state).
+:- mode io__action_sequence4(
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(in, in, in, in, out) is det,
+	out, di, uo) is det.
+
+:- pred io__action_sequence5(
+	pred(io__result(T1), io__state, io__state),
+	pred(io__result(T2), io__state, io__state),
+	pred(io__result(T3), io__state, io__state),
+	pred(io__result(T4), io__state, io__state),
+	pred(io__result(T5), io__state, io__state),
+	pred(T1, T2, T3, T4, T5, io__result(T)),
+	io__result(T), io__state, io__state).
+:- mode io__action_sequence5(
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(in, in, in, in, in, out) is det,
+	out, di, uo) is det.
+
+:- pred io__action_sequence6(
+	pred(io__result(T1), io__state, io__state),
+	pred(io__result(T2), io__state, io__state),
+	pred(io__result(T3), io__state, io__state),
+	pred(io__result(T4), io__state, io__state),
+	pred(io__result(T5), io__state, io__state),
+	pred(io__result(T6), io__state, io__state),
+	pred(T1, T2, T3, T4, T5, T6, io__result(T)),
+	io__result(T), io__state, io__state).
+:- mode io__action_sequence6(
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(in, in, in, in, in, in, out) is det,
+	out, di, uo) is det.
+
+:- pred io__action_sequence7(
+	pred(io__result(T1), io__state, io__state),
+	pred(io__result(T2), io__state, io__state),
+	pred(io__result(T3), io__state, io__state),
+	pred(io__result(T4), io__state, io__state),
+	pred(io__result(T5), io__state, io__state),
+	pred(io__result(T6), io__state, io__state),
+	pred(io__result(T7), io__state, io__state),
+	pred(T1, T2, T3, T4, T5, T6, T7, io__result(T)),
+	io__result(T), io__state, io__state).
+:- mode io__action_sequence7(
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(in, in, in, in, in, in, in, out) is det,
+	out, di, uo) is det.
+
+:- pred io__action_sequence8(
+	pred(io__result(T1), io__state, io__state),
+	pred(io__result(T2), io__state, io__state),
+	pred(io__result(T3), io__state, io__state),
+	pred(io__result(T4), io__state, io__state),
+	pred(io__result(T5), io__state, io__state),
+	pred(io__result(T6), io__state, io__state),
+	pred(io__result(T7), io__state, io__state),
+	pred(io__result(T8), io__state, io__state),
+	pred(T1, T2, T3, T4, T5, T6, T7, T8, io__result(T)),
+	io__result(T), io__state, io__state).
+:- mode io__action_sequence8(
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(in, in, in, in, in, in, in, in, out) is det,
+	out, di, uo) is det.
+
+:- pred io__action_sequence9(
+	pred(io__result(T1), io__state, io__state),
+	pred(io__result(T2), io__state, io__state),
+	pred(io__result(T3), io__state, io__state),
+	pred(io__result(T4), io__state, io__state),
+	pred(io__result(T5), io__state, io__state),
+	pred(io__result(T6), io__state, io__state),
+	pred(io__result(T7), io__state, io__state),
+	pred(io__result(T8), io__state, io__state),
+	pred(io__result(T9), io__state, io__state),
+	pred(T1, T2, T3, T4, T5, T6, T7, T8, T9, io__result(T)),
+	io__result(T), io__state, io__state).
+:- mode io__action_sequence9(
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(out, di, uo) is det,
+	pred(in, in, in, in, in, in, in, in, in, out) is det,
+	out, di, uo) is det.
+
+%-----------------------------------------------------------------------------%
+
 % Global state predicates.
 
 :- pred io__progname(string, string, io__state, io__state).
@@ -4385,6 +4542,478 @@
 	mercury_close(mf);
 	update_io(IO0, IO);
 ").
+
+/* I/O "combinators" */
+
+io__action_sequence2(P1, P2, Combine, Res) -->
+	call(P1, Res1),
+	(
+		{ Res1 = ok(T1) },
+		call(P2, Res2),
+		(
+			{ Res2 = ok(T2) },
+			{ call(Combine, T1, T2, Res) }
+		;
+			{ Res2 = eof },
+			{ Res = eof }
+		;
+			{ Res2 = error(Err) },
+			{ Res = error(Err) }
+		)
+	;
+		{ Res1 = eof },
+		{ Res = eof }
+	;
+		{ Res1 = error(Err) },
+		{ Res = error(Err) }
+	).
+
+io__action_sequence3(P1, P2, P3, Combine, Res) -->
+	call(P1, Res1),
+	(
+		{ Res1 = ok(T1) },
+		call(P2, Res2),
+		(
+			{ Res2 = ok(T2) },
+			call(P3, Res3),
+			(
+				{ Res3 = ok(T3) },
+				{ call(Combine, T1, T2, T3, Res) }
+			;
+				{ Res3 = eof },
+				{ Res = eof }
+			;
+				{ Res3 = error(Err) },
+				{ Res = error(Err) }
+			)
+		;
+			{ Res2 = eof },
+			{ Res = eof }
+		;
+			{ Res2 = error(Err) },
+			{ Res = error(Err) }
+		)
+	;
+		{ Res1 = eof },
+		{ Res = eof }
+	;
+		{ Res1 = error(Err) },
+		{ Res = error(Err) }
+	).
+
+io__action_sequence4(P1, P2, P3, P4, Combine, Res) -->
+	call(P1, Res1),
+	(
+		{ Res1 = ok(T1) },
+		call(P2, Res2),
+		(
+			{ Res2 = ok(T2) },
+			call(P3, Res3),
+			(
+				{ Res3 = ok(T3) },
+				call(P4, Res4),
+				(
+					{ Res4 = ok(T4) },
+					{ call(Combine, T1, T2, T3, T4, Res) }
+				;
+					{ Res4 = eof },
+					{ Res = eof }
+				;
+					{ Res4 = error(Err) },
+					{ Res = error(Err) }
+				)
+			;
+				{ Res3 = eof },
+				{ Res = eof }
+			;
+				{ Res3 = error(Err) },
+				{ Res = error(Err) }
+			)
+		;
+			{ Res2 = eof },
+			{ Res = eof }
+		;
+			{ Res2 = error(Err) },
+			{ Res = error(Err) }
+		)
+	;
+		{ Res1 = eof },
+		{ Res = eof }
+	;
+		{ Res1 = error(Err) },
+		{ Res = error(Err) }
+	).
+
+io__action_sequence5(P1, P2, P3, P4, P5, Combine, Res) -->
+	call(P1, Res1),
+	(
+		{ Res1 = ok(T1) },
+		call(P2, Res2),
+		(
+			{ Res2 = ok(T2) },
+			call(P3, Res3),
+			(
+				{ Res3 = ok(T3) },
+				call(P4, Res4),
+				(
+					{ Res4 = ok(T4) },
+					call(P5, Res5),
+					(
+						{ Res5 = ok(T5) },
+						{ call(Combine, T1, T2, T3, T4,
+							T5, Res) }
+					;
+						{ Res5 = eof },
+						{ Res = eof }
+					;
+						{ Res5 = error(Err) },
+						{ Res = error(Err) }
+					)
+				;
+					{ Res4 = eof },
+					{ Res = eof }
+				;
+					{ Res4 = error(Err) },
+					{ Res = error(Err) }
+				)
+			;
+				{ Res3 = eof },
+				{ Res = eof }
+			;
+				{ Res3 = error(Err) },
+				{ Res = error(Err) }
+			)
+		;
+			{ Res2 = eof },
+			{ Res = eof }
+		;
+			{ Res2 = error(Err) },
+			{ Res = error(Err) }
+		)
+	;
+		{ Res1 = eof },
+		{ Res = eof }
+	;
+		{ Res1 = error(Err) },
+		{ Res = error(Err) }
+	).
+
+io__action_sequence6(P1, P2, P3, P4, P5, P6, Combine, Res) -->
+	call(P1, Res1),
+	(
+		{ Res1 = ok(T1) },
+		call(P2, Res2),
+		(
+			{ Res2 = ok(T2) },
+			call(P3, Res3),
+			(
+				{ Res3 = ok(T3) },
+				call(P4, Res4),
+				(
+					{ Res4 = ok(T4) },
+					call(P5, Res5),
+					(
+						{ Res5 = ok(T5) },
+						call(P6, Res6),
+						(
+							{ Res6 = ok(T6) },
+							{ call(Combine, T1, T2,
+								T3, T4, T5,
+								T6, Res) }
+						;
+							{ Res6 = eof },
+							{ Res = eof }
+						;
+							{ Res6 = error(Err) },
+							{ Res = error(Err) }
+						)
+					;
+						{ Res5 = eof },
+						{ Res = eof }
+					;
+						{ Res5 = error(Err) },
+						{ Res = error(Err) }
+					)
+				;
+					{ Res4 = eof },
+					{ Res = eof }
+				;
+					{ Res4 = error(Err) },
+					{ Res = error(Err) }
+				)
+			;
+				{ Res3 = eof },
+				{ Res = eof }
+			;
+				{ Res3 = error(Err) },
+				{ Res = error(Err) }
+			)
+		;
+			{ Res2 = eof },
+			{ Res = eof }
+		;
+			{ Res2 = error(Err) },
+			{ Res = error(Err) }
+		)
+	;
+		{ Res1 = eof },
+		{ Res = eof }
+	;
+		{ Res1 = error(Err) },
+		{ Res = error(Err) }
+	).
+
+io__action_sequence7(P1, P2, P3, P4, P5, P6, P7, Combine, Res) -->
+	call(P1, Res1),
+	(
+	    { Res1 = ok(T1) },
+	    call(P2, Res2),
+	    (
+	        { Res2 = ok(T2) },
+	        call(P3, Res3),
+	        (
+	            { Res3 = ok(T3) },
+	            call(P4, Res4),
+	            (
+	                { Res4 = ok(T4) },
+	                call(P5, Res5),
+	                (
+	                    { Res5 = ok(T5) },
+	                    call(P6, Res6),
+	                    (
+	                        { Res6 = ok(T6) },
+	                        call(P7, Res7),
+	                        (
+	                            { Res7 = ok(T7) },
+	                            { call(Combine, T1, T2, T3, T4, T5, T6, T7,
+	                                Res) }
+	                        ;
+	                            { Res7 = eof },
+	                            { Res = eof }
+	                        ;
+	                            { Res7 = error(Err) },
+	                            { Res = error(Err) }
+	                        )
+	                    ;
+	                        { Res6 = eof },
+	                        { Res = eof }
+	                    ;
+	                        { Res6 = error(Err) },
+	                        { Res = error(Err) }
+	                    )
+	                ;
+	                    { Res5 = eof },
+	                    { Res = eof }
+	                ;
+	                    { Res5 = error(Err) },
+	                    { Res = error(Err) }
+	                )
+	            ;
+	                { Res4 = eof },
+	                { Res = eof }
+	            ;
+	                { Res4 = error(Err) },
+	                { Res = error(Err) }
+	            )
+	        ;
+	            { Res3 = eof },
+	            { Res = eof }
+	        ;
+	            { Res3 = error(Err) },
+	            { Res = error(Err) }
+	        )
+	    ;
+	        { Res2 = eof },
+	        { Res = eof }
+	    ;
+	        { Res2 = error(Err) },
+	        { Res = error(Err) }
+	    )
+	;
+	    { Res1 = eof },
+	    { Res = eof }
+	;
+	    { Res1 = error(Err) },
+	    { Res = error(Err) }
+	).
+
+io__action_sequence8(P1, P2, P3, P4, P5, P6, P7, P8, Combine, Res) -->
+	call(P1, Res1),
+	(
+	    { Res1 = ok(T1) },
+	    call(P2, Res2),
+	    (
+	        { Res2 = ok(T2) },
+	        call(P3, Res3),
+	        (
+	            { Res3 = ok(T3) },
+	            call(P4, Res4),
+	            (
+	                { Res4 = ok(T4) },
+	                call(P5, Res5),
+	                (
+	                    { Res5 = ok(T5) },
+	                    call(P6, Res6),
+	                    (
+	                        { Res6 = ok(T6) },
+	                        call(P7, Res7),
+	                        (
+	                            { Res7 = ok(T7) },
+	                            call(P8, Res8),
+	                            (
+	                                { Res8 = ok(T8) },
+	                                { call(Combine, T1, T2, T3, T4, T5, T6,
+	                                    T7, T8, Res) }
+	                            ;
+	                                { Res8 = eof },
+	                                { Res = eof }
+	                            ;
+	                                { Res8 = error(Err) },
+	                                { Res = error(Err) }
+	                            )
+	                        ;
+	                            { Res7 = eof },
+	                            { Res = eof }
+	                        ;
+	                            { Res7 = error(Err) },
+	                            { Res = error(Err) }
+	                        )
+	                    ;
+	                        { Res6 = eof },
+	                        { Res = eof }
+	                    ;
+	                        { Res6 = error(Err) },
+	                        { Res = error(Err) }
+	                    )
+	                ;
+	                    { Res5 = eof },
+	                    { Res = eof }
+	                ;
+	                    { Res5 = error(Err) },
+	                    { Res = error(Err) }
+	                )
+	            ;
+	                { Res4 = eof },
+	                { Res = eof }
+	            ;
+	                { Res4 = error(Err) },
+	                { Res = error(Err) }
+	            )
+	        ;
+	            { Res3 = eof },
+	            { Res = eof }
+	        ;
+	            { Res3 = error(Err) },
+	            { Res = error(Err) }
+	        )
+	    ;
+	        { Res2 = eof },
+	        { Res = eof }
+	    ;
+	        { Res2 = error(Err) },
+	        { Res = error(Err) }
+	    )
+	;
+	    { Res1 = eof },
+	    { Res = eof }
+	;
+	    { Res1 = error(Err) },
+	    { Res = error(Err) }
+	).
+
+io__action_sequence9(P1, P2, P3, P4, P5, P6, P7, P8, P9, Combine, Res) -->
+	call(P1, Res1),
+	(
+	    { Res1 = ok(T1) },
+	    call(P2, Res2),
+	    (
+	        { Res2 = ok(T2) },
+	        call(P3, Res3),
+	        (
+	            { Res3 = ok(T3) },
+	            call(P4, Res4),
+	            (
+	                { Res4 = ok(T4) },
+	                call(P5, Res5),
+	                (
+	                    { Res5 = ok(T5) },
+	                    call(P6, Res6),
+	                    (
+	                        { Res6 = ok(T6) },
+	                        call(P7, Res7),
+	                        (
+	                            { Res7 = ok(T7) },
+	                            call(P8, Res8),
+	                            (
+	                                { Res8 = ok(T8) },
+	                                call(P9, Res9),
+	                                (
+	                                    { Res9 = ok(T9) },
+	                                    { call(Combine, T1, T2, T3, T4, T5,
+	                                        T6, T7, T8, T9, Res) }
+	                                ;
+	                                    { Res9 = eof },
+	                                    { Res = eof }
+	                                ;
+	                                    { Res9 = error(Err) },
+	                                    { Res = error(Err) }
+	                                )
+	                            ;
+	                                { Res8 = eof },
+	                                { Res = eof }
+	                            ;
+	                                { Res8 = error(Err) },
+	                                { Res = error(Err) }
+	                            )
+	                        ;
+	                            { Res7 = eof },
+	                            { Res = eof }
+	                        ;
+	                            { Res7 = error(Err) },
+	                            { Res = error(Err) }
+	                        )
+	                    ;
+	                        { Res6 = eof },
+	                        { Res = eof }
+	                    ;
+	                        { Res6 = error(Err) },
+	                        { Res = error(Err) }
+	                    )
+	                ;
+	                    { Res5 = eof },
+	                    { Res = eof }
+	                ;
+	                    { Res5 = error(Err) },
+	                    { Res = error(Err) }
+	                )
+	            ;
+	                { Res4 = eof },
+	                { Res = eof }
+	            ;
+	                { Res4 = error(Err) },
+	                { Res = error(Err) }
+	            )
+	        ;
+	            { Res3 = eof },
+	            { Res = eof }
+	        ;
+	            { Res3 = error(Err) },
+	            { Res = error(Err) }
+	        )
+	    ;
+	        { Res2 = eof },
+	        { Res = eof }
+	    ;
+	        { Res2 = error(Err) },
+	        { Res = error(Err) }
+	    )
+	;
+	    { Res1 = eof },
+	    { Res = eof }
+	;
+	    { Res1 = error(Err) },
+	    { Res = error(Err) }
+	).
 
 /* miscellaneous predicates */
 
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list