great work, Raul.  That's a big help.

the (a: 1 : adverb content) construct you have basically defines an adverb, and 
applies it to null, thereby returning a verb.  very cool.

I believe I have seen before a way to define both monad and dyad parts of a 
verb on the same line.  Is there a way to have a single function that would 
return this verb? 
(nm,'@]')
:
('[',nm,']') 

(trying to interject, LF, CR or CRLF between the items on a single line didn't 
work)

----- Original Message ----
From: "Miller, Raul D" <[EMAIL PROTECTED]>
To: Programming forum <[email protected]>
Sent: Monday, October 30, 2006 12:09:15 PM
Subject: RE: [Jprogramming]  passing object functions to other objects

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





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

Reply via email to