Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Standard for substitute?

69 views
Skip to first unread message

jo...@planet.nl

unread,
Feb 8, 2016, 8:14:16 AM2/8/16
to
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]

Anton Ertl

unread,
Feb 8, 2016, 12:26:33 PM2/8/16
to
jo...@planet.nl writes:
>It seems there exist several versions of SUBSTITUTE
> 1) Is the version at
> http://www.forth200x.org/text-substitution.txt still right?

The committee refined especially the specification of boundary cases
afterwards; I don't think this has been revised in the RfD/CfV (and it
probably should not; the vote was on the CfV text).

You can find the version specified in Forth-2012 at
<http://forth-standard.org/standard/string/SUBSTITUTE>

>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

I don't see a REPLACES for "5b1".

>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?

1) There were 0 replacements, and 0 is returned. Looks fine to me.
2) From the standard:

|3) If the text is not a valid substitution name, the name with leading
|and trailing delimiters is passed unchanged to the output. The current
|number of substitutions is not changed.

The %1ab result has one '%" too much.

>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?

This result is Forth-2012-conformant, see above.

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2015: http://www.rigwit.co.uk/EuroForth2015/

Gerry Jackson

unread,
Feb 8, 2016, 3:26:42 PM2/8/16
to
On 08/02/2016 13:14, jo...@planet.nl wrote:
> 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
>

You could save yourself some work if you used the SUBSTITUTE and
REPLACES tests in the forth 2012 test file: stringtest.fth
See https://github.com/gerryjackson/forth2012-test-suite

--
Gerry

jo...@planet.nl

unread,
Feb 8, 2016, 5:12:28 PM2/8/16
to
Thanks Anton,

That is just what I was looking for.
Under Win32Forth the replacement for %5b1% is:
%5b1%mac2
Note: when reading:
----------
2:If the text is a valid substitution name acceptable to
17.6.2.2141 REPLACES, the leading and trailing delimiter
characters and the enclosed substitution name
are replaced by the substitution text.
The current number of substitutions is incremented.
----------
It looks like the name including the delimiters %5b1% should
removed from the result. Leaving just 'mac2' (without the quotes)
( = substitution text ? ) as the result.

Jos

On 8 februari 2016 18:26:33 UTC+1 Anton Ertl wrote:
I agree.

jo...@planet.nl

unread,
Feb 8, 2016, 5:22:29 PM2/8/16
to
Hi Gerry,

The description of the Forth200x gave is not clear to me.
The test program does not explain it to me so I am asking questions.
It is not my intension to replace your test program.

Jos

On 8 februari 2016 21:26:42 UTC+1 Gerry wrote:

jo...@planet.nl

unread,
Feb 8, 2016, 6:08:03 PM2/8/16
to
Hi Anton,

I just read the whole stuff again.
Please ignore my remarks about
%5b1%mac2
The output should indeed be %5b1%mac2

Jos

On 8 februari 2016 18:26:33 UTC+1 Anton Ertl wrote:
0 new messages