I didn't explicity say this, but to enable anonymous objects, it would be good 
if either __ ( double) or ___ (triple) syntax allowed to parameterize the 
locale after it.  For example, if o below were to be assigned (< 10) by conew.  
I understand that name__ is currently shorthand for name_base_ but that is 
supposedly temporary.  I'll use ___ (triple _) as the proposed syntax.

o =. conew 'myclass'
mymethod___ o (would return mymethod_10_)

THIS ADVERB DOESNT WORK, but should work like the above.

OO =: 1 : 0 NB. m: string of method/field, y: boxed locale number
NB. returns function that is either method_y_ or Get field_y_ for the member
y=. ": > y
t=. (m ,'_', y , '_' )
if. 0=4!:0 < t do. NB. if current value of field is noun, return field 
getter/reader
3 : ('] ' , t )
else.
 3 : (t , ' y')  NB.monad only :(
end.
)
'mymethod' OO o should return the function mymethod__o (with o fixed reference)
while the adverb doesn't work, using the return values directly does.
   f=: ({. Nonad 5 4 3 2 1)
   >f
13
    3 : ('] ' , 'STATE_10_' )) ''
5 4 3 2 1
   (3 : ('resume_13_' , ' y')) ''
5


To address your question as to why such a feature is useful:

1. objects are made easier to use by having as little methods/fields available 
to the user as possible.  Constructors that return only the user-relevant 
method(s) to the user greatly simplifies use of the class.  Completely hiding 
the OO implementation into a function means its easier to use.  Memoization 
(soon to be M.), nonads/Closure are examples of such single relevant method 
classes.  A lazily evaluated data stream that is prefetched asynchroniously 
using any processor core on the network would be another example of a complex 
class implementation that can be presented to the user as a single function 
interface.

2. Anonymous objects are allowed by that syntax permitting more one liners.
myconstruct =: (mymethod1 ; myfield2) OO conew ]
'`f g' =: myconstruct 'myclass'
'`f g' =: (mymethod1 ; myfield2) OO conew 'myclass' NB. equivalent to above 
line.

2b. in addition to convenience, is layering security on top of classes by 
limiting access to constructors.

What I directly want to accomplish is passing around a reference to a method or 
field of an object that is accessible in any locale, and maintains its locale 
reference.
mymethod_o_ (where o has been converted to numeric representation of locale) 
satisfies this, but mymethod_o_ f. does not because it loses its context.  

btw, a potential bug is that 5!:0 doesn't seem to work on a local variable that 
holds a name.  A nice foreign function in the 5!:x group would be
 'nameofvariable' 5!:99 ==> nameofvariable  (ie converting string form of a 
name to the executable form of that name... ie. ('mymethod_22_' 5!:99  y)  -: 
mymethod_22_ y  )

----- Original Message ----
From: "Miller, Raul D" <[EMAIL PROTECTED]>
To: Programming forum <[email protected]>
Sent: Sunday, October 29, 2006 9:40:10 PM
Subject: RE: [Jprogramming]  passing object functions to other objects

Pascal Jasmin wrote:

> working with classes does get messy... for instance you can't do

> this inside a constructor,

> 

> o =. conew 'myclass'

> mymethod__o

> return.

>

> maybe extra syntax would help. (triple _)

What are you trying to do?

It looks like you are creating yet another object, and then trying

to reference a method in that object.

This doesn't make sense to me, since -- if this is in a constructor

-- why would you be creating a different object, if you're not going

to retain a reference to it?

Also, the value of the create method is ignored, at best a single

word on a line by itself will simply refer to some other value.

More likely, 'mymethod__o' refers to a verb -- which is even less

useful on a line by itself in another verb.

(Perhaps, seeing what I make of that, or don't, you can provide

an explanation of what it was you really wanted to accomplish?)

Thanks,

-- 

Raul




----------------------------------------------------------------------
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