Deutsch English Français Italiano |
<vedv35$6b05$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ruvim <ruvim.pinka@gmail.com> Newsgroups: comp.lang.forth Subject: Re: Number parsing with checks Date: Sat, 12 Oct 2024 17:54:45 +0400 Organization: A noiseless patient Spider Lines: 38 Message-ID: <vedv35$6b05$1@dont-email.me> References: <636c943eae41d9a5832ce5a94414cb81be04a44f@i2pn2.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 12 Oct 2024 15:54:46 +0200 (CEST) Injection-Info: dont-email.me; posting-host="029219deb48b7ec40bab467397e85d8f"; logging-data="207877"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hKjRru3WExhK4doQAIhbs" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:H4Nc5o6vX9Sbf6Puf8GjDDooOoQ= In-Reply-To: <636c943eae41d9a5832ce5a94414cb81be04a44f@i2pn2.org> Content-Language: en-US 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 ) > : ?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