I misunderstood what was happening. I have recreated the situation using  a 
contrived example:


coclass 'GrandParent'

create=: 3 : 0
''
)

coclass 'Parent'
coinsert 'GrandParent'
create=: 3 : 0
m=: 'something'
n=: 'Parent'
f=: 4 4 3 2
)


coclass 'Child'

create=: 3 : 0
create_Parent_ f. y
other=: '' conew 'Other'
q=: 5
)

coclass 'Other'

create=: 3 : 0
xyz=: 123
)

There are three classes, GrandParent, Parent, Child. Child inherits from 
Parent. Parent inherits from GrandParent.

   child =: 0 conew 'Child'
    a: -:  {. (copath ::( a:"_) m__child) -. <, 'z' 
1
    a: -:  {. (copath ::( a:"_) n__child) -. <, 'z'  NB. should return 1, but 
returns zero.
0
    a: -:  {. (copath ::( a:"_) f__child) -. <, 'z' 
1
    a: -:  {. (copath ::( a:"_) other__child) -. <, 'z'  NB. return 0 because 
not primitive
0
    a: -:  {. (copath ::( a:"_) q__child) -. <, 'z' 
1
   
The above checks all pass, except for n. Because the variable n is a literal 
with the same name as the class (i.e. Parent).
This is where the check fails:
   (copath ::( a:"_) n__child)
┌───────────┬─┐
│GrandParent│z│
└───────────┴─┘
   (copath ::( a:"_) m__child)
┌─┐
│z│
└─┘
   
I think the solution is to override the variable from the parent class, if it 
has the same name as the parent class.
i.e. m__child = 'Child'

This serialization failure problem only occurred because I store each class's 
name as a member variable, so I can get the
quickly type  quickly. I forgot to override it for some child classes. 
Overriding it fixed the issue. Still feels a little brittle though.

Thanks,
Jon
--------------------------------------------
On Tue, 7/10/18, Henry Rich <[email protected]> wrote:

 Subject: Re: [Jprogramming] Test whether class member is primitive
 To: [email protected]
 Date: Tuesday, July 10, 2018, 10:56 AM
 
 I don't understand the term
 'object'.
 
 Does that
 mean 'numbered locale'?  If so, then a test for
 objectness 
 would be
 
 1 = 18!:0
 
 
 Henry Rich
 
 On
 7/9/2018 9:41 PM, 'Jon Hough' via Programming
 wrote:
 > I want to test if a given member
 variable of an object is  primitive  (e.g. one of the J
 datatypes - literal, integer etc etc) or an object.
 >
 > coclass
 'MyClass'
 >
 >
 create=: 3 : 0
 > m=:
 'something'
 > )
 >
 >
 >
 Here is one method:
 >
 > myClass =: '' conew
 'MyClass'
 >   a: -:  {. (copath
 ::( a:"_) m__myClass) -. <, 'z' NB. return 1
 if primitive, 0 if an object.
 >
 > This works, except if the member is
 defined in a parent class.
 >
 > coclass 'MyOtherClass'
 > coinsert 'MyClass'
 >
 > create=: 3 : 0
 > create_MyClass_ f. ''
 > ''
 > )
 >
 >
 >
 myOtherClass =: '' conew 'MyOtherClass'
 >   a: -:  {. (copath ::( a:"_)
 m__myOtherClass) -. <, 'z'
 >
 >
 >
 the above returns 0, but member is a primitive member of the
 MyOtherClass instance. Ideally this
 >
 should return 1 in this case, since m is still a primitive
 member of MyOtherClass.
 >
 > Any better way to test for primitive
 members?
 >
 >
 Thanks,
 > Jon
 >
 ----------------------------------------------------------------------
 > For information about J forums see http://www.jsoftware.com/forums.htm
 
 
 ---
 This email has been checked for viruses by
 AVG.
 https://www.avg.com
 
 ----------------------------------------------------------------------
 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