Re: Reverse SCAN SPLIT

Liste des GroupesRevenir à cl forth 
Sujet : Re: Reverse SCAN SPLIT
De : ruvim.pinka (at) *nospam* gmail.com (Ruvim)
Groupes : comp.lang.forth
Date : 07. Oct 2024, 11:02:05
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <ve0bit$1lo0q$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 2024-10-07 12:52, dxf wrote:
Earlier I mentioned scanning in reverse.  Here's an implementation.
 [undefined] dxforth [if]
: \CHAR ( a u -- a2 u2 c )  1- 2dup + c@ ;
[then]
 \ As for SCAN but scan from end
: SCAN< ( a u c -- a2 u2 | a 0 )
   >r over swap begin dup while \char r@ = until 1+ then
   rot drop rdrop ;
 \ As for SPLIT but scan from end. Latter string is topmost.
: SPLIT< ( a u c -- a2 u2 a3 u3 )
   >r 2dup r> scan< 2swap 2 pick /string ;
 \ example
 : /T ( a u -- hour min sec )
   3 0 do
     [char] : split<  0 0 2swap >number 2drop drop  -rot
     ( u ... a u)  dup if  1-  then
   loop 2drop  swap rot ;
                  ^^^^^^^^    (1)
 : T  /t  cr  rot . ." hr "  swap . ." min " . ." sec " ;
                ^^^            ^^^^   (2)
Why do you prefer the order ( u.hour u.min u.sec ) rather than ( u.sec u.min u.hour ) ?
The later order makes code simpler in (1) and (2), also, it follows the order of parameters in `TIME&DATE`.
Moreover, if you want to convert three components to seconds, you need to reverse their order again:
: time3-to-seconds ( u.hour u.min u.sec -- u.sec-total )
   swap rot  60 * + 60 * +
;
If the order of parameters is reversed, the above definition takes a simpler form:
: time3-to-seconds ( u.sec u.min u.hour -- u.sec-total )
   60 * + 60 * +
;
--
Ruvim

Date Sujet#  Auteur
7 Oct 24 * Reverse SCAN SPLIT18dxf
7 Oct 24 +* Re: Reverse SCAN SPLIT6Ahmed
7 Oct 24 i`* Re: Reverse SCAN SPLIT5Ahmed
7 Oct 24 i `* Re: Reverse SCAN SPLIT4dxf
7 Oct 24 i  `* Re: Reverse SCAN SPLIT3Ahmed
8 Oct 24 i   `* Re: Reverse SCAN SPLIT2dxf
8 Oct 24 i    `- Re: Reverse SCAN SPLIT1Ahmed
7 Oct 24 +* Re: Reverse SCAN SPLIT2Ruvim
7 Oct 24 i`- Re: Reverse SCAN SPLIT1dxf
7 Oct 24 +- Re: Reverse SCAN SPLIT1dxf
10 Oct 24 +- Re: Reverse SCAN SPLIT1dxf
10 Oct 24 `* Re: Reverse SCAN SPLIT7albert
10 Oct 24  `* Re: Reverse SCAN SPLIT6dxf
17 Oct 24   +- Re: Reverse SCAN SPLIT1minforth
17 Oct 24   `* Re: Reverse SCAN SPLIT4mhx
18 Oct 24    +- Re: Reverse SCAN SPLIT1dxf
18 Oct 24    `* Re: Reverse SCAN SPLIT2dxf
19 Oct 24     `- Re: Reverse SCAN SPLIT1albert

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal