[Jprogramming] Test whether class member is primitive
Henry Rich
henryhrich at gmail.com
Tue Jul 10 01:56:14 UTC 2018
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
More information about the Programming
mailing list