It seems the words SAVE-INPUT and RESTORE-INPUT are not quite useful.
They are like FILE-POSITION and REPOSITION-FILE, but they work for the current input source.
Did anybody use them in programs/libraries? (not in system internals)
I can only imagine their application in an interpretive loops
implementation.
It seems the words SAVE-INPUT and RESTORE-INPUT are not quite useful.
They are like FILE-POSITION and REPOSITION-FILE, but they work for the current input source.
Did anybody use them in programs/libraries? (not in system internals)
I can only imagine their application in an interpretive loops
implementation.
On 31/01/2023 22:47, Ruvim wrote:
It seems the words SAVE-INPUT and RESTORE-INPUT are not quite useful.
They are like FILE-POSITION and REPOSITION-FILE, but they work for the
current input source.
Did anybody use them in programs/libraries? (not in system internals)
I can only imagine their application in an interpretive loops
implementation. >>
They are useful if you want to scan the input source twice.
For example
in the ANS Forth implementation of closures and quotations that I did
some years ago. In a special colon definition the first pass executed SAVE-INPUT and stacked the input source data in a separate stack,
looking for various words to do with the closures. If nested, SAVE-INPUT again stacked the input source data.
At the end of each definition RESTORE-INPUT did just that from the
separate stack to compile the source in a second pass. This results in
the innermost definition being compiled first.
In the first version I saved the source text in a buffer before
realising that SAVE and RESTORE-INPUT were a better solution.
It is not much use where a keyboard is the input source as RESTORE-INPUT
is not guaranteed to work and, I suspect that most Forth systems don't
bother to save keyboard input.
It seems the words SAVE-INPUT and RESTORE-INPUT are not quite useful.
They are like FILE-POSITION and REPOSITION-FILE, but they work for the >current input source.
Did anybody use them in programs/libraries? (not in system internals)
I can only imagine their application in an interpretive loops
implementation.
Ruvim
In article <trc5pq$3vi3m$1@dont-email.me>,
Ruvim <ruvim.pinka@gmail.com> wrote:
It seems the words SAVE-INPUT and RESTORE-INPUT are not quite useful.
They are like FILE-POSITION and REPOSITION-FILE, but they work for the
current input source.
Did anybody use them in programs/libraries? (not in system internals)
I can only imagine their application in an interpretive loops
implementation.
Saving and restoring >IN is mostly enough.
I have redesigned SAVE-INPUT RESTORE-INPUT into SAVE and RESTORE
that tuck intermediate results on the return stack.
: EVALUATE SAVE SET-SRC 'INTERPRET CATCH RESTORE THROW ;
INCLUDED is approximately
: INCLUDED GET-FILE EVALUATE ;
So I use it all the time.
I supply SAVE-INPUT for others to use, no big deal:
: SAVE-INPUT SRC 2@ PP @ 3 ;
It comes in handy for EXECUTE-PARSING
: EXECUTE-PARSING ROT ROT SAVE SET-SRC CATCH RESTORE THROW ;
But a normal person would use
\ ( sc - ?? )
SAVE SET-SRC 'whatever CATCH RESTORE THROW ;
or even
SAVE SET-SRC whatever RESTORE
if you don't care about exceptions
(say you're doing a quick and dirty program for taxes.)
Bottom line I reject SAVE-INPUT as a reasonable internal.
On 2023-02-01 10:36, Gerry Jackson wrote:
On 31/01/2023 22:47, Ruvim wrote:
It seems the words SAVE-INPUT and RESTORE-INPUT are not quite useful.
They are like FILE-POSITION and REPOSITION-FILE, but they work for
the current input source.
Did anybody use them in programs/libraries? (not in system internals)
I can only imagine their application in an interpretive loops
implementation. >>
They are useful if you want to scan the input source twice.
I have just realized, they can be used instead of ">IN @ ... >IN !"
But they are more heavy internally.
OTOH, in many cases you don't need to deal with ">in" if you can employ "execute-parsing".
For example in the ANS Forth implementation of closures and quotations
that I did some years ago. In a special colon definition the first
pass executed SAVE-INPUT and stacked the input source data in a
separate stack, looking for various words to do with the closures. If
nested, SAVE-INPUT again stacked the input source data.
At the end of each definition RESTORE-INPUT did just that from the
separate stack to compile the source in a second pass. This results in
the innermost definition being compiled first.
In the first version I saved the source text in a buffer before
realising that SAVE and RESTORE-INPUT were a better solution.
I guess this solution is fragile about redefinitions/renames/wrappers,
e.g.:
: foo[ postpone [: ; immediate
: ]foo postpone ;] ; immediate
: bar foo[ ... ]foo ... ;
It is not much use where a keyboard is the input source as
RESTORE-INPUT is not guaranteed to work and, I suspect that most Forth
systems don't bother to save keyboard input.
Yes. It's technically possible, but after the first call of SAVE-INPUT
the system should save all keyboard (or stdin) input forever (till
process termination).
On 01/02/2023 12:42, Ruvim wrote:[...]
On 2023-02-01 10:36, Gerry Jackson wrote:
It is not much use where a keyboard is the input source as
RESTORE-INPUT is not guaranteed to work and, I suspect that most
Forth systems don't bother to save keyboard input.
Yes. It's technically possible, but after the first call of SAVE-INPUT
the system should save all keyboard (or stdin) input forever (till
process termination).
Wouldn't a definition ABORTing abandon saving of keyboard input or do
you consider that as 'process termination'?
What about the value returned by KEY?
On 01/02/2023 12:42, Ruvim wrote:
On 2023-02-01 10:36, Gerry Jackson wrote:
On 31/01/2023 22:47, Ruvim wrote:
It seems the words SAVE-INPUT and RESTORE-INPUT are not quite useful.
They are like FILE-POSITION and REPOSITION-FILE, but they work for
the current input source.
Did anybody use them in programs/libraries? (not in system internals)
I can only imagine their application in an interpretive loops
implementation. >>
They are useful if you want to scan the input source twice.
I have just realized, they can be used instead of ">IN @ ... >IN !"
But they are more heavy internally.
OTOH, in many cases you don't need to deal with ">in" if you can employ
"execute-parsing".
For example in the ANS Forth implementation of closures and quotations
that I did some years ago. In a special colon definition the first
pass executed SAVE-INPUT and stacked the input source data in a
separate stack, looking for various words to do with the closures. If
nested, SAVE-INPUT again stacked the input source data.
At the end of each definition RESTORE-INPUT did just that from the
separate stack to compile the source in a second pass. This results in
the innermost definition being compiled first.
In the first version I saved the source text in a buffer before
realising that SAVE and RESTORE-INPUT were a better solution.
I guess this solution is fragile about redefinitions/renames/wrappers,
e.g.:
: foo[ postpone [: ; immediate
: ]foo postpone ;] ; immediate
: bar foo[ ... ]foo ... ;
Yes it is a limitation of the program that it cannot handle immediate
user defined parsing words such as your FOO[ inside a colon definition.
It can handle standard parsing words such as POSTPONE S" etc, and
comments but not [IF] etc and DOES> where it aborts. These are
documented as restrictions.
But it could still pass Knuth's Man or Boy test as a man.
It is not much use where a keyboard is the input source as
RESTORE-INPUT is not guaranteed to work and, I suspect that most Forth
systems don't bother to save keyboard input.
Yes. It's technically possible, but after the first call of SAVE-INPUT
the system should save all keyboard (or stdin) input forever (till
process termination).
Wouldn't a definition ABORTing abandon saving of keyboard input or do
you consider that as 'process termination'? What about the value
returned by KEY?
--
Gerry
On 01/02/2023 12:42, Ruvim wrote:[...]
On 2023-02-01 10:36, Gerry Jackson wrote:
It is not much use where a keyboard is the input source as
RESTORE-INPUT is not guaranteed to work and, I suspect that most
Forth systems don't bother to save keyboard input.
Yes. It's technically possible, but after the first call of SAVE-INPUT
the system should save all keyboard (or stdin) input forever (till
process termination).
Wouldn't a definition ABORTing abandon saving of keyboard input or do
you consider that as 'process termination'?
I mean the keyboard as far as it's the user input device that is the
input source. For example, in a case of an interactive session.
I think, it should not save keyboard events, but only characters that
are read by REFILL under the hood.
This can be schematically represented as:
keyboard ==> the user input device ==> the input source ==> refill
Or, in a case of input from a file:
the file ==> the input source ==> refill
But in the case of a file there is no need to save the characters since
the file read position can be changed back (as well as the content of
the input buffer and ">IN").
By process termination I mean the action of BYE (or alike).
When ABORT is performed, and it's not caught (by CATCH), you can still >perform RESTORE-INPUT (or another word that calls this one)
interactively, even several times. So the saved characters cannot be >abandoned.
What about the value returned by KEY?
KEY (and ACCEPT) does not read the input source, but the user input device.
RESTORE-INPUT does reposition of the input source. I think, it should
not affect the user input device, and hence it should not affect KEY.
--
Ruvim
My take on it is that ABORT is a system restart. Implementing ABORTI tend to agree with you. If you want to leave, leave. If you want to think about
via a THROW is an abomination. If you want THROW , you know where to
find them.
Implementing endless layers of recovery serves no purpose. The
certainty that you have a word that kills and restarts trustworthy
everything going on, is on the other hand eminently useful. Don't use
it if you don't want that.
There isn't ever needed a REFILL except for the terminal input bufferHere we differ. In 4tH, if you want to read chunks of raw data, you use
aptly named REFILL-TIB. It reads a line from the terminal,
approximately READ-FILE from standard in.
Nowadays REFILL is only used to interpret a source file line by line.
So lina has to supply them as a loadable extension, but otherwise
has no employment for it.
On Thursday, February 2, 2023 at 12:22:52 PM UTC+1, none albert wrote:
There isn't ever needed a REFILL except for the terminal input bufferHere we differ. In 4tH, if you want to read chunks of raw data, you use >ACCEPT. REFILL reads lines.
aptly named REFILL-TIB. It reads a line from the terminal,
approximately READ-FILE from standard in.
Nowadays REFILL is only used to interpret a source file line by line.
So lina has to supply them as a loadable extension, but otherwise
has no employment for it.
But note that 4tH has a vastly different file mechanism. Each input or
output word (yes, even TYPE, . or .") can write to an output file. If you >open a file in 4tH, you've opened a stream. The word USE connects this
stream to (depending HOW you opened it) the input and/or the output
channel.
Therefore, there is no distinction between text or binary mode. Treat it like >a text file (e.g. by using REFILL) and it is a text file.
Treat it like a binary file
(e.g. by using ACCEPT) and it is a binary file.
Consequently, it is trivial to define the ANS FILE wordset in 4tH, but almost >impossible to implement 4tHs way of handling files in ANS.
Hans BezemerGroetjes Albert
It seems the words SAVE-INPUT and RESTORE-INPUT are not quite useful.
They are like FILE-POSITION and REPOSITION-FILE, but they work for the current input source.
Did anybody use them in programs/libraries? (not in system internals)
On 2023-01-31 22:47, Ruvim wrote:
It seems the words SAVE-INPUT and RESTORE-INPUT are not quite useful.
They are like FILE-POSITION and REPOSITION-FILE, but they work for the
current input source.
Did anybody use them in programs/libraries? (not in system internals)
Don't you think these words can be destandardized due to their little >usefulness?
What is a better API to replace them?
--
Ruvim
In article <trmbli$23fon$1@dont-email.me>,
Ruvim <ruvim.pinka@gmail.com> wrote:
On 2023-01-31 22:47, Ruvim wrote:
It seems the words SAVE-INPUT and RESTORE-INPUT are not quite useful.
They are like FILE-POSITION and REPOSITION-FILE, but they work for the
current input source.
Did anybody use them in programs/libraries? (not in system internals)
Don't you think these words can be destandardized due to their little
usefulness?
What is a better API to replace them?
You don't mean FILE-POSITION and REPOSITION-FILE , I hope?
On 2023-01-31 22:47, Ruvim wrote:
It seems the words SAVE-INPUT and RESTORE-INPUT are not quite useful.
They are like FILE-POSITION and REPOSITION-FILE, but they work for the current input source.
Did anybody use them in programs/libraries? (not in system internals)
Don't you think these words can be destandardized due to their little usefulness?
What is a better API to replace them?
On 5/02/2023 6:28 am, Ruvim wrote:
On 2023-01-31 22:47, Ruvim wrote:
It seems the words SAVE-INPUT and RESTORE-INPUT are not quite useful.
They are like FILE-POSITION and REPOSITION-FILE, but they work for
the current input source.
Did anybody use them in programs/libraries? (not in system internals)
Don't you think these words can be destandardized due to their little
usefulness?
What is a better API to replace them?
If those words have little use, then what is the case for replacing them?
On 2023-02-05 03:48, dxforth wrote:
On 5/02/2023 6:28 am, Ruvim wrote:
On 2023-01-31 22:47, Ruvim wrote:
It seems the words SAVE-INPUT and RESTORE-INPUT are not quite useful.
They are like FILE-POSITION and REPOSITION-FILE, but they work for
the current input source.
Did anybody use them in programs/libraries? (not in system internals)
Don't you think these words can be destandardized due to their little
usefulness?
What is a better API to replace them?
If those words have little use, then what is the case for replacing them?
If a reason of little use is their inconvenient API.
On 05/02/2023 12:49, Ruvim wrote:
On 2023-02-05 03:48, dxforth wrote:
On 5/02/2023 6:28 am, Ruvim wrote:
On 2023-01-31 22:47, Ruvim wrote:
It seems the words SAVE-INPUT and RESTORE-INPUT are not quite useful. >>>>>Don't you think these words can be destandardized due to their
They are like FILE-POSITION and REPOSITION-FILE, but they work for
the current input source.
Did anybody use them in programs/libraries? (not in system internals) >>>>
little usefulness?
What is a better API to replace them?
If those words have little use, then what is the case for replacing
them?
If a reason of little use is their inconvenient API.
What is their inconvenient API? It seems ok to me.
Before words get
removed from the standard their use should be deprecated for some years
to enable users to adjust to their absence.
You should not regard response on comp.lang.forth as covering all Forth programmers. I think many people are driven away by the toxic posters we have.
On 05/02/2023 12:49, Ruvim wrote:
On 2023-02-05 03:48, dxforth wrote:
On 5/02/2023 6:28 am, Ruvim wrote:
On 2023-01-31 22:47, Ruvim wrote:
It seems the words SAVE-INPUT and RESTORE-INPUT are not quite useful. >>>>>Don't you think these words can be destandardized due to their little usefulness?
They are like FILE-POSITION and REPOSITION-FILE, but they work for the current input source.
Did anybody use them in programs/libraries? (not in system internals) >>>>
What is a better API to replace them?
If those words have little use, then what is the case for replacing them? >>>
If a reason of little use is their inconvenient API.
What is their inconvenient API? It seems ok to me. Before words get removed from the standard their use should be deprecated for some years to enable users to adjust to their absence.
You should not regard response on comp.lang.forth as covering all Forth programmers. I think many people are driven away by the toxic posters we have.
On 6/02/2023 12:02 am, Gerry Jackson wrote:
What is their inconvenient API? It seems ok to me. Before words get removed from the standard their use should be deprecated for some years to enable users to adjust to their absence.
The last release was 2012 so that would seem to cover it.
Unless I'm mistaken 200x is required to conduct discussions through c.l.f.
dxforth <dxforth@gmail.com> writes:
...
Unless I'm mistaken 200x is required to conduct discussions through c.l.f.
Not any longer. All online discussions are on forth-standard.org. If
I do a proposal of wider interest, I usually post a pointer here,
however.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 475 |
Nodes: | 16 (2 / 14) |
Uptime: | 18:25:38 |
Calls: | 9,487 |
Calls today: | 6 |
Files: | 13,617 |
Messages: | 6,121,091 |