What does the dyad `=` do to boxed strings?

103 Views Asked by At

If x were a boxed string, I expect x=<'ABC' to compare the >x to 'ABC' to see if they are equal, but the following example shows that this is not the case. The J vocabulary document doesn't say anything about what "equal" means to boxes. So my questions are:

  1. What does = do to boxes of strings?
  2. In the example, instead of x=<'A' what is the correct way to get the "common sense result" 0 1 0 0?
   load 'convert/pjson'
   x=.dec_pjson_ enc_pjson_ ('TXT';'A';'CNAME';'MX') 
   x                              NB. Let's see what's in here...
┌───┬─┬─────┬──┐
│TXT│A│CNAME│MX│
└───┴─┴─────┴──┘
   x = <'TXT'                     NB. OK...
1 0 0 0
   x = <'MX'                      NB. Also good...
0 0 0 1
   x = <'A'                       NB. Why??
0 0 0 0
   y=.('TXT';'A';'CNAME';'MX')    NB. Let's make the same thing manually
   y = <'A'                       NB. So if I make the list of string manually it works
0 1 0 0
   y = x                          NB. But the 'A' in x is different from the 'A' in y
1 0 1 1
   (>1{y) = (>1{x)                NB. But everything returns to normal after unboxing x?
1
   (<>1{x) = (<>1{y)              NB. It will fail if you box it back up again
0
1

There are 1 best solutions below

1
Eelvex On BEST ANSWER

dec_pjson_ always returns a list:

   $ L:0 x    NB. Opened leaves are lists
┌─┬─┬─┬─┐
│3│1│5│2│
└─┴─┴─┴─┘ 
   $> 1 { x
1

'A' is not a list:

   $'A'
              NB. empty
   $> <'A'
              NB. empty

,'A' is a list:

   $,'A'
1
   (<,'A') = 1 { x
1
   (<,'A') = x
0 1 0 0

Specifically, the result of dec enc y gives you the "words" (;:) of y:

   ;:'TXT A CNAME MX'
┌───┬─┬─────┬──┐
│TXT│A│CNAME│MX│
└───┴─┴─────┴──┘
   (;:'TXT A CNAME MX') = x
1 1 1 1