Code: Select all
∇new0
:Access Public
:Implements Constructor
matl← ⎕NEW Material
∇
In this example I have a namespace RayTracer and two classes within it, Shape and Material. The use of :Include with the enclosing namespace reference doesn't help, nor unfortunately does ⎕PATH. If I use an absolute path reference to Material, all is fine but it is not what I would prefer. A local relative path reference works, but only if I'm within the enclosing RayTracer namespace, i.e.
Code: Select all
matl← ⎕NEW ##.Material
If I try to create the class instance outside of the enclosing RayTracer namespace, for example in #, that also fails with undefined name. What I need is the equivalent of ⎕PATH for class references. Having to code all references as absolute within a constructor would pin me to a particular place, as in
Code: Select all
matl← ⎕NEW #.RayTracer.Material
The only alternative at the moment is to not assign the field in the constructor at all, but assign a class instance after creation like this
Code: Select all
⍝ Within RayTracer namespace
p←⎕NEW Shape
p.matl←⎕NEW Material
⍝ or anywhere else
p←⎕NEW #.RayTracer.Shape
p.matl←⎕NEW #.RayTracer.Material
This will work regardless of where I am, but requires a little extra work on the part of the programmer. Any suggestions on avoiding full namespace path references within the class code I'm writing if I'd like to create instances of other classes within constructors?
Thanks in advance,
~Mark