MathGroup Archive 2005

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

Search the Archive

Re: The right context to declare a symbol

  • To: mathgroup at
  • Subject: [mg63060] Re: The right context to declare a symbol
  • From: dh <dh at>
  • Date: Tue, 13 Dec 2005 03:40:41 -0500 (EST)
  • References: <dnedrl$1di$>
  • Sender: owner-wri-mathgroup at

Hi Trevor,
instead of simply declaring:
you could distinguish by "Head"


Trevor Baca wrote:
> I'm interested in creating two different "objects", which we'll call
> obj1 and obj2.
> So I create two separate .m packages callled obj1.m and obj2.m.
> Then let's say that for each object I want to define a getLength
> function (accessor) so that I can say both
>   getLength[p]
> and
>   getLength[q]
> where p is an obj1 and q is an obj2.
> The problem is that if both obj1.m and obj2.m declare a getLength
> expression, then doing
> << obj1`
> works, but then adding
> << obj2`
> causes shadowing objections since, of course, the expression getLength
> now lives in two contexts.
> So what's the right way to declare a simple expression (like getLength,
> getName, getColor, etc) that operates on multiple different classes of
> object defined in different packages?
> It would, of course, work to declare getLength, etc, in, say, the
> System` or Global` context and NOT in any other context ... but that
> just seems odd. Shouldn't expressions related to a package live in the
> package?
> Trevor.

  • Prev by Date: Re: Re: How to hide a cell?
  • Next by Date: Re: Turning on numerical computation
  • Previous by thread: The right context to declare a symbol
  • Next by thread: functional programming