Re: Parsing timestamps?

Liste des GroupesRevenir à cl forth 
Sujet : Re: Parsing timestamps?
De : dxforth (at) *nospam* gmail.com (dxf)
Groupes : comp.lang.forth
Date : 30. Oct 2024, 01:31:10
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <8f7bf4216fd15f1df2119232963da5f90e9a18b8@i2pn2.org>
References : 1 2 3 4 5 6
User-Agent : Mozilla Thunderbird
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.


Date Sujet#  Auteur
6 Oct 24 * Parsing timestamps?45dxf
6 Oct 24 +* Re: Parsing timestamps?8mhx
6 Oct 24 i+* Re: Parsing timestamps?3dxf
6 Oct 24 ii`* Re: Parsing timestamps?2dxf
7 Oct 24 ii `- Re: Parsing timestamps?1dxf
7 Jun13:38 i`* Re: Parsing timestamps?4B. Pym
7 Jun15:36 i `* Re: Parsing timestamps?3dxf
7 Jun18:07 i  `* Re: Parsing timestamps?2LIT
8 Jun03:38 i   `- Re: Parsing timestamps?1dxf
6 Oct 24 +* Re: Parsing timestamps?5Ruvim
6 Oct 24 i`* Re: Parsing timestamps?4dxf
6 Oct 24 i `* Re: Parsing timestamps?3Ruvim
6 Oct 24 i  +- Re: Parsing timestamps?1Ruvim
6 Oct 24 i  `- Re: Parsing timestamps?1Ruvim
6 Oct 24 +* Re: Parsing timestamps?6FFmike
6 Oct 24 i`* Re: Parsing timestamps?5FFmike
7 Oct 24 i `* Re: Parsing timestamps?4dxf
7 Oct 24 i  `* Re: Parsing timestamps?3FFmike
7 Oct 24 i   `* Re: Parsing timestamps?2dxf
7 Oct 24 i    `- Re: Parsing timestamps?1FFmike
6 Oct 24 +* Re: Parsing timestamps?2Anthony Howe
7 Oct 24 i`- Re: Parsing timestamps?1dxf
7 Oct 24 +* Re: Parsing timestamps?9albert
7 Oct 24 i`* Re: Parsing timestamps?8dxf
7 Oct 24 i `* Re: Parsing timestamps?7sjack
8 Oct 24 i  `* Re: Parsing timestamps?6dxf
8 Oct 24 i   +* Re: Parsing timestamps?3Ahmed
8 Oct 24 i   i+- Re: Parsing timestamps?1dxf
8 Oct 24 i   i`- Re: Parsing timestamps?1sjack
8 Oct 24 i   `* Re: Parsing timestamps?2sjack
9 Oct 24 i    `- Re: Parsing timestamps?1dxf
8 Oct 24 +* Re: Parsing timestamps?3albert
8 Oct 24 i`* Re: Parsing timestamps?2dxf
8 Oct 24 i `- Re: Parsing timestamps?1Ahmed
9 Oct 24 +* Re: Parsing timestamps?4alaa
10 Oct 24 i+* Re: Parsing timestamps?2dxf
10 Oct 24 ii`- Re: Parsing timestamps?1alaa
16 Oct 24 i`- Re: Parsing timestamps?1Hans Bezemer
18 Oct 24 `* Re: Parsing timestamps?7Gerry Jackson
19 Oct 24  `* Re: Parsing timestamps?6dxf
28 Oct 24   `* Re: Parsing timestamps?5Hans Bezemer
29 Oct 24    `* Re: Parsing timestamps?4dxf
29 Oct 24     `* Re: Parsing timestamps?3Hans Bezemer
30 Oct 24      `* Re: Parsing timestamps?2dxf
31 Oct 24       `- Re: Parsing timestamps?1dxf

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal