illo
Joined 15 years ago
Karma
141
Submissions
16
Member since
Sep 19
born, raised. Will die.
View on Hacker NewsJoined 15 years ago
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"Not to be taken as a general rule though. I might be mistaken but I think that bash would parse the line as:
([ a = b ] && echo "Oops!") || echo "Expected; phew!"
so if the command sequence after `&&` fails, then the code sequence after `||` is executed anyway: illo@joe:~ $ [ "a" == "a" ] && >/dev/full echo "strings match" || echo "strings don't match"
-bash: echo: write error: No space left on device
strings don't match
illo@joe:~ $
This is different from the semantics of the `if` block: illo@joe:~ $ if [ "a" == "a" ]; then >/dev/full echo "strings match"; else echo "strings don't match"; fi
-bash: echo: write error: No space left on device
illo@joe:~ $ grade(#student{work=Work, tried_hard=Tried}) -> grade1(Work, Tried).
grade1(excellent_work, _) -> 'a+';
grade1(okay_stuff, yes) -> b;
grade1(okay_stuff, _) -> 'b-';
grade1(_, _) -> c.
Edit: formatting.