Sujet : Re: Number parsing with checks
De : ruvim.pinka (at) *nospam* gmail.com (Ruvim)
Groupes : comp.lang.forthDate : 12. Oct 2024, 15:46:52
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vee24s$6b05$2@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
On 2024-10-12 17:54, Ruvim wrote:
On 2024-10-12 05:45, dxf wrote:
The basics:
>
: .BAD ( -- ) cr ." Invalid item" .abort ;
>
: ZE? ( x -- ) if .bad then ; \ abort if non-zero
: NZ? ( x -- ) 0= ze? ; \ abort if zero
Typically, if word name ends with a question mark, the first (top) output parameter of the word is a *flag*. And it's true for all standard words. (though, opposite is not true)
These are better names and narrower stack diagrams:
DROP-NZ ( x\0 -- | 0 -- never )
DROP-ZE ( 0 -- | x\0 -- never )
I do not like these names too.
These seem better:
?NZ-DROP
?ZE-DROP
: ?ZE ( x -- x ) dup ze? ; \ check x is zero
: ?NZ ( x -- x ) dup nz? ; \ check x is non-zero
Better stack diagrams:
?ZE ( 0 -- 0 | x\0 -- never )
?NZ ( x.some\0 -- x.some | 0 -- never )
I suggest to use the data type symbol "never" for the empty data type.
See my explanation about the empty data type at <https://github.com/ ForthHub/discussion/discussions/171#discussioncomment-10882259>
(this can be discussed there, or in a new thread here)
-- Ruvim