Created
June 17, 2012 05:30
-
-
Save rebcabin/2943522 to your computer and use it in GitHub Desktop.
prints nice grid layout of rules in Mathematica
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
gridRules[rules_] /; | |
(ListQ[rules] && | |
(Length @ rules > 0) && | |
(And @@ (((Head @ # === Rule)||(Head @ # === RuleDelayed))& /@ rules))) := | |
With[{ | |
keys = #[[1]]& /@ rules, | |
heads = #[[0]]& /@ rules, | |
vals = gridRules[#[[2]]]& /@ rules}, | |
Grid[MapThread[{ | |
Style[#1, Bold], | |
Style[#3, Bold, Switch[#2, Rule, Blue, RuleDelayed, Red]]}&, | |
{keys, heads, vals}], | |
Frame -> All, | |
Alignment -> Left, | |
Background -> {{LightOrange, {LightYellow}}}] | |
]; | |
gridRules[rules_List] := Column[ | |
gridRules /@ rules, | |
Frame -> All, | |
Alignment -> Left, | |
Background -> LightGreen]; | |
gridRules[any_] := InputForm @ any; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment