Proposal:  String store and fetch
This page is dedicated to discussing this specific proposal
albert  String store and fetchProposal2023-11-12 13:12:55
Hint: Please delete the blockquote explanations, they are just for your convenience while writing the proposal
Albert van der Horst .
With the advent of a proper notation for strings (recognizers) it is time to tackle the manipulation of strings. Strings deserve a prefix like D DF SF U to set these wordset apart from other words and greatly enhance reasibility. The foremost decision is how to choose the prefix. STR and $ comes to mind. In this proposal I use <string> because to discussion of how to choose the prefix distracts from the conclusion that we need such a prefix. In the following I use the $ because we are obliged to use a web interface instead of the brilliant programmer editors like emacs and gvim.
As we adapt this solution the future look bright with words as: $^ $\ $/ $= $,
We need analogous words to ! @ +! , DF! DF@ 2! 2! . Define a stringconstant with an (address character-count) pair. In the stackdiagram indicated as sc Define a stringvariable as a-addr with sufficient space for a string to be stored. In the stacj k diagram indicated as sv.
This requires thus <string>@ <string>! <string>+! and <string>C+
The foremost decision is that these words work with a cell that determines the count. The habit of storing the count in a character, can largely be ignored. It is fortunate that the brain-damaged word to do this (COUNT, PLACE) are different from this proposal.
This wordset is used since 1984 on the Osborne and has been used internally and externally in ciforth implementation since 2000.
Typical use: (Optional)
CREATE MYBUFFER 100 ALLOT "ROME" MYBUFFER <string>! MYBUFFER <string>@ TYPE \ ROME OK BL MYBUFFER <string>+C MYBUFFER <string>@ TYPE CHAR | EMIT \ ROME | OK "ATHENE" MYBUFFER <string>+!
Add the following paragraphs to the STRING chapter.
STACKEFFECT: sc addr ---
Store a string constant sc in the string variable at address addr.
STACKEFFECT: sc addr ---
Append a string constant sc to the string variable at address addr. __________________________________________________________________
STACKEFFECT: addr --- sc
From address addr fetch a string constant sc . __________________________________________________________________
STACKEFFECT: ch addr ---
Append a char ch to the string variable at address addr. __________________________________________________________________
If the proposal surviive the first ridicule I shall have the reference implementation copied from PROJECT-FORTH-WORKS See PROJECT-FORTH-WORKS
HEX 4 , 41 C, 39 C, 45 C, 30 C, HERE 4 CELL+ - $@ TYPE | A9E0 HEX 2 , 41 C, 39 C, HERE 2 CELL+ - $@ PAD $! PAD $@ TYPE | A9 HEX 2 , 41 C, 39 C, HERE 2 CELL+ - $@ 2DUP PAD $! PAD $+! PAD $@ TYPE | A9A9 HEX 2 , 41 C, 39 C, HERE 2 CELL+ - $@ PAD $! HERE 1 - C@ PAD $C+ PAD $@ TYPE | A99
The testresults are after the vertical bar. If the proposal surviive the first ridicule I shall edit to correspond test harness in Appendix F.