Pascal Jasmin wrote:
> 'mymethod' OO o should return the function mymethod__o
> (with o fixed reference)

Here's a way of accomplishing that.  v1 produces a monad,
v2 produces a dyad:

refname=:4 :0
 NB. x - name of member
 NB. y - locale
 nm=. x,'_',(":>y),'_'
)

v1=:2 :0
 NB. deferred monad
 if. 0=4!:0<nm=.m refname n do.
  ". bind nm
 else.
  a:1 :(nm,'@]')
 end.
)

v2=:2 :0
 NB. deferred dyad
 if. 0=4!:0<nm=.m refname n do.
  ". bind nm
 else.
  a:1 :('[',nm,']')
 end.
)

To defer resolution of the name, I'm creating a short
phrase that uses it.  That said, your suggestion, below,
points at another possible approach:

> btw, a potential bug is that 5!:0 doesn't seem to work on a
> local variable that holds a name.

More specifically, names are resolved.

   a=:+
   c=:a_base_
   c
a_base_
   5!:1<'c'
+-------+
|a_base_|
+-------+
   (5!:1<'c')5!:0
+

However, introducing an extra level of indirection lets us
work around this limitation:
   b=:a_base_
   c=:b
   (5!:1<'c')5!:0
a_base_

By definition, (5!:1<'c')5!:0 should produce the same thing
as c, and in the context of locales it's clear that this is
not the case -- so I think this is a bug, and I think that
in some future version of J we might see this fixed.

-- 
Raul


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

Reply via email to