Re: output formatting
Hi Stephen, On 9/10/23 21:58, Stephen Lewis via Bugs and suggestions for GNU APL wrote: ... When using 'apl' script in a pipeline I was surprised to find formatting clearly designed for a terminal when output was going to a file. Especially when the formatting has the effect of changing the shape of a matrix. It does not. It merely folds the output at the point indicated by ⎕PW. Many Unix commands behave differently when the output is not a terminal. Would it make sense for 'apl' to turn off terminal formatting when --script is in effect and the output is not a terminal? The problem is that when printing into a file, APL cannot know if the folding of the output is desired or not. Some may want the folded output (e.g. to later cat it), some may not. Also, APL cannot even know in a reliable way if the output goes to a file or to a terminal. In your case (forwarding to a file) all that APL sees is a file descriptor which is one end of a pipe to which the output goes. It cannot see the other end of that pipe (possibly a file but also possibly a terminal e.g. if the pipe is an ssh connection). The whole point of --PW is to tell APL where is shall fold the output. Unfortunately IBM APL2 says that ⎕PW has a minimum value of 30 so we cannot use 0 or -1 to suppress the folding. Therefore using large value is the only option remaining without breaking the APL2 compatibility of GNU APL. Best regards, Jürgen
Re: output formatting
Thank you all for the quick replies and suggestions. Chris Moller, Bill Daly - Thanks, "Page Width" (Print Width?) solved my immediate problem, --PW 500 on commandline or ⎕pw←500. 'tr' and 'sed' does fix the spaces and blank line but my version (Gnu APL 1.8 from tarball) does not have --exec option. Redirected output from shell works but I will also try writing to a file from 'apl'. Christian Robert, Jürgen Sauermann, I have not tried FIO yet but will read documentation and try suggested function. That looks very useful, thanks. When using 'apl' script in a pipeline I was surprised to find formatting clearly designed for a terminal when output was going to a file. Especially when the formatting has the effect of changing the shape of a matrix. Many Unix commands behave differently when the output is not a terminal. Would it make sense for 'apl' to turn off terminal formatting when --script is in effect and the output is not a terminal? -- Stephen Lewis
Re: output formatting
Hi, the problem seems to be that you let APL print to a terminal (which wraps long lines at ⎕PW). A better way is probably to use one of the ⎕FIO functions in your APL script as to write directly to the output file (which bypasses the terminal). Of course output forwarding in the shell would not see anything in that case. Best regards and welcome to GNU APL, Jürgen On 9/10/23 01:07, Stephen Lewis via Bugs and suggestions for GNU APL wrote: I am a novice and I am using APL to calculate the points for a surface. The output will go to another program. The goal is to write a matrix, with the correct number of rows and columns, to a file. Elements should be separated by and rows should be separated by . I have found that the output is formatted in an unexpected way. Test case to write a matrix with 2 rows of 50 columns. Is there any way to write a matrix with correct shape to a file when rows exceed 80 characters? I have tried the following: Method 1 script_1.apl: - 2 50⍴⍳100 - apl < script_1.apl apl < script_1.apl > out_1.txt Writes welcome banner, elements in 4 row matrix with spurious extra characters and four messages about end-of-input and a goodbye message and also writes to stderr. Method 2 apl -f script_1.apl apl -f script_1.apl > out_2.txt Writes welcome banner, elements in 4 row matrix with spurious extra characters and a goodbye message and remains in 'apl' unless stdout is redirected to a file or )OFF added to script. Method 3 script_2.apl: - #! /usr/bin/apl --script --OFF 2 50⍴⍳100 - ./script_2.apl ./script_2.apl > out_3.txt Must add )OFF to script or use --OFF. Writes elements in 4 row matrix with spurious extra characters and a blank line. I would like two rows of 50 elements but output file looks like this: - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 -
Re: output formatting
On Sun, 10 Sept 2023 at 01:08, Stephen Lewis wrote: > Writes elements in 4 row matrix with spurious > extra characters and a blank line. One thing you could do is to increase the print width ⎕PW so that it doesn't wrap, but ultimately this default printout is intended for human consumption. Short of formatting it explicitly and writing it to file, another thing you could try would be to use the quote-quad output: ⍞←2 50⍴⍳100 This is outside of the ISO standard (which only accepts character vectors rather than arbitrary values for quote-quad output) and I'm not sure if it's exactly what you need, but it's a reasonably simple way to send the character representation (in its default form as if by monadic ⍕, with columns still aligned and padded with spaces) to the output without any additional wrapping with indents or blank lines. -k
Re: output formatting
If you change your printing width APL may not print the overflow of each line as a separate line. tmp←2 50 ⍴ ⍳ 100 ⎕pw←225 tmp 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 It might be better to use apl to write your out put file: )copy 5 DALY/export DUMPED 2023-07-17 17:07:29 (GMT-4) NEW )COPY_ONCE workspace: 5 DALY/utf8 DUMPED 2023-07-17 16:44:54 (GMT-4) NEW )COPY_ONCE workspace: 5 DALY/utl DUMPED 2023-08-07 15:46:53 (GMT-4) tmp←2 50 ⍴ ⍳ 100 tmp export∆array '/home/dalyw/staging/tmp.txt' 0 file tmp.txt has a tab character between each datum rather than a space. It it must be a space you can modify export∆array. w On 9/9/23 19:07, Stephen Lewis via Bugs and suggestions for GNU APL wrote: I am a novice and I am using APL to calculate the points for a surface. The output will go to another program. The goal is to write a matrix, with the correct number of rows and columns, to a file. Elements should be separated by and rows should be separated by . I have found that the output is formatted in an unexpected way. Test case to write a matrix with 2 rows of 50 columns. Is there any way to write a matrix with correct shape to a file when rows exceed 80 characters? I have tried the following: Method 1 script_1.apl: - 2 50⍴⍳100 - apl < script_1.apl apl < script_1.apl > out_1.txt Writes welcome banner, elements in 4 row matrix with spurious extra characters and four messages about end-of-input and a goodbye message and also writes to stderr. Method 2 apl -f script_1.apl apl -f script_1.apl > out_2.txt Writes welcome banner, elements in 4 row matrix with spurious extra characters and a goodbye message and remains in 'apl' unless stdout is redirected to a file or )OFF added to script. Method 3 script_2.apl: - #! /usr/bin/apl --script --OFF 2 50⍴⍳100 - ./script_2.apl ./script_2.apl > out_3.txt Must add )OFF to script or use --OFF. Writes elements in 4 row matrix with spurious extra characters and a blank line. I would like two rows of 50 elements but output file looks like this: - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 -
Re: output formatting
Try adding the option "--PW 1000" (or any large number less than 1). That will set the print width to huge. The tr utility with the -s option can compress repeated spaces into a single space. sed '$d' will kill the last line. So something like apl --PW 500 --eval "2 70⍴⍳140" | tr -s ' ' | sed '$d' should work. On 9/9/23 19:07, Stephen Lewis via Bugs and suggestions for GNU APL wrote: I am a novice and I am using APL to calculate the points for a surface. The output will go to another program. The goal is to write a matrix, with the correct number of rows and columns, to a file. Elements should be separated by and rows should be separated by . I have found that the output is formatted in an unexpected way. Test case to write a matrix with 2 rows of 50 columns. Is there any way to write a matrix with correct shape to a file when rows exceed 80 characters? I have tried the following: Method 1 script_1.apl: - 2 50⍴⍳100 - apl < script_1.apl apl < script_1.apl > out_1.txt Writes welcome banner, elements in 4 row matrix with spurious extra characters and four messages about end-of-input and a goodbye message and also writes to stderr. Method 2 apl -f script_1.apl apl -f script_1.apl > out_2.txt Writes welcome banner, elements in 4 row matrix with spurious extra characters and a goodbye message and remains in 'apl' unless stdout is redirected to a file or )OFF added to script. Method 3 script_2.apl: - #! /usr/bin/apl --script --OFF 2 50⍴⍳100 - ./script_2.apl ./script_2.apl > out_3.txt Must add )OFF to script or use --OFF. Writes elements in 4 row matrix with spurious extra characters and a blank line. I would like two rows of 50 elements but output file looks like this: - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 - OpenPGP_0xDA6C0193083E.asc Description: OpenPGP public key OpenPGP_signature Description: OpenPGP digital signature