| Deutsch English Français Italiano |
|
<8f7bf4216fd15f1df2119232963da5f90e9a18b8@i2pn2.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: dxf <dxforth@gmail.com>
Newsgroups: comp.lang.forth
Subject: Re: Parsing timestamps?
Date: Wed, 30 Oct 2024 11:31:10 +1100
Organization: i2pn2 (i2pn.org)
Message-ID: <8f7bf4216fd15f1df2119232963da5f90e9a18b8@i2pn2.org>
References: <1f433fabcb4d053d16cbc098dedc6c370608ac01@i2pn2.org>
<vetsc2$3av44$1@dont-email.me>
<a8021708d18be9f53cfa1ab6a6627eaa03121612@i2pn2.org>
<nnd$20ac8605$11da13fb@384eaef047f1a2fb>
<a25af4abbaaa757b2f15306405b6c63d2981d81c@i2pn2.org>
<nnd$632dc57a$2ae5d913@8baf4544b88cb263>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 30 Oct 2024 00:31:13 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="74411"; mail-complaints-to="usenet@i2pn2.org";
posting-account="XPw7UV90Iy7EOhY4YuUXhpdoEf5Vz7K+BsxA/Cx8bVc";
User-Agent: Mozilla Thunderbird
Content-Language: en-GB
X-Spam-Checker-Version: SpamAssassin 4.0.0
In-Reply-To: <nnd$632dc57a$2ae5d913@8baf4544b88cb263>
Bytes: 2511
Lines: 37
On 30/10/2024 12:45 am, Hans Bezemer wrote:
> On 29-10-2024 10:25, dxf wrote:
>> On 29/10/2024 4:07 am, Hans Bezemer wrote:
>>> ...
>>> I have put the complication elsewhere. If we assume we're working in decimal, you don't even need >NUMBER:
>>>
>>> char 0 negate +constant 0-
>>>
>>> : /int ( a1 n1 -- a2 n2 n3)
>>> 0 >r 1 >r 1- chars over +
>>> begin
>>> over 1- over <
>>> while
>>> dup c@ is-digit
>>> while
>>> dup c@ 0- r> tuck * r> + >r 10 * >r 1-
>>> repeat over - rdrop r> -rot
>>> ;
>>> ...
>>
>> So that's how to convert a numeric string from the other end.
>> Nice! Easier than I imagined it would be.
>
> TORS is the multiplier, 2ORS is the accumulator. Normally, the multiplier is multiplied after each run with BASE @ - but that makes little sense when IS-DIGIT isn't properly adjusted. Would be a nice exercise, though.
Something like this...
\ \CHAR ( a u -- a u-1 c )
\ >DIGIT ( c base -- u -1 | c 0 )
: /INT ( a1 n1 -- a2 n2 u )
0 >r 1 begin >r dup while
\char base @ >digit while
r> tuck * r> + >r base @ *
repeat drop ( -1 /string) then rdrop r> ;
OTOH the necessity to convert R-L is probably rare.