untested, but

Stacks =. cones 'stack' NB. should probably use this variable for only 
stacks/objects
someprivatestack__Stacks =: conew 'stack'

somefield__someprivatestack__Stacks NB. accessing deeper.

or

pop__someprivatestack__Stacks ''

to answer your last question more directly,

a=. pop__Stacks ''
pop__a ''

if you do a forum search for inl, its a method that will let you access 
parameters from a list of objects/locales


----- Original Message -----
From: Jon Hough <[email protected]>
To: "[email protected]" <[email protected]>
Cc: 
Sent: Saturday, May 31, 2014 1:01:16 PM
Subject: Re: [Jprogramming] J and OOP

Thanks for answering.
I see what you are doing, but if the returned popped element is another 
instance of Stack (or any other object for that matter) how can I then call its 
methods?

> Date: Sat, 31 May 2014 12:58:14 -0400
> From: [email protected]
> To: [email protected]
> Subject: Re: [Jprogramming] J and OOP
> 
> I forgot to unbox the top element; also this version is much cleaner and
> doesn't require a temporary variable.
>   pop =: 3 : '(items =: }. items)  ]  > {. items'
> 
> Marshall
> 
> On Sat, May 31, 2014 at 12:55:29PM -0400, Marshall Lochbaum wrote:
> > The method pop as listed doesn't return the popped item; it returns the
> > size of the stack after the first element is popped. To have it return
> > the popped item you can instead write
> >   pop =: 3 : 'top [ (items =: }.items) [ top =. {.items'
> > .
> > 
> > Marshall
> > 
> > On Sat, May 31, 2014 at 05:32:02PM +0100, Jon Hough wrote:
> > > I'm trying to get my head round OOP in J.
> > > Mainly with http://www.jsoftware.com/help/learning/25.htm
> > > 
> > > My current problem is if I create an instance of a class and, and I want 
> > > to use it as a member variable of another object, how can I do this and 
> > > then call it and its functions?
> > > e.g.
> > > Using the Stack example:
> > > coclass 'Stack'   create =: 3 : 'items =: 0 $ 0'    push =: 3 : '# items 
> > > =: (< y) , items'    top =: 3 : '> {. items'     pop =: 3 : '#  items =: 
> > > }. items'     destroy =: codestroy     S =: conew 'Stack'   create__S 0
> > >    push__S 2
> > > 1   NB. create new stack T
> > > T =: conew 'Stack'   create__T 0
> > >    push__S T
> > > 2
> > > Now T is on S's stack. And I can retrieve it by popping, but doing this 
> > > does not seem to returna reference to the actual object T, and I cannot 
> > > call any of T's methods. Is there a way to cast the returned item to a 
> > > stack? Then possibly I can call it's methods.
> > > A Java example (not using generics):
> > > 
> > > public class MyStack{..// definitions etc}
> > > MyStack S = new MyStack();
> > > MyStack T = new MyStack();
> > > S.push(T);
> > > MyStack U = (MyStack)S.pop();//cast returned object to a MyStack
> > > U.push(5);//do something with returned object.
> > > Regards.                           
> > > ----------------------------------------------------------------------
> > > For information about J forums see http://www.jsoftware.com/forums.htm



> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
                          
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to