I can see two things you are doing wrong here, perhaps three.

First, consider:

   myVerb=: +/ % #
   MyVerb 1 2 3
|value error

J is case sensitive.

Next, consider:
   coname''
base
   myVerb_base_
+/ % #
   myVerb_z_
|value error

You defined myVerb in the base locale, and not in the z locale.

So that's two things.

Next let's consider the design of your constructor:

coclass 'MyClass'

create=: verb define
  myValue=: ".y
)

This says that you are expecting the constructor to be getting an sentence
which will be evaluated in the object's locale. That means that any names
would have to be defined in the z locale or in your class definition
definition (by default your object inherits from z and the class but not
from any other locale). So that's the possible third problem.

You might instead want the object to inherit from some other locale (in
this example, you have implied you are interested in the base locale). You
could make the class inherit from base:

coclass 'MyClass'
coinsert 'base'

create=: verb define
  myValue=: ".y
)

Or maybe you think that that is a bad idea, and instead only want the
sentence to be evaluated in the base locale:

coclass 'MyClass'

create=: verb define
  myValue=: do_base_ y
)

(There is no way to discover what locale you were called from unless
debugging was enabled before the call was made, or unless some
programmer-imposed convention was used to identify the calling locale.)

Of course, you could just specify the locale where the name was defined in
the sentence you pass to the constructor:

   'myVerb_base_ 1 2 3' conew 'MyClass'
+-+
|5|
+-+
   myValue_5_
2

I'd also take note of the other responses you've gotten.

Thanks,

-- 
Raul






On Mon, Sep 15, 2014 at 10:38 AM, Jon Hough <[email protected]> wrote:

> OOJ = object oriented J
> I have a preexisting verb, for example lets call it myVerb =. +/ % #.
> Next I define a class:
> coclass 'MyClass'
> create =: verb define       myValue =: ". y
> )
> So, essentialy my value is going to run the command y, using verb ".
> So perhaps I want y to by 'myVerb 1 2 3'
> Then, hopefully myValue will be 2.
> So I do
> myObj =: conew 'MyClass'
> create__myObj 'MyVerb 1 2 3'
> However, I get a value error for MyVerb. I asusme this is because myVerb
> was defined in a different locale.
> I then tried create__myObj 'MyVerb_z_ 1 2 3'
> Which also gives a value error.
> By the way, what I am trying to do is pass a callback to the constructor
> of MyClass, so I can execute an arbitrary function. I am using ". to call
> the arbitrary function. I think this method of callbacks was shown in J for
> C.
> So the question is, what is my code doing wrong?
> Thanks.
>
>
> ----------------------------------------------------------------------
> 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