Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: The right context to declare a symbol

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

Hi Trevor,
instead of simply declaring:
getLength[p]
you could distinguish by "Head"
getLength[p_obj1]
getLength[p_obj2]

Daniel


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