I/O and printing lists question

This is a discussion on I/O and printing lists question within the ml forums in Programming Languages category; Hello all, I hope my problem is appropriate for this board, Ok, I've been coding for a while with sml, but I have never really needed to use any of the I/O stuff besides printing to the stdOut. Nevertheless, I have his problem of needing to print large lists (i.e., a' list list) and the order of the printing matters (I need it to be tab delimited so I can stick the output into some stat packages). Anyway, I have a list (the rows) of columns of a' 's. So, here is the question: Is there a way to convert ...

Go Back   Application Development Forum > Programming Languages > ml

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 10-30-2007, 09:02 PM
cougar.ksu@gmail.com
Guest
 
Default I/O and printing lists question

Hello all,
I hope my problem is appropriate for this board,

Ok, I've been coding for a while with sml, but I have never really
needed to use any of the I/O stuff besides printing to the stdOut.
Nevertheless, I have his problem of needing to print large lists
(i.e., a' list list) and the order of the printing matters (I need it
to be tab delimited so I can stick the output into some stat
packages). Anyway, I have a list (the rows) of columns of a' 's.

So, here is the question: Is there a way to convert that list into a
nicer structure for printing to a file? I've been looking at the sml
Basis library last night and this morning, but nothing seems too
promising and google hasn't turned up much. If nothing works, i'll
write an ugly function to print everything a bit at a time, but I was
hoping I wouldn't have to do that.

Any help would be greatly appreciated



Reply With Quote
  #2  
Old 11-07-2007, 06:23 PM
Vesa Karvonen
Guest
 
Default Re: I/O and printing lists question

cougar.ksu@gmail.com wrote:
[...]
> Nevertheless, I have his problem of needing to print large lists
> (i.e., a' list list) and the order of the printing matters (I need it
> to be tab delimited so I can stick the output into some stat
> packages). Anyway, I have a list (the rows) of columns of a' 's.


> So, here is the question: Is there a way to convert that list into a
> nicer structure for printing to a file?


There might be, but your description of the desired output format and
input list is insuffient to give a really good answer. However, based
on the description you gave, I see no immediate reason to convert the
list of lists to another form. As a first approximation, one could
write something like this:

fun printTabDelimitedTable printElem =
app (fn [] => () (* don't print empty lines *)
| x::xs => (printElem x
; app (fn x => (print "\t" ; printElem x)) xs
; print "\n"))

Now,

val () =
printTabDelimitedTable
(print o Int.toString)
[[3, 4, 1],
[5, 9, 2, 6],
[5]]

produces the output:

3 4 1
5 9 2 6
5

-Vesa Karvonen


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 02:07 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.