Standard ML program. I fear it does not contribute much to the conversation but I cannot abstain from calling attention to my favourite pragmatic programming language that is presently on what seems to be a neverending life support.
structure I = Int
structure S = String
structure SU = Substring
structure SC = StringCvt
infix 5 >>
fun (x >> y) f = if x = y then () else (f x; ((x + 1) >> y) f)
val printRow =
let
val p0 = SC.padLeft #"0" val ps = SC.padLeft #" "
val td = I.fmt SC.DEC val tx = I.fmt SC.HEX
val to = I.fmt SC.OCT val tb = I.fmt SC.BIN
val desc = fn
0 => "NUL" | 1 => "SOH" | 2 => "STX" | 3 => "ETX" | 4 => "EOT" | 5 => "ENQ"
| 6 => "ACK" | 7 => "BEL" | 8 => "BS" | 9 => "HT" | 10 => "LF" | 11 => "VT"
| 12 => "FF" | 13 => "CR" | 14 => "SO" | 15 => "SI" | 16 => "DLE" | 17 => "DC1"
| 18 => "DC2" | 19 => "DC3" | 20 => "DC4" | 21 => "NAK" | 22 => "SYN" | 23 => "ETB"
| 24 => "CAN" | 25 => "EM" | 26 => "SUB" | 27 => "ESC" | 28 => "FS" | 29 => "GS"
| 30 => "RS" | 31 => "US" | 32 => "SPC" | 127 => "DEL" | n => str (chr n)
in
fn n => print (S.concatWith " " [ps 3 (td n), p0 2 (tx n), p0 7 (tb n), p0 3 (to n), desc n] ^ "\n")
end
val spec =
let
val scan = fn rad => fn sl => SC.scanString (I.scan rad) (implode sl)
in
fn str => valOf (case explode str of
#"0" :: #"x" :: hex => scan SC.HEX hex
| #"0" :: #"o" :: oct => scan SC.OCT oct
| #"0" :: #"b" :: bin => scan SC.BIN bin
| dec => scan SC.DEC dec)
end
val () = case CommandLine.arguments () of
[] => (0 >> 128) printRow
| [req] => printRow (spec req)
| _ => raise Fail "arguments"
Happy to see Ada still gets some interest outside of MIC. When I went off to university, I was a Perl snob but my school used Ada as its primary teaching language. It was a great way of expanding my knowledge across the horizon to understand the value in strong typing.
After nearly half a century, I still don't have ASCII memorized either but usually just use asciitable.com to do a quick lookup. Having a system utility like this one would be handy in situation without internet access. Plus like he noted, it was a good way to learn more about Ada.
reply