Created
April 5, 2012 20:12
-
-
Save rebcabin/2313759 to your computer and use it in GitHub Desktop.
application of captive2
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
SetAttributes[gridCaptive2, HoldAllComplete]; | |
dpyCaptive2[{ex_, {}}] := dpyNullary[dpyCaptive2 @ ex]; | |
dpyCaptive2[{a_, {as__}}] := dpyMultiary[dpyCaptive2 @ a, dpyCaptive2 /@ {as}]; | |
dpyCaptive2[number2[ex_]] := dpyQuotedAtom[number2[ex]]; | |
dpyCaptive2[string2[ex_]] := dpyQuotedAtom[string2[ex]]; | |
dpyCaptive2[symbol2[ex_]] := dpyQuotedAtom[symbol2[ex]]; | |
dpyCaptive2[x___] := Throw[Unevaluated @ {x}]; | |
gridCaptive2[expr_] := dpyCaptive2 @ captive2 @ expr; | |
dpyNullary[ex_] := | |
Grid[{{ex, ""}}, | |
Frame -> {All,False}, | |
Alignment -> Left, | |
Background -> {{LightOrange,{LightYellow}}}]; | |
dpyMultiary[key_, vals_] := | |
With[{c = Length @ vals}, | |
Module[{ | |
spans = Table["", {c}], | |
slot = Floor[(1+c)/2]}, | |
spans[[slot]] = key; | |
Grid[MapThread[List,{spans, vals}], | |
Frame -> {All,False}, | |
Alignment -> Left, | |
Background -> {{LightOrange,{LightGreen}}}] | |
]]; | |
dpyQuotedAtom[number2[ex_]] := | |
Grid[{{ex}}, | |
Frame -> All, | |
Alignment -> Left, | |
Background -> LightBlue]; | |
dpyQuotedAtom[string2[ex_]] := | |
Grid[{{ex}}, | |
Frame -> All, | |
Alignment -> Left, | |
Background -> Green]; | |
dpyQuotedAtom[symbol2[ex_]] := | |
Grid[{{ex}}, | |
Frame -> All, | |
Alignment -> Left, | |
Background -> LightPurple]; | |
dpyEmpty[] := | |
Grid[{{}}, | |
Frame -> All, | |
Alignment -> Left, | |
Background -> White]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
depends on captive2 in https://gist.github.com/2313720