bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] ⎕FIO[49]


From: Juergen Sauermann
Subject: Re: [Bug-apl] ⎕FIO[49]
Date: Fri, 20 Jan 2017 16:57:55 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

Hi Xtian,

yes, one thing that I overlooked was that you should put ⎕FIO[49] into parantheses because
otherwise it will grab the function left of it and apply it to each line read from the file and not to
the final result:

      ⎕FIO[49]'x' 
 Line 1 Line 2 Line 3

      ⊃⎕FIO[49]'x'     ⍝ apply ⊃ to each line of the file (has no effect)
 Line 1 Line 2 Line 3

      ⊃(⎕FIO[49]'x')   ⍝ apply ⊃ to the final result of ⎕FIO[49]
Line 1
Line 2
Line 3

Syntactically ⎕FIO[49] behaves like a monadic operator with an optional left function argument.
The parentheses prevent it from using the left argument. In my previous example,

Z←CONVERT¨Z←⎕FIO[49] 'filename'

the had the same effect as the parentheses.


/// Jürgen


On 01/19/2017 11:10 PM, Christian Robert wrote:
Juergen,

Just a note, your example as of yesterday to disclose the result of ⎕FIO[49] to obtain a matrix no longer work as is.


I had to add a tack (⊢) between ⎕FIO[49] and the "⊃" as in LoadSudoku2 below.


  LoadSudoku2←{{⊂9 9 ⍴ ⍵}⍤1 ⊃ ⊢⎕FIO[49] ⍵}
  LoadSudoku3←{{⊂9 9 ⍴ ⍵} ⎕FIO[49] ⍵}

without the tack it would run disclose on each line which is a noop.


      time "a←LoadSudoku2 'Sudoku_dump.txt'"
3.370101159
      time "a←LoadSudoku3 'Sudoku_dump.txt'"
2.977278584

      time "a←LoadSudoku2 'Sudoku_dump.txt'"
3.142475014
      time "a←LoadSudoku3 'Sudoku_dump.txt'"
2.966579181

the LoadSudoku3 run faster than the LoadSudoku2


      ⍴a
219025
      ⊃a[1 2 3]
 000000000  000000000  000000000
 000000008  000000009  000000009
 560230400  400008120  580030100
 100803000  001030000  001640008
 090060000  085009760  000300005
 000025010  090040200  602005041
 300500706  800070006  003700000
 076002000  000021050  920000076
 005090021  006000010  040809000
      Display ¨ ⊃a[1 2 3]
 ╔═══╤═══╤═══╦═══╤═══╤═══╦═══╤═══╤═══╗  ╔═══╤═══╤═══╦═══╤═══╤═══╦═══╤═══╤═══╗  ╔═══╤═══╤═══╦═══╤═══╤═══╦═══╤═══╤═══╗
 ║   │   │   ║   │   │   ║   │   │   ║  ║   │   │   ║   │   │   ║   │   │   ║  ║   │   │   ║   │   │   ║   │   │   ║
 ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢  ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢  ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢
 ║   │   │   ║   │   │   ║   │   │ 8 ║  ║   │   │   ║   │   │   ║   │   │ 9 ║  ║   │   │   ║   │   │   ║   │   │ 9 ║
 ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢  ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢  ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢
 ║ 5 │ 6 │   ║ 2 │ 3 │   ║ 4 │   │   ║  ║ 4 │   │   ║   │   │ 8 ║ 1 │ 2 │   ║  ║ 5 │ 8 │   ║   │ 3 │   ║ 1 │   │   ║
 ╠═══╪═══╪═══╬═══╪═══╪═══╬═══╪═══╪═══╣  ╠═══╪═══╪═══╬═══╪═══╪═══╬═══╪═══╪═══╣  ╠═══╪═══╪═══╬═══╪═══╪═══╬═══╪═══╪═══╣
 ║ 1 │   │   ║ 8 │   │ 3 ║   │   │   ║  ║   │   │ 1 ║   │ 3 │   ║   │   │   ║  ║   │   │ 1 ║ 6 │ 4 │   ║   │   │ 8 ║
 ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢  ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢  ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢
 ║   │ 9 │   ║   │ 6 │   ║   │   │   ║  ║   │ 8 │ 5 ║   │   │ 9 ║ 7 │ 6 │   ║  ║   │   │   ║ 3 │   │   ║   │   │ 5 ║
 ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢  ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢  ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢
 ║   │   │   ║   │ 2 │ 5 ║   │ 1 │   ║  ║   │ 9 │   ║   │ 4 │   ║ 2 │   │   ║  ║ 6 │   │ 2 ║   │   │ 5 ║   │ 4 │ 1 ║
 ╠═══╪═══╪═══╬═══╪═══╪═══╬═══╪═══╪═══╣  ╠═══╪═══╪═══╬═══╪═══╪═══╬═══╪═══╪═══╣  ╠═══╪═══╪═══╬═══╪═══╪═══╬═══╪═══╪═══╣
 ║ 3 │   │   ║ 5 │   │   ║ 7 │   │ 6 ║  ║ 8 │   │   ║   │ 7 │   ║   │   │ 6 ║  ║   │   │ 3 ║ 7 │   │   ║   │   │   ║
 ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢  ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢  ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢
 ║   │ 7 │ 6 ║   │   │ 2 ║   │   │   ║  ║   │   │   ║   │ 2 │ 1 ║   │ 5 │   ║  ║ 9 │ 2 │   ║   │   │   ║   │ 7 │ 6 ║
 ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢  ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢  ╟───┼───┼───╫───┼───┼───╫───┼───┼───╢
 ║   │   │ 5 ║   │ 9 │   ║   │ 2 │ 1 ║  ║   │   │ 6 ║   │   │   ║   │ 1 │   ║  ║   │ 4 │   ║ 8 │   │ 9 ║   │   │   ║
 ╚═══╧═══╧═══╩═══╧═══╧═══╩═══╧═══╧═══╝  ╚═══╧═══╧═══╩═══╧═══╧═══╩═══╧═══╧═══╝  ╚═══╧═══╧═══╩═══╧═══╧═══╩═══╧═══╧═══╝


I love ⎕FIO[49] ;-)

Xtian.


On 2017-01-19 09:17, Juergen Sauermann wrote:
Hi,

I have added *⎕FIO[49]* to GNU APL in *SVN 858*.

*Z←⎕FIO[49] 'filename'* reads the file named *filename* line by line and stores every line
of the file in one enclosed item of result vector*Z* , for example (file *x* has 3 lines):

*      **⍪**⊃ ⎕FIO[49] 'x'
 Line 1
 Line 2
 Line 3
*
The end of line character (LF = '\n') character possibly a trailing CR = '\r' character is being removed in the process.

*⎕FIO[49]* accepts an optional left function argument *F* which is a monadic conversion function.
The conversion functions F is called with every line read and the result of the function
is then stored in Z. for example:

*      ⍪⊃ {'x: ', ⍵} ⎕FIO[49] 'x'**
**x: Line 1**
**x: Line 2**
**x: Line 3*

/// Jürgen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]