Liste des Groupes | Revenir à cl forth |
In article <03d13185898a1ee00bea4f420aa1a3721b0585f2@i2pn2.org>,
dxf <dxforth@gmail.com> wrote:On 27/04/2025 8:28 pm, Hans Bezemer wrote:Store a string in allocated memory....of the "how"). E.g. for counted strings it might be:
Another handy word is >STRING that converts a "raw" string to a fully qualified string ( a1 n1 -- a2) that can handle a COUNT (you have the carnal knowledge - you take care>>
: >STRING swap over over dup char+ rot cmove c! ;
For forths that have PACK ( a u a2 -- a2 )
>
: >STRING ( a u -- a ) over pack ;
>
sc (string constant: a u)
: $!A DUP ALLOCATE THROW >R
R@ SWAP CMOVE
R> ;
It helps to have SIZE in the memory wordset:
sva (string variable stored ALLOCATE d)
: $@A DUP SIZE ;
The proper mindset is that there are string variables,
(string areas where a string could be stored and changed)
and string constants, sc n where you are no supposed
to change the content of the string.
Les messages affichés proviennent d'usenet.