Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #45370
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Standard for substitute? |
| Date | 2016-02-08 17:08 +0000 |
| Organization | Institut fuer Computersprachen, Technische Universitaet Wien |
| Message-ID | <2016Feb8.180842@mips.complang.tuwien.ac.at> (permalink) |
| References | <74c901b1-0d95-427a-91ec-c6d1ca079d6e@googlegroups.com> |
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/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web