Sujet : Re: Parsing timestamps?
De : dxforth (at) *nospam* gmail.com (dxf)
Groupes : comp.lang.forthDate : 10. Jun 2025, 03:31:51
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <70a3014f99baf5e43b32e1320d7b8cd482be04c1@i2pn2.org>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : Mozilla Thunderbird
On 10/06/2025 6:00 am, LIT wrote:
...
Stack jugglery means wasting CPU cycles for
moving the bytes around - it's contrproductive.
Variables have been invented to be used. They're
useful, if you didn't notice, or if they didn't
tell you that in your college, or wherever.
Forth uses variables in the global sense and this works well.
Variables at the word level is often an indication something is
wrong. Locals users rarely justify on grounds of performance as
experience over the years has shown time and again well-written
stack code is both shorter and faster. The temptation is to
write one routine that does it all and this is where variables
and 'stack juggling' can sneak in. OTOH some implementations
are just neater and its a matter of finding them!
: HMS>SEC ( s m h -- ud ) 3600 um* 2swap 60 * + 0 d+ ;
\ Parse HH:MM:SS or free-form ref: sjack
: >HMS ( a u -- sec min hr )
2>r 0 0 0 2r> begin
/int 5 -roll rot drop dup while [char] : ?skip
repeat 2drop ;
\ Parse HMS string returning #csecs
: /HMS ( a u -- ud ) >hms hms>sec 100 mu* ;