Skip to content

Instantly share code, notes, and snippets.

@athas
Created September 8, 2012 09:52
Show Gist options
  • Save athas/3673116 to your computer and use it in GitHub Desktop.
Save athas/3673116 to your computer and use it in GitHub Desktop.
SML tabs2spaces
local
val tabWidth = 2
fun tabsToSpaces' #"\t" = implode(List.tabulate(tabWidth, fn _ => #" "))
| tabsToSpaces' c = str c
in
val tabsToSpaces = String.concat o map tabsToSpaces' o explode
end
fun tabsToSpacesInFile f =
let val ih = TextIO.openIn f
val s = tabsToSpaces(TextIO.inputAll ih)
val oh = TextIO.openOut f
in TextIO.output(oh, s);
TextIO.closeIn ih;
TextIO.closeOut oh
end
(* Oversæt med følgende kommando:
mosmlc tabs2spaces.sml -o tabs2spaces
Udkommenter nedenstående definition hvis du vil indlæse filen
interaktivt, ellers får du en fejl.
*)
local
fun main [] = print ("Usage: " ^ CommandLine.name() ^ " <file>")
| main fs = () before map tabsToSpacesInFile fs
in
val _ = main (CommandLine.arguments())
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment