(9!:37) usage restriction

28 views
Skip to first unread message

More Rice

unread,
Aug 20, 2024, 9:18:31 PMAug 20
to fo...@jsoftware.com
Hello,

I may be running into something silly again; but, I can't figure it out based on existing documentation.

Let me start with a short piece of code before asking the question.

NB. increase b(efore) to from 0 to 10 and a(fter) from 222 to 490
showmore =: 1 : 0
s =. (9!:36)''
(9!:37) 0 256 10 490
try.
   r =. u y
catch.
   stderr 13!:12''
   r =. ''
end.
(9!:37) s
r

)


Now, I found that the (9!:37) doesn't apply the new values inside the adverb above.

(9!:36)''  NB. show default values (b = 0, a = 222)

0 256 0 222

,. showmore i.222  NB. displays every line as expected

0

1

2

... NB. I chopped it for email

219

220

221

,. showmore i.223

... NB. <-- Why does J still use default b and a values and chopped here?

1

2

3

... NB. I chopped it for email

220

221

222

If I removed all the (9:37) inside the adverb, and called it outside the adverb (to change the b's and a's value), showmore works as expected - shows every line of i.500 .

The question is why?  Do we have usage restrictions?

(I'm using j9.4.2/j64avx2/windows.)

thanks

Maurice
PS. "atoms 2-3: the values of a and b." is wrong (ref). I think it should be "atoms 2-3: the values of b and a respectively."

Henry Rich

unread,
Aug 21, 2024, 2:51:05 AMAug 21
to fo...@jsoftware.com
The values of 9!:37 are applied when the result is formatted for display,, which is after the sentence has completed.

Henry Rich

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

Raul Miller

unread,
Aug 21, 2024, 9:40:05 AMAug 21
to fo...@jsoftware.com
And, as for why...

Generally speaking, no one really wants to see gigabytes of data
displayed in their session.

--
Raul

More Rice

unread,
Aug 21, 2024, 9:49:44 AMAug 21
to fo...@jsoftware.com
I was unbelievably silly.  Thanks Henry.

Initially, I was just trying to change the way my verb (u) would display its result, and then I got greedy - I also want to return the result.  I removed the "smoutput r" right after the 1st (9!:37) in the process.

thanks.

More Rice

unread,
Aug 21, 2024, 9:56:27 AMAug 21
to fo...@jsoftware.com
Raul, thanks.
I have rows and columns of boxes containing mixed data types, some are nested boxes.  They are nicely displayed by J front ends. I'm not sure how to write them out to file while preserving the formatting as much as possible at this point.  That's why I decided to change the display output for now to get by.

Do you know a foreign that can save boxed data (possibly nested) to a file nicely?

thanks.

On Wed, Aug 21, 2024 at 9:40 AM Raul Miller <rauld...@gmail.com> wrote:

Gaetan Godin

unread,
Aug 21, 2024, 10:09:15 AMAug 21
to fo...@jsoftware.com

Have you looked at files and component files in the Primer?

Gaëtan

Jan-Pieter Jacobs

unread,
Aug 21, 2024, 10:21:07 AMAug 21
to fo...@jsoftware.com
If I'd need the text representation, I would do something like: 

'foo.txt' fwrites ": your_boxed_data

This doesn't seem bothered by display limitations.

For saving the data for further use, there are better options (like component files, as pointed out by Gaëtan, or perhaps memory mapped files if you're feeling exotic; a list of ways to persist data can be found at https://code.jsoftware.com/Guides/Persistence).

Best regards,
Jan-Pieter

More Rice

unread,
Aug 21, 2024, 9:41:50 PMAug 21
to fo...@jsoftware.com
Thanks Jan-Pieter and Gaëtan.

Let me clarify a bit on the goal - the whole point of writing to a file is so that I can view the verb's entire output without dropping any rows/columns using an external viewer.  If I had to use J to read back the saved file content to view it using one of the J front ends, I end up with the same problem which I started with - I have to tweak J's display output using (9!37) again.

So when I asked Raul for the foreign to save to a file, I expect when I write <'test' to the file for example, I will get the following in my plain text editor when I open the file - a perfect box around 'test'.

┌────┐

│test│

└────┘

(Note: I have no intention to read the data file back into J for processing.  This is a pure data dump for text editor panning/viewing of the data.)

Now, let's get the suggestions ...

1. component files (your url doesn't work for me, Jan-Pieter)

In J:
   load'jfiles'
   f =. 'foo.txt'
   jcreate f
1
   (<'test') jappend f
0

In bash:

$ xxd -g1 foo.txt
...
000006f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
00000700: e3 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00  ................
00000710: 04 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00  ................
00000720: 04 00 00 00 00 00 00 00 74 65 73 74 00 00 00 00  ........test....
00000730: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20

Nope. Plain text editor can't view it.

2. fwrite?

In J:
         (": <'test') fwrite 'bar.txt'
18

In bash:
$ xxd -g1 bar.txt
00000000: 2b 2d 2d 2d 2d 2b 7c 74 65 73 74 7c 2b 2d 2d 2d  +----+|test|+---
00000010: 2d 2b 

Promising, but no 0d nor 0a. Box structure not rendered correctly.

Do you see what I'm looking for?


Maurice
thanks.





bill lam

unread,
Aug 21, 2024, 9:46:12 PMAug 21
to fo...@jsoftware.com
Why didn't you set it inside your configuration? eg.
in my base.cfg , I set
Output=: 0 8000 3 8000

Mr. Brian B. McGuinness

unread,
Aug 21, 2024, 9:57:45 PMAug 21
to fo...@jsoftware.com
This worked on my Linux box:

NB. Set the box drawing characters to ASCII characters
9!:7 '+++++++++|-'

NB. Format to characters, append a newline to each row, ravel, and write to a text file
(,(": <'test'),.LF) (1!:2) <'/home/brian/Desktop/jtest.txt'

--- Brian


From: fo...@jsoftware.com <fo...@jsoftware.com> on behalf of More Rice <mrmor...@gmail.com>
Sent: Wednesday, August 21, 2024 9:41 PM
To: fo...@jsoftware.com <fo...@jsoftware.com>
Subject: [External]Re: [Jforum] (9!:37) usage restriction
 

More Rice

unread,
Aug 21, 2024, 10:08:24 PMAug 21
to fo...@jsoftware.com
thanks Bill.

I assume this is a session wide config which affects all sentences' display output?  I didn't look for something like this because like Raul said, "Generally speaking, no one really wants to see gigabytes of data displayed in their session."  Totally agree - me too.  That's why I wrote the showmore adverb to restrict excessive display output only to the result I want more of.

(But of course, if J can dump the result to a plain text file I can view with a simple text editor, I won't even need to bother with the adverb.)

Maurice


Mr. Brian B. McGuinness

unread,
Aug 21, 2024, 10:17:52 PMAug 21
to fo...@jsoftware.com
Maybe something like this would help:

NB. Append a value to a text file

NB. x = pathname of output file
NB. y = value to write

add_text =: 4 : 0
  old =. 9!:6 ''
  9!:7 '+++++++++|-'
  (,(": y),"1 LF) (1!:3) <jpath x
  9!:7 old
)

--- Brian


From: fo...@jsoftware.com <fo...@jsoftware.com> on behalf of More Rice <mrmor...@gmail.com>
Sent: Wednesday, August 21, 2024 9:41 PM
To: fo...@jsoftware.com <fo...@jsoftware.com>
Subject: [External]Re: [Jforum] (9!:37) usage restriction
 

bill lam

unread,
Aug 21, 2024, 10:31:28 PMAug 21
to fo...@jsoftware.com
I think the use of adverb here is overkill.

I am using jconsole so that displaying large amount of data isn't an issue.

chris burke

unread,
Aug 21, 2024, 10:31:39 PMAug 21
to fo...@jsoftware.com
To get something from the session to a plain text file for later
viewing, you can just copy and paste.

The problem you are having in writing a boxed display to a file is
that the boxed display makes use of non-standard characters outside
the usual ascii visible character set, e.g.

a.i. ": <'test'
16 26 26 26 26 18
25 116 101 115 116 25
22 26 26 26 26 24

Text editors won't know how to handle this.

You can see how the utility clipwrite handles it:

clipwrite_jqtide_
3 : 0
txt=. boxj2utf8 flatten ":y
wd 'clipcopy *',txt
#txt
)

Using the same utilities (in the jqtide locale) will give you a utf8
character string that can be written to a readable text file:

a.i. boxj2utf8_jqtide_ flatten_jqtide_ ":<'text'
226 148 140 226 148 128 226 148 128 226 148 128...

'bar.txt' fwrite~ boxj2utf8_jqtide_ flatten_jqtide_ ":<'text'
48

More Rice

unread,
Aug 21, 2024, 11:16:19 PMAug 21
to fo...@jsoftware.com
Bill, agreed.

Chris, your sentence worked beautifully!  Thank you! It never crossed my mind to look there. This is very interesting.  Will take a close look.

Brain, your solution works flawlessly for me as well. Thank you so much.


thanks
Maurice



More Rice

unread,
Aug 22, 2024, 1:12:02 AMAug 22
to fo...@jsoftware.com
It works fast and very well.  Thank you, Brian.
Reply all
Reply to author
Forward
0 new messages