-- -- -- IO -- -- -- -- IO -- def print x := do write x write "\n" flush () def printToPort port x := do writeToPort port x writeToPort port "\n" def display x := do write x flush () def displayToPort port x := do writeToPort port x def eachLine proc := do let eof := isEof () if eof then return () else do let line := readLine () proc line eachLine proc def eachLineFromPort port proc := do let eof := isEofPort port if eof then return () else do let line := readLineFromPort port proc line eachLineFromPort port proc def eachFile files proc := match files as list string with | [] -> return () | $file :: $rest -> do let port := openInputFile file eachLineFromPort port proc closeInputPort port eachFile rest proc -- -- Collection -- def each proc xs := match xs as list something with | [] -> do return () | $x :: $rs -> do proc x each proc rs -- -- Debug -- def debug %expr := io $ do print (show expr) return expr def debug2 %msg %expr := io $ do display msg print (show expr) return expr