All pastes #215195 Raw Edit

Unnamed

public text v1 · immutable
#215195 ·published 2006-10-22 13:28 UTC
rendered paste body
load "TextIO";
load "String";
load "Int";
load "Option";

(* fileToList "infile" åbner infile og outputter dette som en liste af typen '(int * string * string) list' *)
 
fun fileToList infile = 
    let val inf  = TextIO.openIn infile
        val st   = String.tokens (fn x => x = #",") (TextIO.inputLine(inf))
        val navn = hd (st)
        val pris = Option.valOf (Int.fromString (hd (tl (st))))
        val vare = String.substring(hd (tl( tl( st))),0, size(hd (tl( tl( st))))-1)
        val koeb = (pris, navn, vare)
    in            
        if TextIO.endOfStream inf
        then koeb :: []
        else koeb :: (fileToList infile) end;

(* giver fejlen:
! Uncaught exception: 
! Io {cause = SysErr ("Too many open files", SOME<syserror>),
      function = "openIn", name = "thisisatest.txt"}
*)