Access to workspace )vars within a class?

Writing and using Classes in Dyalog APL

Access to workspace )vars within a class?

Postby sloughin on Mon Dec 12, 2016 7:19 pm

How would one reference a var defined in the workspace within a class? For example, suppose I have a list of items, as enclosed character arrays, which I want to reference within a class:

myList←('apple' 'banana' 'cherry' 'date') ⍝ myList shows up in )vars

then in my class (e.g. ○FruitCake ) ...

∇z←indexOf fruit
z←myList ⍳ ⊂fruit

do I need to do something special so that myList is "visible" within the class? When I try something like the above, I get a Value Error for myList

Thanks for your help!
sloughin
 
Posts: 2
Joined: Mon Sep 12, 2011 8:38 pm

Re: Access to workspace )vars within a class?

Postby paulmansour on Tue Dec 13, 2016 2:53 pm

First, you probably don't want to really do that if you can avoid it.

But if you insist, then use an absolute path to the variable like:

      #.myList


If the variable is in fact a constant, then just define it as a read-only public field on the class. If it needs to be used by many classes, then you might consider creating a base class that all classes inherit from.
paulmansour
 
Posts: 418
Joined: Fri Oct 03, 2008 4:14 pm


Return to Object Oriented Programming

Who is online

Users browsing this forum: No registered users and 1 guest