It seems there exist several versions of SUBSTITUTE
1) Is the version at
http://www.forth200x.org/text-substitution.txt still right?
2) gForth uses an other version which seems to be Forth-2012
but not the same as described at forth200x.
Next follows a test code.
Most important is the difference at the test of %5b1%mac2
How should substitute behave?
The test code is:
cr cr .( Extra tests for Substitute ) cr
\ needs _200xSubstitute.f \ See below
: .before ( adr1 n1 adr2 n2 - adr1 n1 adr2 n2 )
2over type ." + " 2dup type ." Stubstitute --> " ;
: .result ( adr len RESn - adr len ) .s drop type ;
cr cr .( Invalid names:)
cr s" %1ab" s" _____" .before SUBSTITUTE .result
cr s" 2ab%" s" _____" .before SUBSTITUTE .result
cr s" 3bc%mac1" s" abc%mac1" .before SUBSTITUTE .result
cr s" 4bc%mac1" s" abc%mac" .before SUBSTITUTE .result
cr cr .( Valid name:)
cr s" %5b1%mac2" s" __________" .before SUBSTITUTE .result
cr
0 [if]
- - - - - - - -
Output under Win32Forth 6.15.04 using _200xSubstitute.f:
Extra tests for Substitute
Invalid names:
%1ab + _____ Stubstitute --> [3] 15556356 5 0 %1ab%
2ab% + _____ Stubstitute --> [3] 15556876 5 0 2ab%%
3bc%mac1 + abc%mac1 Stubstitute --> [3] 15557396 8 -1 3bc%mac1
4bc%mac1 + abc%mac Stubstitute --> [3] 15557916 7 -1 4bc%mac
Valid name:
%5b1%mac2 + __________ Stubstitute --> [3] 15558436 9 0 %5b1%mac2
ok
Questions and comment under Win32Forth 6.15.04:
Case: %1ab OK RESn is zero
Case: 2ab% One % too much
Case: 3bc%mac1 RESn should be 0
Case: %5b1%mac2:
1) RESn not the same as the number of replacements
2) Should the output not be mac2 without the name?
- - - - - - - -
Output gForth using their compiled Substitute version:
Extra tests for Substitute
Invalid names:
%1ab + _____ Stubstitute --> <3> 21778744 4 0 %1ab
2ab% + _____ Stubstitute --> <3> 21796312 4 0 2ab%
3bc%mac1 + abc%mac1 Stubstitute --> <3> 21796384 8 0 3bc%mac1
4bc%mac1 + abc%mac Stubstitute --> <3> 21796456 7 -78 4bc%mac
Valid name:
%5b1%mac2 + __________ Stubstitute --> <3> 21796528 9 0 %5b1%mac2
ok
Questions and comment under gForth:
Case: %5b1%mac2:
1) RESn not the same as the number of replacements
2) Should the output not be mac2 without the name?
------------------
Added for Win32Forth in _200xSubstitute.f
[defined] about-win32forth [if] \
: ($create) ( name len -- ) \ Create a definition for name len.
\in-system-ok "HEADER DOVAR COMPILE, ;
: makeSubst \ caddr len -- caddr
\ Given a name string create a substution and storage space.
\ Return the address of the buffer for the substitution text.
get-current >r wid-subst set-current
($create) \ like CREATE but takes caddr/len
r> set-current
here 256 allot 0 over c! \ create buffer space
;
[then]
[then]