A good print command needed?

26 views
Skip to first unread message

Arnab Chakraborty

unread,
Aug 22, 2024, 10:28:54 PMAug 22
to fo...@jsoftware.com
Dear J-ers,

   As a dabbler in J, I am often bothered by the lack of any output mechanism in J that will allow me to inspect if two objects are equal (as determined by =). 
  One such example is 
   x=.1
   y=.,:1
   x
   y

Both x and y will print as 1. I need to print $x and $y to see the difference.

Just today I have come across another similar situation that is still puzzling me. I have two objects, good and bad:

   good
┌─┐
│1│
└─┘
   bad
┌─┐
│1│
└─┘
Both print the same, as you see. Both are atomic:

   $good
NB. Empty
   $bad
NB. Empty

Yet they are not the same:

   good=bad
0

Let's look inside the boxes:

   (>good)=(>bad)
1
  
Now they are the same! So where can the difference possibly be? 

I have not shown how I got good and bad (they are the results of some complex math procedure that is irrelevant here).
 
My question is: How to debug in such a situation? More specifically,  I want to make a feature request to have a print command that provides a visual representation that is faithful to the = operator. 
  
Thanks and regards,

Arnab

Arnab Chakraborty

unread,
Aug 22, 2024, 10:58:52 PMAug 22
to fo...@jsoftware.com
UIUA-style corner pieces while printing an array might be a good idea to bring out leading 1s in the shape.


To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.

bill lam

unread,
Aug 22, 2024, 11:06:43 PMAug 22
to fo...@jsoftware.com
For named nouns, you can use 5!:5 to visualize the content
   x=. 1
   y=. ,:1
   x=y
1
   5!:5<'x'
1
   5!:5<'y'
,1

To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.

Arnab Chakraborty

unread,
Aug 23, 2024, 12:42:20 AMAug 23
to fo...@jsoftware.com
Thanks a lot, Bill. Now I can understand. The 1 inside the box of good was an atom, while that inside bad had shape 1.

But does this not point at a serious inconsistency?

1 and ,:1 are considered to be the same by = and yet once boxed they are flagged as different by =

Is this a feature or a bug?

bill lam

unread,
Aug 23, 2024, 12:52:53 AMAug 23
to fo...@jsoftware.com
The rank of the verb = is 0 meaning it compares atom by atom
when comparing 1 and ,1  the two nouns are extended to the same shape.
For testing equality between nouns, sometime the verb -: (match) is more appropriate
depending on what you want. eg
   1 -: ,1
0

Arnab Chakraborty

unread,
Aug 23, 2024, 12:55:00 AMAug 23
to fo...@jsoftware.com
Ah, the "strange" behavior of = is a feature after all, as I just now learned from my umpteenth perusal of the nuvoc. Yet another thing to wrap my brain around!

Arnab Chakraborty

unread,
Aug 23, 2024, 1:04:20 AMAug 23
to fo...@jsoftware.com
Wonderful, Bill, you are -:-. (match less)

More Rice

unread,
Aug 23, 2024, 1:12:04 AMAug 23
to fo...@jsoftware.com
Are you looking for Bob's "Enhanced J Display"?
(a video of it)
I never tried, but it looks really cool.

Maurice


Henry Rich

unread,
Aug 23, 2024, 2:41:14 AMAug 23
to fo...@jsoftware.com
Consider using Dissect to examine your result.

Henry Rich
Reply all
Reply to author
Forward
0 new messages