SirWumpus / post4

Post4 is an indirect threaded Forth dialect written in C.
BSD 2-Clause "Simplified" License
4 stars 1 forks source link

`accept` is not compliant #62

Closed ruv closed 2 hours ago

ruv commented 1 day ago
  1. accept tries to receive a string from the input source instead of the user input device.
  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.

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.

SirWumpus commented 1 day 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
ruv commented 23 hours ago

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 🤔

SirWumpus commented 23 hours ago

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.

SirWumpus commented 23 hours ago
  1. 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?

ruv commented 23 hours ago

-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).

SirWumpus commented 20 hours ago

Q: Does REFILL use ACCEPT?

SirWumpus commented 19 hours ago

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$
ruv commented 14 hours ago

Q: Does REFILL use ACCEPT?

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.

SirWumpus commented 2 hours ago

Closing since you haven't reported any issues with the fixes for this.

ruv commented 1 hour ago

Yes, accept works as expected now!