In io.write_list(List(integer), ",", OutputPred, !IO), what is OutputPred? I'm trying to display a list of type integer. The list is initially never empty.
How do I display a list of long integers? (Mercury language)
178 views Asked by dogwood At
2
There are 2 answers
1
On
io.write_list(MyList, ",", io.write, !IO), where MyList is a list of type integer, will cause MyList members to be printed/displayed. Each member has the following display format i(1, [integer_value]), so it's an awkward appearing output, but is correct. An empty list prints nothing and doesn't result in error.
An alternative is io.write(MyList, !IO) and produces the same result.
The answer to the question of what OutputPred is is io.write. io.print also works.
This information was obtained from Mercury.org
The following Mercury code will display/print the list of type Integer in a more common form: [10, 9, 8,..., 2, 1].
io.write_string(string.join_list(" ,", map(integer.to_string, My_List)), !IO).
The square brackets have to be added separately and can be obtained with preceding and trailing io.write_string commands.
It works. My_List is a list of elements of type integer.
This information was obtained from Mercury.org