Vorticon, on Wed Feb 22, 2012 7:47 PM, said:
Excellent question.
When you get to the end of a block, you can use the word -->
The word --> when encountered at load time, will automatically pull in the next block from disk and continue loading. You can chain blocks together like this indefinately.
editor.png 88.42K
2 downloadsNote, you can use --> in the middle of a colon definition (i.e. a colon definition can span more than one block, but it's very very bad practice and liable to get you shot by the Forth Police, so don't do it!)
When you're in the editor, you can use CTRL O and CTRL P to move to the previous, and next block respectively.
Now is probably a good time to introduce you to block buffers. Most Forth systems, including TurboForth, have the notion of block buffers. The basically work like a block cache. When you request a block (with EDIT, or with LOAD, or with LIST or whatever) the requested block is loaded into (in TurboForth's case) one of six buffers (in TF these buffers are in VDP memory to keep CPU memory free for your code).
You can see the 'block cache' in action by typing the following (it's VERY obvious if you're using a REAL TI machine with floppy drives).
1 LIST
2 LIST
3 LIST
4 LIST
5 LIST
6 LIST
See how each request caused a trip to the floppy disk drive? Now type, say, 4 LIST again.
Notice how there was no round-trip to the floppy disk? That's because TF knew that block 4 was already in its cache, so it didn't bother going to the floppy disk for it.
When you EDIT a block, it brings it into one of the six buffers and invokes the editor. The moment you make a change in the editor (by changing the source code in any way) the buffer in which your block resides is marked as dirty (because it has been changed, so the version on disk is 'out of date' with the version in memory).
When you exit the editor with FCTN 9 the editor block is in the cache and will NOT be written to disk until it is FLUSHed. A flush happens under two circumstances:
- You type FLUSH on the command line.
- All six buffers are in use and you request a new block (that is not in the cache)
You'll get into the habit of exiting the editor and typing FLUSH to make sure you're edits are saved back to disk (it's fairly easy to crash all Forth systems, since you are completely free to screw up in any way you see fit!)
Note that you can also load code directly from the cache! You don't have to do anything special to do that; if the block requested is in the cache then it gets served to the compiler/editor/whatever from the cache.
Finally, if you are editing a block and you screw up, just press FCTN =. This will exit the editor but it will NOT mark the buffer/block as dirty. It will actually mark the buffer in which that block was residing as empty, which will force the original block to be re-loaded when you edit it again.
Okay, that's probably quite a lot to digest in one hit! I hope this makes sense. It's actually very natural... There's a cache between you and the block hosting device; be that a ram disk, hard disk, floppy disk, CF7, whatever...
Please feel free to ask further questions!













