I answered your questions about objectlists yesterday. you need to use the verb inl.
What you've done below is just create 5 boxed strings 'Account'. These are not locales. When you create "objects" the return values look like boxed numbers (though they are strings of numbers). If your list doesn't hold numbers, then it doesn't contain object instances (numbered locales). If your list has 5 identical numbers, then it is 5 references to the same object. You have to read these... maybe again every day until more of it gets absorbed. http://www.jsoftware.com/help/jforc/modular_code.htm#_Toc191734482 http://www.jsoftware.com/jwiki/Vocabulary/Locales working with lists of objects is fairly advanced with no tutorials for doing so. You should only tackle it after you have mastered getting one object working. ----- Original Message ----- From: Jon Hough <[email protected]> To: "[email protected]" <[email protected]> Cc: Sent: Wednesday, June 4, 2014 11:16:40 AM Subject: [Jprogramming] More Object List Questions 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
