Scheme from Scratch - Bootstrap v0.4 - Strings
Another day, another data type: strings.
Like with the character implementation, we only need to worry about ASCII strings for a bootstrap interpreter. The only tricks are reading and writing escaped double quote and newline characters inside a string.
A sample REPL session with strings:
$ ./scheme Welcome to Bootstrap Scheme. Use ctrl-c to exit. > "asdf" "asdf" > "asdf\"asdf" "asdf\"asdf" > "asdf\n" "asdf\n" > "asdf " "asdf\n"
Note that when you want to enter a newline as part of a string you type two characters
\n and when the string is displayed a newline is displayed as the same two characters; however, in the interpreter’s internal string model, a newline is stored as a single byte.
There is a v0.4 branch on github for this version.
Can I see a show of hands who has actually compiled the Bootstrap Scheme code themselves? Has anyone improved it?
Have something to write? Comment on this article.