Closed ruv closed 2 hours ago
2. If the EOF is reached, `accept ( c-addr n1 -- n2 )` returns `-1`, while it shall either return a number n2, 0 ≤ n2 ≤ n1, or throw an exception.
How is EOF meant to be returned? C's EOF macro equals -1.
For example, if your enter interactively:
s" cr pad 80 accept" evaluate .
it immediately prints -1. But it shall wait for the user's input.
elf$ ./post4
ok s" cr pad 80 accept" evaluate .
-1 ok
How is EOF meant to be returned?
accept
cannot return EOF by design. Typically it is implemented to throw an exception if EOF is reached before any character is received.
BTW, Gforth uses throw code -56 for that case 🤔
How is EOF meant to be returned?
accept
cannot return EOF by design. Typically it is implemented to throw an exception if EOF is reached before any character is received.
Whisky Tango Foxtrot! No EOF by design? Ewww. But I never thought to throw on EOF. That would work IMO.
BTW, Gforth uses throw code -56 for that case 🤔
-56? QUIT? Oh that sounds very very evil. I would have thought -39 would be the correct choice.
- accept tries to receive a string from the input source instead of the user input device.
I've been putting off this part, cause I'm sure I won't like it. BUT. Why not the input source?
-56? QUIT? Oh that sounds very very evil. I would have thought -39 would be the correct choice.
Probably it was simply a mistake that the throw code -56 was associated with the word QUIT
, and the code -56 was indented for the signal SIGQUIT. Then, it makes sense. Because the word QUIT
cannot be called by a throw code by design.
I've been putting off this part, cause I'm sure I won't like it. BUT. Why not the input source?
My implementation of a similar word does not work in Post4. To use accept
for debugging, it must read from the user input device (i.e., stdin).
Q: Does REFILL
use ACCEPT
?
Works more as expected, but I'm sure you'll find something:
elf$ ./post4
ok s" pad /pad accept" evaluate .
It slices! It dices! it makes Julian fries.
43 ok
ok
elf$
Q: Does
REFILL
useACCEPT
?
When the input source is the user input device REFILL
can use (call) ACCEPT
, otherwise — no.
QUIT
can use REFILL
because it makes the user input device the input source at the first.
Closing since you haven't reported any issues with the fixes for this.
Yes, accept
works as expected now!
accept
tries to receive a string from the input source instead of the user input device.accept ( c-addr n1 -- n2 )
returns-1
, while it shall either return a number n2, 0 ≤ n2 ≤ n1, or throw an exception.For example, if your enter interactively:
it immediately prints -1. But it shall wait for the user's input.