String Byte Length: Difference between revisions
Content deleted Content added
Undo revision 7095 by Special:Contributions/IjxJaq (User talk:IjxJaq) |
|||
Line 151:
'''Interpreter:''' ANS Forth
Strings in Forth come in two forms, neither of which are the null-terminated form commonly used in the C standard library.
===Counted string===
A counted string is a single pointer to a short string in memory. The string's first byte is the count of the number of characters in the string. This is how symbols are stored in a Forth dictionary.
CREATE s ," Hello world" \ create string "s"
s C@ ( -- length=11 )
===Stack string===
A string on the stack is represented by a pair of cells: the address of the string data and the length of the string data (in characters). The word '''COUNT''' converts a counted string into a stack string. The STRING utility wordset of ANS Forth works on these addr-len pairs. This representation has the advantages of not requiring null-termination, easy representation of substrings, and not being limited to 255 characters.
S" string" ( addr len)
DUP . \ 6
==[[Haskell]]==
|