io-util.sml

来自「这是我们参加06年全国开源软件的竞赛作品」· SML 代码 · 共 59 行

SML
59
字号
(* io-util.sml * * COPYRIGHT (c) 1997 AT&T Labs Research. *)structure IOUtil : IO_UTIL =  struct    type instream = TextIO.instream    type outstream = TextIO.outstream    fun swapInstrm (s, s') =	  TextIO.getInstream s before TextIO.setInstream(s, s')    fun withInputFile (s, f) x = let	  val oldStrm = swapInstrm(TextIO.stdIn, TextIO.getInstream(TextIO.openIn s))	  fun cleanUp () =		TextIO.StreamIO.closeIn(swapInstrm(TextIO.stdIn, oldStrm))	  val res = (f x) handle ex => (cleanUp(); raise ex)	  in	    cleanUp();	    res	  end    fun withInstream (strm, f) x = let	    val oldStrm = swapInstrm(TextIO.stdIn, TextIO.getInstream strm)	    fun cleanUp () =		  TextIO.setInstream(strm, swapInstrm(TextIO.stdIn, oldStrm))	    val res = (f x) handle ex => (cleanUp(); raise ex)	    in	      cleanUp();	      res	    end    fun swapOutstrm (s, s') =	  TextIO.getOutstream s before TextIO.setOutstream(s, s')    fun withOutputFile (s, f) x = let	  val oldStrm = swapOutstrm(TextIO.stdOut, TextIO.getOutstream(TextIO.openOut s))	  fun cleanUp () =		TextIO.StreamIO.closeOut(swapOutstrm(TextIO.stdOut, oldStrm))	  val res = (f x) handle ex => (cleanUp(); raise ex)	  in	    cleanUp();	    res	  end    fun withOutstream (strm, f) x = let	    val oldStrm = swapOutstrm(TextIO.stdOut, TextIO.getOutstream strm)	    fun cleanUp () =		  TextIO.setOutstream(strm, swapOutstrm(TextIO.stdOut, oldStrm))	    val res = (f x) handle ex => (cleanUp(); raise ex)	    in	      cleanUp();	      res	    end  end (* IOUtil *)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?