Very nice. Thanks! Would it make sense to add a tokenisation function as well that one could use as a RO for this operator?
Regards, Elias On 27 Jan 2017 23:04, "Juergen Sauermann" <juergen.sauerm...@t-online.de> wrote: > Hi, > > I have added two wrapper functions in the *FILE_IO* workspace: > > *Z←FIO∆readlines Bs* > > reads the entire file named *Bs* (i.e. not a file handle Bh!) line by > line and stores each line i in *Z[i]**.* > > *Z←(LO FIO∆transform_lines) Bs* > > does the same, but every line is processed by (monadic) *LO* and the > result returned by *LO* > is then stored in *Z[i]*. > > *SVN 863*. > > /// Jürgen > > > On 01/27/2017 12:33 PM, Juergen Sauermann wrote: > > Hi > > currently we have '*readlines*' in the wrapper function *FIO* which is > contained in the *FILE_IO* workspace. > > BTW the *FILE_IO* workspace, already contains this wrapper function *Z←L > FIO[X**]** R*, kindly provided by > Christian Robert, which calls *⎕FIO* with string *X* instead of numeric > axis argument *X*. > > Of course I forgot to add *FIO**∆**readlines* to the *FILE_IO *workspace. > > /// Jürgen > > > > On 01/27/2017 03:03 AM, Elias Mårtenson wrote: > > Thank you Jürgen. You make a compelling argument. > > In particular, I'd argue that the ⎕FIO[n] functions should be seen as an > internal implementation detail, and the “official” API as it were, should > be the wrapper functions. > > Speaking of which, ⎕FIO[49] needs a name in wslib5. Any suggestions? > > Regards, > Elias > > On 25 January 2017 at 19:57, Juergen Sauermann < > juergen.sauerm...@t-online.de> wrote: > >> Hi, >> >> there is nothing wrong with *⎕**ReadLines* as such. However, >> >> - if I remember correctly then in the 70s APL was very much loved by >> programmers that were >> not speaking English every day, in particular in France and Canada. >> >> - Every new ⎕ function requires quite some coding. The C-code that >> implements it has typically only a few lines >> because the function itself is normally already implemented somewhere in >> libstdio. Suppose you already have the >> implementation in, say, *{ CODE }*. >> >> Then making *{ CODE }* available as, say, *⎕FIO[N]* is currently simply >> a new case clause: >> >> * case **N**:** { CODE** }* >> >> For *⎕ReadLines* instead fo *⎕FIO[N]* you would need far more changes: >> >> - a new *Id* for it, >> - a new *Token* for it, >> - a new class, say *Quad_ReadLines* around *{ CODE }.* That also means >> two more source code >> files and therefore impacts in *src/Makefile.am* and *SVN* >> - write testcases for it, >> - write a *)HELP* entry >> - write documentation for it >> >> I am normally planning 3 days of (part-time) work for one new Quad >> Function. This would be 3×49 days >> for converting *⎕FIO* into different *⎕something* functions. And after >> that, you would have a good >> argument to ask why, for example *⎕CR* or *⎕SQL* are using numbers >> instead of names. >> >> So this is half a year of work on my side compared to a simple >> >> *)COPY 5 FILE_IO* >> >> where named wrapper functions for every *⎕FIO**[X]* already exist (and >> you can even change the names >> if you don't like them). >> >> /// Jürgen >> >> >> >> >> On 01/25/2017 05:54 AM, Elias Mårtenson wrote: >> >> Is there anything inherently wrong with having more quad-commands? What >> is the reason we have to do ⎕FIO[49] instead of simply ⎕ReadLines or >> something like that? >> >> It's like we're going out of way to make code unreadable. I know APL is >> all about terseness, but I think this is going too far. Am I alone in this? >> >> Regards, >> Elias >> >> On 25 January 2017 at 12:36, Christian Robert < >> christian.rob...@polymtl.ca> wrote: >> >>> In fact we should make all/most ⎕FIO[] in into parantheses >>> >>> things like this was working fine before ⎕FIO[49] >>> >>> fd← "r" ⎕fio[3] ".bashrc" >>> fd >>> 5 >>> ⊣ ⎕fio[4] fd >>> DOMAIN ERROR >>> ⊣⎕FIO[4]fd >>> ^ ^ >>> >>> well, I know now that I have to make it: >>> >>> ⊣ (⎕fio[4] fd) >>> >>> but it's a change into the previous behavior of ⎕FIO[]. It was not >>> trying to grab the left operator of ⎕fio[4] >>> >>> >>> Xtian. >>> >>> >>> On 2017-01-20 10:57, Juergen Sauermann wrote: >>> >>>> 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 >>>>>> >>>>>> >>>>> >>>> >> >> > > >