Starting Forth : I/O

Hadrien W.
2 min readDec 9, 2017

--

This will be the first installament of a series where I document my progress through the book Starting Forth, by Leo Brodie. As I’ve already read the first nine chapters, this will be about Chap.10 : I/O and You.

A Televideo ASCII character mode terminal, image in the public domain.

I use Gforth 0.7.3 on a linux laptop. My main tool is emacs, which I use with forth-mode for editing souce files, and for running the interpreter. Up till now, gforth has integrated pretty seamlessly with emacs.

Here is the code for the chapter :

exercise 10.1 :

exercise 10.2 : (this one was trivial, if you have read the chapter)

exercise 10.3 : here things got very thorny, since I ran into issues with emacs. It appears key doesn’t behave in the same way whether you run gforth from your shell or from emacs. In emacs, key effectively suspends execution until you type return. This version doesn’t work as well in emacs (you’ll have to type a newline after your year of birth). Here we use a superstring (“animals”), which appears, after a quick google search (correct me if I’m wrong), to be a forth-ism.

exercise 10.4 : In the block we are using (block # 2, in our case), each line’s first 40 bytes will contain the vitals (name, eyes, me) for our exercise. The first 14 bytes will be the lover’s name, the next 12 bytes will be the lover’s eye color and the next 14 bytes will be the sender’s name. The word letter is largely unaffected by the changes, except for the drop at the end. I don’t use the page word at the beginning of letter because it doesn’t seem to work with emacs. Notice our implementation is not really efficient since we compute name 3 times for each letter generated.

exercise 10.5 : cells are 8 bytes long on my system. Each block thus contains 128 cells.

Those are all the exercises for Chapter 10. This chapter was full of handy tricks, such as the random number generator. I found block I/O to be pretty straightforward to deal with. I’ll read the next chapter tomorrow and I’ll do the exercises when I have the time.

--

--

Hadrien W.
0 Followers

I work as a doctor in a psychiatry residency. I also like programming and sketching.