Skip to content

Instantly share code, notes, and snippets.

@rebcabin
Created April 5, 2012 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rebcabin/2313759 to your computer and use it in GitHub Desktop.
Save rebcabin/2313759 to your computer and use it in GitHub Desktop.
application of captive2
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];
@rebcabin
Copy link
Author

rebcabin commented Apr 5, 2012

depends on captive2 in https://gist.github.com/2313720

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment