6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 8:28 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: What is this
PostPosted: Sun Aug 04, 2013 2:58 pm 
Offline
User avatar

Joined: Wed Jul 10, 2013 3:13 pm
Posts: 67
this is some modern forth I saw
Code:

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 ??

_________________
JMP $FFD2


Top
 Profile  
Reply with quote  
 Post subject: Re: What is this
PostPosted: Sun Aug 04, 2013 3:38 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
Looks like pretty typical Forth to me.

Obviously they're interacting with GTK.

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.

But, yup, that's Forth in all its glory.


Top
 Profile  
Reply with quote  
 Post subject: Re: What is this
PostPosted: Sun Aug 04, 2013 7:39 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
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.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: What is this
PostPosted: Mon Aug 05, 2013 5:27 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8513
Location: Midwestern USA
GARTHWILSON wrote:
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.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: What is this
PostPosted: Mon Aug 05, 2013 5:39 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
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!)

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 05, 2013 12:59 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
GARTHWILSON wrote:
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:
Attachment:
File comment: Readability preview
starting-forth-leo-brodie.png
starting-forth-leo-brodie.png [ 63.78 KiB | Viewed 2161 times ]

Attachment:
File comment: Original site
starting-forth-on-forth.com.png
starting-forth-on-forth.com.png [ 254.66 KiB | Viewed 2161 times ]

Cheers
Ed


Top
 Profile  
Reply with quote  
 Post subject: Re: What is this
PostPosted: Sat Sep 07, 2013 6:16 pm 
Offline
User avatar

Joined: Sat Sep 29, 2012 10:15 pm
Posts: 904
I was wondering why BDD's messages are so much clearer! I hope this doesn't turn into a font size contest :)

_________________
In theory, there is no difference between theory and practice. In practice, there is. ...Jan van de Snepscheut


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: