Using a class (or a locale) is indeed a way of tying variables together.

Another approach (which is all a class or an object "really is", in J)
is to adopt a naming convention. Names can be thought of as
references. (Indices can also be thought of as references, but they
are more regular in their behavior than names).

The risk, with classes and objects, is that you'll be creating
something you don't really understand and whose behavior will be
mysterious to you as a result. It's somewhat like the snakeoil
approach to medicine (which, granted, has some benefits, even if they
are only placebo or "fun-oriented").

And, I guess it might be something of a "what else are you going to
do" kind of thing. But that's why I asked.

Thanks,

-- 
Raul


On Wed, Sep 17, 2014 at 3:45 AM, Jon Hough <[email protected]> wrote:
> Because I am making objects whose instance variables are dependent on the 
> constructor.
> I could use inheritence but the number of subclasses will get very large. So 
> I originally thought just define the variables based on what is passed in the 
> constructor.
> That way I only need one class.
> Why do I need a class?
> Well, maybe I don't. But I have half a dozen variables I want to tie 
> together. For me the obvious choice (in Java, C++ for example) is to make a 
> class.
>
>
> --- Original Message ---
>
> From: "Raul Miller" <[email protected]>
> Sent: September 17, 2014 4:37 PM
> To: "Programming forum" <[email protected]>
> Subject: Re: [Jprogramming] OOJ and calling a verb from another locale
>
> Out of curiosity, why?
>
> Thanks,
>
> --
> Raul
>
> On Wed, Sep 17, 2014 at 2:21 AM, Jon Hough <[email protected]> wrote:
>> Thanks for the answers.
>> I think I was trying to be a little too clever. But for my specific problem 
>> OOP is the way to go I think.
>>
>>
>> --- Original Message ---
>>
>> From: "Dan Bron" <[email protected]>
>> Sent: September 16, 2014 4:47 AM
>> To: [email protected]
>> Subject: Re: [Jprogramming] OOJ and calling a verb from another locale
>>
>> If this was StackOverflow, I'd be able to give this post a +1. As it is,
>> however, the best I can do is clutter up the list by vehemently agreeing
>> with you :)
>>
>> -Dan
>>
>> ----- Original Message ---------------
>>
>> Subject: Re: [Jprogramming] OOJ and calling a verb from another locale
>>    From: Devon McCormick <[email protected]>
>>    Date: Mon, 15 Sep 2014 15:38:37 -0400
>>      To: J-programming forum <[email protected]>
>>
>> The basic problem is attempting to do OO for its own sake.
>>
>> On Mon, Sep 15, 2014 at 2:32 PM, Raul Miller <[email protected]> wrote:
>>
>>> 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
>>>
>>
>>
>>
>> --
>> Devon McCormick, CFA
>> ----------------------------------------------------------------------
>> 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
> ----------------------------------------------------------------------
> 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