Sujet : Re: Reverse SCAN SPLIT
De : dxforth (at) *nospam* gmail.com (dxf)
Groupes : comp.lang.forthDate : 07. Oct 2024, 13:13:53
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <d20baa2948b40b2043af3adc40a05054c82ad22e@i2pn2.org>
References : 1
User-Agent : Mozilla Thunderbird
On 7/10/2024 7:52 pm, 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 ;
Checking I see F-PC has -SCAN which appears to work similarly to SCAN< .
I'll be renaming my def's to -SCAN and -SPLIT respectively.