The right context to declare a symbol
- To: mathgroup at smc.vnet.net
- Subject: [mg63001] The right context to declare a symbol
- From: "Trevor Baca" <trevorbaca at gmail.com>
- Date: Sat, 10 Dec 2005 06:03:18 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
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.