Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.forth    |    Forth programmers eat a lot of Bratwurst    |    117,927 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 116,853 of 117,927    |
|    Ruvim to dxf    |
|    Re: Reverse SCAN SPLIT    |
|    07 Oct 24 14:02:05    |
      From: ruvim.pinka@gmail.com              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              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca