The idea of strings is that a character string (s) is in fact a counted string (cs) that has been stored. s (c-addr) is the string, cs (c-addr u) is constant string. The base words are :
$@ $! $+! $C+
Furthermore I have:
$^ $/ " CORA $,
" is a denotation. It replaces S" and works the same way in interpret and compile mode. Unlike S" it is not followed by a space. Adding these words to Forth is a simplification in the sense that I can do away with more than 9 words that are no longer needed (among them COUNT ). It also is in the sense that WORD EVALUATE INTERPRET CREATE etc. can be more clearly expressed using them.
The wordset STRING contains words that manipulate strings of characters. In ciforth strings have been given their civil rights. So they are entitled to a denotation and have a proper fetch and store. An (address length) pair is considered a string constant. It may be trimmed, but the data referring to via address must not be changed. It can be stored in a buffer, a string variable, that contains in its first cell the count. Formerly this was in the first byte, and these are called old fashioned (or less flatteringly: brain-damaged) strings.
Store a string constant sc in the string variable at address addr.
Append a string constant sc to the string variable at address addr.
Allocate and store a string constant sc in the dictionary and leave its address addr.
From address addr fetch a string constant sc .
Append a char ch to the string variable at address addr.
Find the first ch in the string constant sc and return its addr1 if present. Otherwise return a nil pointer (0).
Find the first ch in the string constant sc and split it at that address. Return the strings after and before ch into sc1 and sc2 respectively. If the character is not present sc1 is a null string (its address is zero) and sc2 is the original string. Both sc1 and sc2 may be empty strings (i.e. their count is zero), if ch is the last or first character in sc .
Other Forth lectures Go to the home page of Albert van der Horst