More than a REPL is needed
So far we only have shown the REPL, the interactive 8th console.In order to create complete programs we need to expand our possibilities a bit.
Using a text editor
We will need a (simple) text editor to write an 8th program.These days there are all kinds of advanced tools, like IDE’s (Interactive Development Environment). However, for our purposes we only need a simple editor.
The editor I am using is called Textpad and costs a little. I also created a simple, but nice looking 8th syntax highlighter for it. You can ask in the 8th forum about this.
A few possible (free) editors (in no specific order):
- Windows Notepad (built in in Windows - free)
- TextPad Editor https://www.textpad.com/ ($27 as of jan. 19 2016))
- Crimson Editor http://www.crimsoneditor.com/ (free)
- ConText Editor http://www.contexteditor.org/index.php (free)
- PsPad Editor http://www.pspad.com/ (free)
- NotePad++ Editor https://notepad-plus-plus.org/ (free)
- Emacs https://www.gnu.org/software/emacs/ (free)
- EmacsW32 especially for Windows users http://www.emacswiki.org/emacs/EmacsW32 (free)
- VIM http://www.vim.org/ (free)
NOTE stay away from text processing programs like MS Word, Wordpad, Open Office, Libre Office etc. Those “editors” make heavy use of markup language. But we need a strict plain text editor for programming purposes!
Program structure in 8th
- if we reference a variable x from within a word w we have defined, that variable x must have been defined before the definition of word w
- if we reference a word w1 from within a word w2 we have defined, that word w1 must have been defined before the definition of word w2 (there is a special case (deferred words) which we will explain later)
- at the end of a program you should define the special word app:main which is the word invoked automatically when your 8th program starts
- the app:main definition should normally end with the bye word. For this rule there are 2 valid exceptions:
- in GUI apps quitting 8th will be done elsewhere in the program; you must leave out bye there
- for debugging reasons; from version 16.01 onwards there will be a word available to start the REPL; you could then use that word, instead of bye to debug your program
Work flow
- open your text editor
- open a command prompt / terminal
- switch to the directory where your source is stored
- create, add or modify a small piece of code in the text editor; never change big pieces of your program at once, because then it is very difficult to track bugs
- start your program in the command prompt / terminal: 8th progname.8th
- check the results of your program
- go back to step 4
Our first program
In the text editor I now show you the first (very simple) program:Namespaces revisited
In the program we used the with: word. Doing so, 8th will search for words and variables in this namespace as well.If you don’t use with: you will need to qualify the defined words / variables in such a namespace. In this example case: @arie.space:squared
NOTE that it is possible to have the same word or variable name in different namespaces. In that case the word found first (in the search order of 8th) will prevail!
Conclusion
Of course this is just the beginning. You should get acquainted with this stuff and try out small snippets of code.Do not hesitate to sprinkle .s words throughout your code. That way you can easily see what is happening on the stack!
More info about 8th
There is a central website for 8th here: http://8th-dev.com/Video
You can watch the complementary video here: https://youtu.be/SmiRwTNWkSs


No comments:
Post a Comment