Sujet : Re: May the numbers speak - supplement
De : melahi_ahmed (at) *nospam* yahoo.fr (ahmed)
Groupes : comp.lang.forthDate : 12. Jun 2025, 15:04:38
Autres entêtes
Organisation : novaBBS
Message-ID : <b2a9022a472e580c28007d91d7921d5d@www.novabbs.com>
References : 1 2 3 4 5 6 7 8
User-Agent : Rocksolid Light
On Thu, 12 Jun 2025 9:59:56 +0000, Paul Rubin wrote:
This version with the string in memory, no error checking, and using a
variable, seems simplest to me.
>
variable p
: advance ( -- ) 1 p +! ;
: digit ( -- n ) p @ c@ '0' - advance ;
: 2digit ( -- n ) digit 10 * digit + ;
: hms ( a u -- h m s ) drop p !
2digit advance 2digit advance 2digit advance ;
: test clearstack s" 12:34:56" hms ;
>
test .s
Hi,
Thanks for all the ideas.
What about this? is it clear, readable, ...?
I think it is the same as yours but use directly the return stack and
advance manually with subtracting 528 whihc is 48*10+48 where 48 is '0'.
: hms ( u n -- h m s)
drop >r
r@ c@ 10 * r@ 1+ c@ + 528 -
r@ 3 + c@ 10 * r@ 4 + c@ + 528 -
r@ 6 + c@ 10 * r@ 7 + c@ + 528 -
rdrop ;
s" 12:34:56" hms .s <3> 12 34 56 ok
Ahmed
--