Created
August 2, 2012 23:28
-
-
Save rebcabin/3241921 to your computer and use it in GitHub Desktop.
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
(* This code is released into the public domain by its author, Brian \ | |
Beckman, on 2 Aug 2012. *) | |
ClearAll[grid, fopts]; | |
ClearAll[allAreRulesQ, noneAreAtomsQ]; | |
(* A "HoldAll" version of the following, with "Unevaluated" \ | |
everywhere, may be required. *) | |
noneAreAtomsQ[candidates_List] := | |
And @@ (Not[AtomQ@#] & /@ candidates); | |
allAreRulesQ[candidates_List] := | |
And @@ (With[{h = Head@#}, h === Rule || h === RuleDelayed] & /@ | |
candidates); | |
fopts[fcolor_, bcolor_] := | |
Sequence[Frame -> All, Alignment -> Left, FrameStyle -> fcolor, | |
Background -> {{LightOrange, {bcolor}}}] | |
grid[Rule[key_, val_]] := | |
Grid[{{Style[grid@key, Bold, Black], Style[grid @ val, Bold, Blue]}}, | |
fopts[Blue, LightYellow]]; | |
grid[RuleDelayed[key_, val_]] := | |
Grid[{{Style[grid@key, Bold, Black], Style[grid @ val, Bold, Red]}}, | |
fopts[Red, LightYellow]]; | |
(* Put lists of non-atoms vertically and join them up, removing one \ | |
level of nesting. *) | |
grid[exprs_List?noneAreAtomsQ] := | |
Grid[(join@Transpose@{grid /@ exprs}), | |
Frame -> All, FrameStyle -> Darker[Green], Alignment -> Left, | |
Background -> LightGreen]; | |
(* Put other lists vertically but DON'T join them up. *) | |
grid[exprs_List] := | |
Grid[(Transpose@{grid /@ exprs}), | |
Frame -> All, FrameStyle -> Darker[Green], Alignment -> Left, | |
Background -> LightGreen]; | |
grid[h_[parts___]] := | |
Grid[{{Style[grid@h, Bold, Darker[Purple]]}~Join~(grid /@ {parts})}, | |
fopts[Black, LightGreen]]; | |
grid[any_?AtomQ] := Style[Grid[{{any}}, Alignment -> Left], Bold]; | |
grid[any_] := Grid[{{any}}, Alignment -> Left]; | |
ClearAll[join]; | |
(* Arbitrarily choose the first of multiple option tails z1, z2, ... \ | |
. *) | |
join[{{Grid[{xs__}, z1___]}, {Grid[{ys__}, z2___]}}] := {{Grid[{xs, | |
ys}, z1]}}; | |
join[{{Grid[{xs__}, z1___]}, {Grid[{ys__}, z2___]}, k__}] := | |
join[{{Grid[{xs, ys}, z1]}, k}]; | |
join[{{Grid[xs___]}}] := {{Grid[xs]}}; | |
join[{{Style[Grid[{xs__}, z1___], sty1___]}, {Style[ | |
Grid[{ys__}, z2___], sty2___]}}] := {{Style[Grid[{xs, ys}, z1], | |
sty1]}}; | |
join[{{Style[Grid[{xs__}, z1___], sty1___]}, {Style[ | |
Grid[{ys__}, z2___], sty2___]}, k__}] := | |
join[{{Style[Grid[{xs, ys}, z1], sty1]}, k}]; | |
join[{{Style[Grid[{xs__}, z1___], sty1___]}, {Grid[{ys__}, | |
z2___]}}] := {{Style[Grid[{xs, ys}, z1], sty1]}}; | |
join[{{Style[Grid[{xs__}, z1___], sty1___]}, {Grid[{ys__}, z2___]}, | |
k__}] := join[{{Style[Grid[{xs, ys}, z1], sty1]}, k}]; | |
join[{{Grid[{xs__}, z1___]}, {Style[Grid[{ys__}, z2___], | |
sty2___]}}] := {{Style[Grid[{xs, ys}, z1], sty2]}}; | |
join[{{Grid[{xs__}, z1___]}, {Style[Grid[{ys__}, z2___], sty2___]}, | |
k__}] := join[{{Style[Grid[{xs, ys}, z1], sty2]}, k}]; | |
join[{{Style[Grid[xs___], sty___]}}] := {{Style[Grid[xs], sty]}}; | |
join[{}] := {}; | |
grid[{rp -> z, sp[a, b], blah[q][r, s, q@t]}] | |
grid[{rp -> z, sp[a, b]}] | |
grid[{q -> {x, y}, rp -> z, sp[a, b]}] | |
grid[k[{q -> {x, y}, r -> z}, s]] | |
ClearAll[f]; | |
SetAttributes[f, {HoldAll, OneIdentity, Flat, Orderless}]; | |
f /: h_*f[x_] := Exp[x + h]; | |
f /: h_ + f[x_] := Exp[h*x]; | |
f[x_] := Sqrt[x]; | |
f[x_, y_] := Log[x + y]; | |
Language`ExtendedFullDefinition[f] | |
(Language`ExtendedFullDefinition[f][[1]] /. f -> "f") // grid | |
{{"BlanusaSnark", {1, 1}}, {"BlanusaSnark", {1, 2}}} // InputForm | |
DeleteCases[GraphData["Snark"], {"Snark", _}] | |
DeleteCases[GraphData["Snark"], {"Snark", _}] // grid | |
{a[b], qfe[a, {}], c[d, e]} // grid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment