[mercury-users] io__write_list

Nancy Mazur Nancy.Mazur at cs.kuleuven.ac.be
Thu Nov 7 19:33:23 AEDT 2002


* Noel  Pinto <cool4life at rediffmail.com> [2002-11-07 09:25]:
> >:- pred io__write_list(io__output_stream, list(T), string,
> >	pred(T, io__state, io__state), io__state, io__state).
> >:- mode io__write_list(in, in, in, pred(in, di, uo) is det, di, 
> >uo)
> >	is det.
> >:- mode io__write_list(in, in, in, pred(in, di, uo) is cc_multi, 
> >di, uo)
> >	is cc_multi.
> >	% io__write_list(Stream, List, Separator, OutputPred, IO0, 
> >IO)
> >	% applies OutputPred to each element of List, printing 
> >Separator
> >	% between each element. Outputs to Stream.
> >
> >From the pred and mode declaration you should, by now, be able 
> >to deduce
> >that "OutputPred" is supposed to be a "pred(T, io__state, 
> >io__state)",
> >with modes "pred(in, di, uo)"...
> 
> In my original question, what I meant was, What is passed to 
> OutputPred??

Nothing ;-) 

example: 

:- type silly_type ---> number(int); couple(int,int).
:- pred print_silly_type(silly_type, io__state, io__state). 
:- mode print_silly_type(in, di, uo). 

print_silly_type(MyType) --> 
	% with some implementation here for printing an individual	
	% item of type "silly_type"... 

Within some other predicate in which you have built up a list of
silly_type items, say MySillyTypeList, you can now use io__write_list as
follows: 
	... 
	io__write_list(Stream, MySillyTypeList, "\n", print_silly_type), 
	... 

	
> All the arguments have modes with in and none for out. OutputPred 
> has mode for in, di and uo. So, what exaclty has to be supplied to 
> OutputPred so that it applies to each element of the List, 
> printing Separator between each element???

So you don't supply anything to the OutputPred-thing.. it's just the
predicate that io__write_list will use to print individual items of your
list. 

> Why is it that the argument has the alphabet T mentioned in such 
> cases and not any other alphabet for arguments such A, B .

because io__write_list is declared for a list of elements of type T. 
This type is instantiated at the moment where io__write_list will be
used, in our case "silly_type".. 
It's perfectly logical: if you want to write out a list of type T stuff,
you need to provide a predicate which explains how to print single items
of this type T thingy. 

Have fun, 
Nancy
--------------------------------------------------------------------------
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