Re: Reverse SCAN SPLIT

Liste des GroupesRevenir à cl forth 
Sujet : Re: Reverse SCAN SPLIT
De : dxforth (at) *nospam* gmail.com (dxf)
Groupes : comp.lang.forth
Date : 10. Oct 2024, 10:57:43
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <84a43479460314388420efa02405b006aea1677b@i2pn2.org>
References : 1 2
User-Agent : Mozilla Thunderbird
On 10/10/2024 7:00 pm, albert@spenarnc.xs4all.nl wrote:
In article <5c65a8f1fdfc3e9937a825842fe23dc2758f48ef@i2pn2.org>,
dxf  <dxforth@gmail.com> 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 ;
 
Compare that with the meticulously designed, exhaustedly specified
and eminently useful -- $/ -- .
After 40 years it has not taken over the world ...
 
NAME: $/
 
STACKEFFECT: sc c --- sc1 sc2
 
DESCRIPTION: []
 
Find the first c in the string constant sc and split it at that
address. Return the strings after and before c into sc1 and sc2
respectively. If the character is not present sc1 is a null string
(its address is zero) and sc2 is the original string. Both sc1 and sc2
may be empty strings (i.e. their count is zero), if c is the last or
first character in sc .
(sc is c-addr len )
 
 
The subtle difference between an empty string (a-add 0 ) and
a null-string ( 0 0 ) allows you to handle empty lines in a file
gracefully.
 
 
>
\ 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 ;
 
If you go for SPLIT< from end define SCAN< .
I have named it $\
...

I wasn't aware you had reverse split.
I was coming to the conclusion SCAN< as I defined it was of little
value on it's own and planned to subsume it into reverse split.
OTOH a reverse SCAN that gave the same results as forward SCAN might
be useful.

Get the name of an executable from the source file:
"aap.frt" &. $\ 2DROP TYPE
aap OK

I didn't need it for CP/M or DOS but separating filename from filetype
in Windows would be easier when scanned from the end.


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