⎕nread vs. ]snap

General APL language issues

⎕nread vs. ]snap

Postby rbe on Fri Mar 15, 2019 5:19 pm

I am fairly happily using ]snap to save APL source text as .dyalog files.
However, I have a problem:

The .dyalog file looks fine with cat and vi, under Ubuntu 18.04LTS.
It also works fine with ]load.
I am unable to read the file into APL as readable text, using ⎕nread.
I tried several conversion codes, with no joy, and also tried a
(⍳256)⎕nxlate ntn, which did not help either.

If I use ⎕nget, it works okay, e.g.:

Logistic←{ ⍝ Sigmoid
÷1+(-⍵}

UTF-8-NOBOM
10

but I still want to know how to make it work with ⎕nread.

Thanks,
Bob
rbe
 
Posts: 8
Joined: Fri Apr 13, 2018 7:55 pm

Re: ⎕nread vs. ]snap

Postby Phil Last on Fri Mar 15, 2019 9:55 pm

If you have ⎕NGET but want to use ⎕NREAD I guess you want it also to work in versions of Dyalog prior to v15.0 when ⎕NGET was introduced.
      ⎕cr'nget'
nget←{enc←'UTF-8' ⋄ LF CR BOM←⎕UCS 10 13 65279
dec←{CR LF(1↓¨∊⍨⊂⊢)CR,{⍵~BOM,LF/⍨CR∊⍵}enc ⎕UCS ⎕UCS ⍵}
{⍵↓⍨-0∊⍴⊃⌽⍵}dec(⎕NUNTIE⊢(⎕NREAD⊢,80,⎕NSIZE))⍵ ⎕NTIE 0
}
This wasn't written specifically for reading SALT files but reads files written by ⎕NPUT and works for me back as far as v14.0 with line-ends CR, LF and CRLF and expects ⎕ML<2. Not tested before v14.0. Syntax is just:
      res ← nget path
and the result is a list of strings. The removal of an empty string from the end - {⍵↓⍨-0∊⍴⊃⌽⍵} - is because of the possibility that the file might or might not have a trailing line-end.
User avatar
Phil Last
 
Posts: 514
Joined: Thu Jun 18, 2009 6:29 pm

Re: ⎕nread vs. ]snap

Postby rbe on Mon May 27, 2019 9:32 pm

Just to close off this thread, I ended up using ⎕map, which works just dandy,
despite ⎕map being, IMO, a dreadful name for mmap(): Hard to find if you don't know
where to look; you don't know what it is mapping
until you find the docs, and the docs don't seem to have logical groupings for
some functions, e.g., native files, ⎕map, etc., so I can't find memory
map stuff in the index or table of contents...
rbe
 
Posts: 8
Joined: Fri Apr 13, 2018 7:55 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest