MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Format[ ] with \[OverBracket] in a package `Private` context

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56431] Format[ ] with \[OverBracket] in a package `Private` context
  • From: "Trevor Baca" <trevorbaca at gmail.com>
  • Date: Mon, 25 Apr 2005 01:30:45 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

hello mathgroup,

my goal is to format foo[_List] objects with an overscripted
\[OverBracket], and then shove this bit of code into a package for
later access. this does the trick in a notebook session:

Format[foo[l_List]] := Overscript[RowBox[l], \[OverBracket]] //
DisplayForm;

the interpreter now outputs foo[{2,3,4,5}] as 1 2 3 4 with a lovely
overbracket stretching across the top. so far so good. now the hard
part: shoving this bit of code into a package without context issues
getting in the way.

(three example packages follow; feel free to skip to the section marked
"CONCLUSION" at the bottom for the actual question.)


==== PROBLEM PACKAGE =================

  BeginPackage["Foo`"]

  foo::usage="foo objects print with overbracket.";

  Begin["`Private`"]

  Format[foo[e_]]:=Overscript[RowBox[e],\[OverBracket]]//DisplayForm

  End[]

  EndPackage[]

==== end problem package ================


with the problem package, i interpret the following three commands:

  Quit[ ]  (* to clear out any previous definitions in any contexts *)

  << Foo`

  foo[{2,3,4,5}]

... and, unfotunately, foo[{2,3,4,5}] prints as 2 3 4 5 with the ugly
label Foo`Private`\[OverBracket] running across the top. not at all
what i wanted. first solution:


==== SOLUTION PACKAGE 1: use System` context ==========

  BeginPackage["Foo`"]

  foo::usage="foo objects print with overbracket.";

  Begin["`Private`"]

  Begin["System`"]

  \[OverBracket]

  End[]

  Format[foo[e_]]:=Overscript[RowBox[e],\[OverBracket]]//DisplayForm

  End[]

  EndPackage[]

==== end solution package 1 =======================



with solution package 1, i again interpret the following three
commands:

  Quit[ ]  (* to clear out any previous definitions in any contexts *)

  << Foo`

  foo[{2,3,4,5}]

... and this works: foo[{2,3,4,5}] now prints as 2 3 4 5 with the
overbracket running across the top, as desired. but i've introduced the
OverBracket symbol into the System` context directly; and is this a
generally bad practice? fearing that it might be, i build this second
solution:


==== SOLUTION PACKAGE 2: use Foo` context ==========

  BeginPackage["Foo`"]

  foo::usage="foo objects print with overbracket.";

  \[OverBracket]

  Begin["`Private`"]

  Format[foo[e_]]:=Overscript[RowBox[e],\[OverBracket]]//DisplayForm

  End[]

  EndPackage[]

==== end solution package 2 =====================



with solution package 2, i interpret the following three commands one
last time:

  Quit[ ]  (* to clear out any previous definitions in any contexts *)

  << Foo`

  foo[{2,3,4,5}]

... and this, too, works fine: foo[{2,3,4,5}] prints as 2 3 4 5 with
the requested overbracket. unfortunately, the OverBracket symbol now
lives in Foo`\[OverBracket], which somehow seems wrong to me, and
further seems to violate the spirit of the purpose of the public
section of a package ... introduce symbols "for export".



CONCLUSION: so is it better to stick the OverBracket symbol into the
System` context (as in solution package 1), or to stick the OverBracket
symbol into the Foo` context (as in solution package 2), or to do
something else entirely?

(i strongly prefer solution 1 (using the System` context) because it
seems bizarre to me that the OverBracket symbol doesn't already exist
in the System` context, so why not remedy the situation? on the other
hand, i could be convinced that messing with the System` context is as
bad an idea as messing with most reserved namespaces, hence solution 2.
but what i don't like about solution 2 is that after loading the
package, Names["Foo`*"] will give you both "foo" (which is good) and
"\[OverBracket]" (which just seems wrong)).

anything to help make the decision or clean this up?


trevor.


  • Prev by Date: Hidden affects of setting $MinPrecision/SetPrecision?
  • Next by Date: Re: simplifying ulam spiral code
  • Previous by thread: Hidden affects of setting $MinPrecision/SetPrecision?
  • Next by thread: Re: Format[ ] with \[OverBracket] in a package `Private` context