I hope I'm not spamming the forum with my questions.
I am still getting my head around OOP in J.
My class:

coclass 'Account'

create =: verb define
balance =: 0
fname =: ''
lname =: ''
)
It's just a dummy 'Account' class with balance, first name and last name.
I want to create several objects in a list:

list =. 5 $ < 'Account'

list

┌───────┬───────┬───────┬───────┬───────┐│Account│Account│Account│Account│Account│└───────┴───────┴───────┴───────┴───────┘

So I have my list of 5 Accounts. Now I want to be able to access their fields, 
functions by indexing the list.
e.g. in Java if I have an array of Accounts
Account[] accounts = new Account[5];
I can access the fields from the array index:
for(int i = 0; i<5; i++){
          accounts[i].fname = "No name given";
}
In J,
I tried the following:
create__(1{list)
|value error: create__
|       create__(1{list)
I tried to call the create function of the 2nd Account (index 1) of th elist. 
It seems I can't append 1{list to create__.
Next I thought about making a function to do the work for me:
NB. function to return y's fname...
func =: verb define     acct =. y        name =: fname__acct        name
)
The above function assumes y is an instance of Account.
Alas, func 1{list doesn't work.
However if I do:
acct =: 1{list
func acct
This will return the fname.
But I have to explicitly define acct, which is not particularly terse. Is there 
a way to call functions from the list of objects?
                                          
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to