Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #132413

Re: Reverse SCAN SPLIT

From Ruvim <ruvim.pinka@gmail.com>
Newsgroups comp.lang.forth
Subject Re: Reverse SCAN SPLIT
Date 2024-10-07 14:02 +0400
Organization A noiseless patient Spider
Message-ID <ve0bit$1lo0q$1@dont-email.me> (permalink)
References <5c65a8f1fdfc3e9937a825842fe23dc2758f48ef@i2pn2.org>

Show all headers | View raw


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

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Reverse SCAN SPLIT dxf <dxforth@gmail.com> - 2024-10-07 19:52 +1100
  Re: Reverse SCAN SPLIT melahi_ahmed@yahoo.fr (Ahmed) - 2024-10-07 09:55 +0000
    Re: Reverse SCAN SPLIT melahi_ahmed@yahoo.fr (Ahmed) - 2024-10-07 10:03 +0000
      Re: Reverse SCAN SPLIT dxf <dxforth@gmail.com> - 2024-10-07 23:07 +1100
        Re: Reverse SCAN SPLIT melahi_ahmed@yahoo.fr (Ahmed) - 2024-10-07 19:25 +0000
          Re: Reverse SCAN SPLIT dxf <dxforth@gmail.com> - 2024-10-08 13:58 +1100
            Re: Reverse SCAN SPLIT melahi_ahmed@yahoo.fr (Ahmed) - 2024-10-08 06:02 +0000
  Re: Reverse SCAN SPLIT Ruvim <ruvim.pinka@gmail.com> - 2024-10-07 14:02 +0400
    Re: Reverse SCAN SPLIT dxf <dxforth@gmail.com> - 2024-10-07 22:22 +1100
  Re: Reverse SCAN SPLIT dxf <dxforth@gmail.com> - 2024-10-07 23:13 +1100
  Re: Reverse SCAN SPLIT dxf <dxforth@gmail.com> - 2024-10-10 17:00 +1100
  Re: Reverse SCAN SPLIT albert@spenarnc.xs4all.nl - 2024-10-10 10:00 +0200
    Re: Reverse SCAN SPLIT dxf <dxforth@gmail.com> - 2024-10-10 20:57 +1100
      Re: Reverse SCAN SPLIT Hans Bezemer <the.beez.speaks@gmail.com> - 2024-10-16 18:13 +0200
        Re: Reverse SCAN SPLIT albert@spenarnc.xs4all.nl - 2024-10-17 10:28 +0200
          Re: Reverse SCAN SPLIT minforth@gmx.net (minforth) - 2024-10-17 09:16 +0000
          Re: Reverse SCAN SPLIT mhx@iae.nl (mhx) - 2024-10-17 10:29 +0000
            Re: Reverse SCAN SPLIT albert@spenarnc.xs4all.nl - 2024-10-17 12:48 +0200
              Re: Reverse SCAN SPLIT dxf <dxforth@gmail.com> - 2024-10-19 01:41 +1100
                Re: Reverse SCAN SPLIT albert@spenarnc.xs4all.nl - 2024-10-19 13:36 +0200
            Re: Reverse SCAN SPLIT dxf <dxforth@gmail.com> - 2024-10-18 12:10 +1100

csiph-web