Created
September 8, 2012 09:52
-
-
Save athas/3673116 to your computer and use it in GitHub Desktop.
SML tabs2spaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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