(* read digits until a nondigit and return their value assuming i is value of previously read digits of digits *) fun getInt(i,IN) = if not (isSome(TextIO.lookahead(IN))) then i (* end of file reached *) else let val c = valOf(TextIO.input1(IN)) in if c <= #"9" andalso c >= #"0" then (* c is a digit *) getInt(10*i+ord(c)-ord(#"0"),IN) else i end; (* print integer i in decimal *) fun putInt1(i,OUT) = if i<10 then TextIO.output(OUT, str(chr(i+ord(#"0")))) else ( putInt1(i div 10, OUT); (* print all but the last digit *) putInt1(i mod 10, OUT) (* print the last digit *) ); (* print i, surrounding multidigit numbers by parens *) fun putInt(i,OUT) = if i<10 then putInt1(i,OUT) else ( TextIO.output(OUT,"("); putInt1(i,OUT); TextIO.output(OUT,")") ); (* convert i to a sequence of base-b digits and print *) fun convert1(i,b,OUT) = if i