Deutsch   English   Français   Italiano  
<nnd$16a55d5e$0e5ab22d@1d9c51e25014f149>

View for Bookmarking (what is this?)
Look up another Usenet article

Date: Mon, 9 Jun 2025 15:21:52 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Parsing timestamps?
Newsgroups: comp.lang.forth
References: <1f433fabcb4d053d16cbc098dedc6c370608ac01@i2pn2.org>
 <7e21117d37c506cccd8e79323c416fd1@www.novabbs.com>
 <1021bsd$31o0d$1@dont-email.me>
 <b5802b3faad00b9a4397e1e445561681d0cd6ce5@i2pn2.org>
 <6ced001912d95b520dad9d25a6014342@www.novabbs.com>
 <60ca19340523b1ddfa4a2cbf1ac0995cb185cdcb@i2pn2.org>
Content-Language: en-US
From: Hans Bezemer <the.beez.speaks@gmail.com>
In-Reply-To: <60ca19340523b1ddfa4a2cbf1ac0995cb185cdcb@i2pn2.org>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Message-ID: <nnd$16a55d5e$0e5ab22d@1d9c51e25014f149>
Organization: KPN B.V.
Path: ...!npeer.as286.net!npeer-ng0.as286.net!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!nntp.comgw.net!feed.abavia.com!abe004.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 67
Injection-Date: Mon, 09 Jun 2025 15:21:52 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2650
Bytes: 2777

On 08-06-2025 04:38, dxf wrote:
> On 8/06/2025 3:07 am, LIT wrote:
>> My solution is rather straightforward:
>>
>> 1 VARIABLE C6
>> 1 VARIABLE C1
>>
>> : TIMESTRSCAN ( addr count -- d )
>>   >R >R 0 0 R> R>
>>   OVER + 1-
>>   DO
>>     I C@ DUP 58 =
>>     IF
>>       DROP
>>       C6 @ 60 * C6 !
>>       1 C1 !
>>     ELSE
>>       48 - C1 @ * C6 @ M* D+
>>       10 C1 !
>>     THEN
>>   -1 +LOOP
>>   1 C6 !  1 C1 !
>> ;

First of all: are you an 8-bit hobbyist? I mean, you can convert 32-bit 
values close to 600,000 hours - that's a whopping 68 years - before you 
overflow this thing. Signed, that is.

Second, stamp out the variables! You use two globals for this trivial 
routine. This does the same thing:

: timescan
   over swap chars + >r 0 tuck begin
     over r@ <
   while
     over c@ [char] : =
     if rot + 60 * swap 0 else 10 * over c@ [char] 0 - + then
     swap char+ swap
   repeat r> drop nip +
;

And the beauty of CHAR is - less magic numbers in your code. But even if 
you are dedicated to using a double word accumulator, you won't need 
those variables:

: dtimescan
   over swap chars + >r >r 0. r> 0 begin
     over r@ <
   while
     over c@ [char] : =
     if
       swap >r s>d d+ 60 1 m*/ r> 0
     else
       10 * over c@ [char] 0 - +
     then
     swap char+ swap
   repeat r> drop nip s>d d+
;


Now - did I win anything? Maybe a T-shirt "May the Forth be with you"?

> Virtue is its own reward.

Hans Bezemer