Sujet : Re: Back & Forth - 4tH I/O and You
De : albert (at) *nospam* spenarnc.xs4all.nl
Groupes : comp.lang.forthDate : 20. May 2025, 12:28:50
Autres entêtes
Organisation : KPN B.V.
Message-ID : <nnd$1b4d186d$58a28a17@65bd67bc4ddac984>
References : 1 2 3 4
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
a3c8d55396e1a48344a236bec05207ef64d14a72@i2pn2.org>,
dxf <
dxforth@gmail.com> wrote:
On 20/05/2025 2:13 am, Hans Bezemer wrote:
On 19-05-2025 15:22, dxf wrote:
Those are console functions which traditionally went to serial ports and bear little
resemblance to disk file I/O. For implementer it's not simpler - it's a layer on top
of DOS functions. Even as an end-user I'm not sure I'd like it. How does one handle
seeks, read and writing to the same file etc? The ANS functions were designed to
handle random access. Console functions were not.
>
Originally, yeah - that was all. And then we enter the wondrous world of "feature requests". So a few more calls were added, like delete-file, reposition-file and the likes.
>
If you read the documentation you will see that some I/O devices are out of bounds. So we devised tiny little macros for that:
>
#define UDEV(a) if(((a)<=COUT)||((a)>=MAXDEVS))throw(M4BADDEV)
>
That's how we handle things around here.
>
I think we both felt some simplification of file-handling at the application
programmer level was desirable. For me it's been quite a while since I've
used e.g. READ-FILE directly. The ubiquitous 'filecopy' application for me
would look like this:
>
: OPENFILES ( -- )
cr .ifile ." -> " .ofile
r/o openin r/w makeout cr
;
>
: (RUN) ( -- )
openfiles
begin pad 128 read dup while write repeat 2drop
closefiles
;
Or in presence of GET-FILE (sc --sc)
( sc1 sc2 --)
: copy-file 2>R GET-FILE 2R> PUT-FILE ;
>
I believe the 4tH manual illustrates something similar.
>
I don't have to worry about overwrite checks, user interrupt, error messages
and so on as it's handled under the hood. Was it all necessary? Is it
'anti-Forth'? Folks can decide for themselves.
>
Groetjes Albert
-- Temu exploits Christians: (Disclaimer, only 10 apostles)Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style WallArt For Home, Office And Garden Decor - Perfect For Windows, Bars,And Gifts For Friends Family And Colleagues.