Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 43 |
Nodes: | 6 (0 / 6) |
Uptime: | 94:26:42 |
Calls: | 290 |
Calls today: | 1 |
Files: | 904 |
Messages: | 76,378 |
On 17/10/2024 9:48 pm, albert@spenarnc.xs4all.nl wrote:Realize that
In article <73ec4c8359439c78d77d4fce31fc50b2@www.novabbs.com>,
mhx <mhx@iae.nl> wrote:
On Thu, 17 Oct 2024 8:28:26 +0000, albert@spenarnc.xs4all.nl wrote:
In article <nnd$231969a2$24a04042@87f25e33f755b9dd>,[..]
Compare to what I'm doing. Promoting the actual API specification
so that you can decide whether you want to actually use it.
$/
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 .
Wil Baden chose to keep c in sc2. Do you have a reason to
remove it?
It seems logical to remove it. I normally use lots of
`1 /STRING' and `-LEADING' or `-TRAILING' sequences in further
processing of Split-At-Char results, but not always.
Maybe because an empty sc2 is less informative than an sc2 of
size 1?
In the rare case that you want the delimiter :
"orang utan" BL $/
( *utan" "orang" )
you simply do
1+
( *utan" "orang " )
Applying 1+ is not foolproof in the case of empty sc2.
Interesting. I'd do the numeric conversion in the main routine if
possible.
There's a parsing issue with s" :30"
swap dup -rot --> over
But "5" needs to work :)
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+ thenrot 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 ;
On 10-10-2024 11:57, dxf wrote:
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.
I got a full load of the whole shebang - since I have to parse some
crazy stuff sometimes. It may not be pretty, but it served me well
through the years (since 2004).
Basically I can scan whatever I like however I like it:
---8<---
: (NO) NOT ;
: (YES) ;
defer is-type ( c -- f)
: (-tokenize) ( a1 n2 xt -- a2 n2 )
is ?not begin dup while 2dup 1- chars + c@ is-type ?not while 1- repeat
;
( a1 n2 xt -- a2 n2)
: (tokenize) is ?not begin dup while over c@ is-type ?not while chop
repeat ;
: scan> ['] (no) (tokenize) ; ( a1 n1 -- a2 n2 )
: scan< ['] (no) (-tokenize) ; ( a1 n1 -- a2 n2 )
: skip> ['] (yes) (tokenize) ; ( a1 n1 -- a2 n2 )
: skip< ['] (yes) (-tokenize) ; ( a1 n1 -- a2 n2 )
: split> 2dup scan> 2swap >r over r> swap - ;
: split< dup >r scan< 2dup chars + -rot r> over - -rot ;
( a1 n1 -- a2 n2 a3 n3)
---8<---
It's still 4tH stuff so your mileage may vary.
Hans Bezemer
On Thu, 17 Oct 2024 8:28:26 +0000, albert@spenarnc.xs4all.nl wrote:
In article <nnd$231969a2$24a04042@87f25e33f755b9dd>,[..]
Compare to what I'm doing. Promoting the actual API specification
so that you can decide whether you want to actually use it.
$/
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 .
Wil Baden chose to keep c in sc2. Do you have a reason to
remove it?
It seems logical to remove it. I normally use lots of
`1 /STRING' and `-LEADING' or `-TRAILING' sequences in further
processing of Split-At-Char results, but not always.
Maybe because an empty sc2 is less informative than an sc2 of
size 1?
-marcel
In article <nnd$231969a2$24a04042@87f25e33f755b9dd>,[..]
Compare to what I'm doing. Promoting the actual API specification
so that you can decide whether you want to actually use it.
$/
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 .