Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #45358 > unrolled thread

Standard for substitute?

Started byjosv@planet.nl
First post2016-02-08 05:14 -0800
Last post2016-02-08 14:22 -0800
Articles 6 — 3 participants

Back to article view | Back to comp.lang.forth


Contents

  Standard for substitute? josv@planet.nl - 2016-02-08 05:14 -0800
    Re: Standard for substitute? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-08 17:08 +0000
      Re: Standard for substitute? josv@planet.nl - 2016-02-08 14:12 -0800
      Re: Standard for substitute? josv@planet.nl - 2016-02-08 15:08 -0800
    Re: Standard for substitute? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-02-08 20:27 +0000
      Re: Standard for substitute? josv@planet.nl - 2016-02-08 14:22 -0800

#45358 — Standard for substitute?

Fromjosv@planet.nl
Date2016-02-08 05:14 -0800
SubjectStandard for substitute?
Message-ID<74c901b1-0d95-427a-91ec-c6d1ca079d6e@googlegroups.com>
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]

[toc] | [next] | [standalone]


#45370

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2016-02-08 17:08 +0000
Message-ID<2016Feb8.180842@mips.complang.tuwien.ac.at>
In reply to#45358
josv@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/

[toc] | [prev] | [next] | [standalone]


#45377

Fromjosv@planet.nl
Date2016-02-08 14:12 -0800
Message-ID<404f63d0-e304-4fe7-ab8f-6be9eefe6979@googlegroups.com>
In reply to#45370
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:
> josv... 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.

I agree.

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

[toc] | [prev] | [next] | [standalone]


#45379

Fromjosv@planet.nl
Date2016-02-08 15:08 -0800
Message-ID<a8576c08-895c-4e91-8925-8dfd6085c17e@googlegroups.com>
In reply to#45370
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:
> josv... 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/

[toc] | [prev] | [next] | [standalone]


#45376

FromGerry Jackson <gerry@jackson9000.fsnet.co.uk>
Date2016-02-08 20:27 +0000
Message-ID<n9atgi$eoh$1@dont-email.me>
In reply to#45358
On 08/02/2016 13:14, josv@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

[toc] | [prev] | [next] | [standalone]


#45378

Fromjosv@planet.nl
Date2016-02-08 14:22 -0800
Message-ID<39cb479e-2550-4c55-b615-4437521c1cdd@googlegroups.com>
In reply to#45376
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:
> On 08/02/2016 13:14, josv... 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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web