Right, makes sense now. Thanks.
BTW, I would like to add a request to the wiki, but have no access. How do I 
request access to the wiki?

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, 12:06 PM
 
 18!:0 y checks the status of y
 when viewed as a locale-name. 
 Unfortunately
 if y is totally bogus as a locale-name, 18!:0 fails with 
 rank/domain/whatever error.
 
 [Jon, if you add a request to
 system/interpreter/requests to remind me, 
 I
 will modify 18!:0 to return _3 for malformed locale rather
 than the 
 error.]
 
 This is where (u :: v) is useful.  It is a
 verb that executes u 
 returning its result,
 except that if u fails, the verb executes v and 
 returns the result of that.
 
 So here, 18!:0 :: _3: is saying 'is y a
 locale?  and if you get an 
 error, just
 return _3.'  Remember _3: is a verb that always returns
 _3, 
 same as _3"_ .
 
 Henry Rich
 
 On
 7/9/2018 10:57 PM, 'Jon Hough' via Programming
 wrote:
 > Yes, you are correct, thanks:
 >
 >     1 = 18!:0 ::
 _3: n__child
 > 0
 > 
    1 = 18!:0 :: _3: m__child
 > 0
 >     
 >     1 =
 18!:0 :: _3: other__child
 > 1
 >     
 > Seems to work
 fine!
 > Although, in this case, I am not
 entirely sure what _3: does.  What exactly
 > is it doing? Nuvoc doesn't seem to
 have any example using it.
 >
 > 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, 11:52
 AM
 >   
 >   It
 looked to me that using
 >   
 >   1 = 18!:0 :: _3:
 > 
  
 >   would solve your problem.
 >   
 >   Henry Rich
 >   
 >   On 7/9/2018
 10:50 PM, 'Jon Hough' via
 >  
 Programming wrote:
 >   > Sorry for
 the lack
 >   of clarity. The answer is
 yes, a boxed numbered locale.
 >   >
 Please see my last email (you may have
 >   missed it because we seemed to have
 sent at about the same
 >   time.)
 >   > My contrived example shows the
 >   root of the problem.
 >   >
 >   > You
 are correct that this method is
 >  
 fragile, but I don't know any other method.
 >   > Mixing up a boxed number locale
 with a
 >   boxed string of digits should
 never be an
 >   > issue with any of
 my classes. If a
 >   variable is a boxed
 string of digits then it is safe to
 >  
 assume
 >   > it as a locale.
 >   >
 >   >
 Anyway, my previous
 >   email gave a
 specific example of when this problem occurs,
 >   and what I
 >   >
 need to do to fix it to some
 >  
 extent.
 >   >
 >  
 > 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,
 11:36
 >   AM
 >  
 >
 >   >   Is an
 >   'object' a boxed
 >   >   numbered
 >   locale?  This is a yes-or-no
 question,
 >   >   and I think you
 are saying
 >   'yes', but I
 >   >   want to be
 >   sure.
 >   >
 >   >
 >   Perhaps
 >   >   you should use 18!:0 ::
 >   _3:   ?
 >  
 >
 >   >
 >  
 You will always have the problem of
 >  
 >
 >   distinguishing a boxed string
 of
 >   >
 >  
 digits
 >   >   from a
 locale-name.
 >   >
 >   >   Looking
 > 
  >   at the path is a bad idea and
 >   fragile.  Paths may be
 >   >   changed
 > 
  or
 >   >   set to empty based on
 the
 >   >   programmer's
 needs.
 >   >
 >  
 >   Henry Rich
 >   >
 >   >   On
 >  
 >   7/9/2018 10:16 PM, 'Jon Hough'
 >   via Programming
 >  
 >   wrote:
 >   >   > By
 "object" i mean
 >   >  
 some variable instantiated with conew -
 >   not a J type.
 >  
 >   > I am writing an
 >   object
 serializer, and
 >   >   looked
 at
 >   >   > https://code.jsoftware.com/wiki/Scripts/Serialization
 >   >   >
 >  
 >   > A
 >   modified version
 of
 >   >   this works
 >   somewhat, but it has problems  with
 >   >
 >   >  
 if. a: -: c=. {.(copath ::(a:"_)
 > 
  >   y)-.<,'z' do.
 >  
 >   > ...
 >   >   >
 >   else.
 >   >  
 > ...
 >   >   > end.
 >   >
 >   >
 >   >   > the above test is to
 check
 >   whether some
 >   >   variable is an object
 >   or a J type.
 >  
 >   > It
 >   >   fails on
 some of my classes for the
 >   reasons I
 explained in
 >   >   my last
 >   email.
 >   >  
 >
 >   >
 >  
 > It
 >   >   seems 18!:0 works
 for the
 >   case I gave, but in general
 will
 >   >   not
 >   work,
 >   >  
 > e.g. if m__myOtherClass
 >   =:
 >   >   1
 >  
 >   >
 >   18!:0 <
 m__myOtherClass
 >   >   >
 will
 >   give an rank error.
 >   >   >
 >  
 >   > The serializer I am
 >  
 >   writing is 90% complete. It just fails
 >   when an object's
 >   >   primitive
 >   member
 >   >  
 > variable is inherited
 >   >  
 from a parent class. Then my serializer
 >   thinks the member is
 >   >   an object type,
 >   because
 >  
 >   > the primitive
 >   >  
 test,
 >   >   > a:
 >   -: c=. {.(copath ::(a:"_)
 >   >
 >  
 y)-.<,'z'
 >   >   >
 fails.
 >   >   >
 >   >   >
 >  
 >   >
 >   >   >
 >   >
 >  
 --------------------------------------------
 >   >   > 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
 >   >
 >   >
 >   >   ---
 >  
 >   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
 >   
 >   
 >   ---
 >   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
 
 
 ---
 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