include ffl/gsv.fs
\ Open the connection to the gtk-server and load the Gtk2 definitions
s" gtk-server.cfg" s" ffl-fifo" gsv+open 0= [IF]
\ Convert the string event to a widget id
: event>widget
0. 2swap >number 2drop d>s
;
0 value window
: window-creation
gtk_init
\ Create the window
GTK_WINDOW_TOPLEVEL gtk_window_new to window
window gtk_widget_show
\ Wait for an event
BEGIN
s" WAIT" gtk_server_callback
event>widget window =
UNTIL
0 gtk_exit
;
window-creation gsv+close drop
[THEN]
this looks incredibly confusing is this the same syntax as on a 6502 ??
The word creation within the [IF] is an odd idiom, but I imagine it's appropriate in this use case.
Looks like all it does is create a connection to the GTK server (I don't know anything about GTK), opens a window if it was successful, and then waits for an event on that window, (like a mouse click), and then it shuts it all down.
As mentioned in other topics here, the standard introduction to Forth is Leo Brodie's book, "Starting Forth," available for free reading online at http://www.forth.com/starting-forth/index.html, updated to reflect ANS Forth and many modernizations. It is very well laid out and gives and easy, entertaining way to familiarize yourself with the Forth way of doing things which is very different from most other programming methods but gives a lot of power and flexibility through simplicity and leaving the user able to "get under the hood" and extend and modify the language and even the compiler itself.
I'm not familiar with GTK, and this excerpt of code could have been written a little more clearly, but some general stuff is:
[IF] is for conditional compilation. The condition is set up first, leaving a flag on the stack, and then the "if" goes ahead if that flag cell was not false (zero). The same goes for the UNTIL you see later, for the loop. That's why there's nothing after the UNTIL. "Until what?" It loops until the flag, left on the stack before the UNTIL, is true (ie, non-zero).
The backslash by itself means the rest of the line is comments for the computer to ignore.
S" puts the following literal string into a temporary buffer.
The : creates a Forth word with the name specified immediately after the colon, and turns on the compiler. ; ends the word with the unnest and turns off the compiler.
This is basic Forth stuff. Which processor it's implemented on is rather irrelevant, except that you won't find 32-bit and 64-bit Forth on 6502's. There is more general description of Forth in other topics here like the "What is Forth?" one. Forth as a programming language and environment is very efficient in terms of development and memory consumed, and, unlike its initial appearances, extremely flexible. It's also rather fast in execution, as far as higher-level languages go.
As mentioned in other topics here, the standard introduction to Forth is Leo Brodie's book, "Starting Forth," available for free reading online at http://www.forth.com/starting-forth/index.html, updated to reflect ANS Forth and many modernizations.
Be aware that the online version of Starting Forth is somewhat cumbersome to read, especially for old guys like me who can't see very well. The page font is tiny and the page itself is somewhat cluttered. A PDF version would be nice for local reading.
BDD, here is another one. It's may not be an "official" reproduction (like the other one from Forth, Inc. who published the paper book), but should be mostly the same, just without the original cartoons from comedian Leo Brodie. It looks like it lacks a "—>Next" and "Previous<—" page link on each page, but they're all linked into the index. I'm sure I've come across other transcriptions on the web too. And you can always turn up the print size on the screen with <Ctrl>+. I don't recall ever seeing a .pdf one. I bought my paper one long ago.
"Thinking Forth" (by the same author) is the next one, and, although focused on Forth, really has more to do with programming philosophy— it's just that the ideas are brought out in Forth. That one is available in .pdf—the 2004 edition—at http://sourceforge.net/projects/thinkin ... f/download . Looking over the preface and other parts, I think I ought to re-read the book now in its latest revision. From the preface, on page 13:
Quote:
Building models in the mind is both the challenge and the joy of programming. How should we prepare for it? Arm ourselves with better debuggers, decompilers, and disassemblers? They help, but our most essential tools and techniques are mental. We need a consistent and practical methodology for thinking about software problems. That is what I have tried to capture in this book. Thinking Forth is meant for anyone interested in writing software to solve problems. It focuses on design and implementation; deciding what you want to accomplish, designing the components of the system, and finally building the program.
The book stresses the importance of writing programs that not only work, but that are also readable, logical, and that express the best solution in the simplest terms.
Although most of the principles described here can be applied to any language, I've presented them in the context of Forth. Forth is a language, an operating system, a set of tools, and a philosophy. It is an ideal means for thinking because it corresponds to the way our minds work. Thinking Forth is thinking simple, thinking elegant, thinking flexible. It is not restrictive, not complicated, not over-general. You don't have to know Forth to benefit from this book. Thinking Forth synthesizes the Forth approach with many principles taught by modern computer science. The marriage of Forth's simplicity with the traditional disciplines of analysis and style will give you a new and better way to look at software problems and will be helpful in all areas of computer application.
If you want to learn more about Forth, another book of mine, Starting Forth, covers the language aspects of Forth[...]
Now looking further at Forth, Inc.'s website, a couple more paper books that interest me are: Forth Programmer's Handbook A detailed, technical Forth manual for experienced programmers, and Forth Application Techniques This Forth-programming tutorial builds practical Forth skills quickly.
(These pages give the table of contents and good descriptions of the books. I recommend a look!)
BDD, ... you can always turn up the print size on the screen with <Ctrl>+.
Well worth trying - it's the category of "know your tools"! The odd approach you have, BDD, of posting everything with an explicit 110% font size, is a bit wearying.
Also worth trying, for websites which are insufficiently readable, is to read them through http://readability.com - they have a URL-shortener at http://rdd.me, so for example the Forth page is at http://rdd.me/3ndkmk72 - you don't need to sign up, but if not logged in you need to click through to get the readable version. Here's an impression of what it looks like - you can change colour scheme, font size, column width: