Email:   
Home
In This Issue
EasyPrint
Click here for the RSS feed's XML code. This is not a browser URL.
Palm programming with Quartus Forth (continued)

The Forth world
Most common programming languages today are based on systems in which previously declared functions are passed variables of a particular type. These are glued together with programming logic like If-Then-Else and For-Next keywords that are integral parts of the language itself. You effectively program in a language that has few words but a rich syntax. Forth uses a completely opposite system; you program in a language that has a simple syntax but is rich in words. This is achieved through two mechanisms, the stack and the interpreter.

The stack is a last-on-first-off queue used by the system to store numbers temporarily before they're worked on by words. The classic visual for this is one of those spring-loaded dish racks you see in a restaurant. The first dish goes on the rack. Then the next dish goes on top, pushing the first dish down. And so forth. When a dish is removed, it's the top dish (the most recently placed on the rack, or stack in computer terms). Finally, the last dish removed is the first that was ever placed on the dish rack.

The Forth interpreter reads your program as you input it, either as a full program or line-by-line. It uses spaces to delimit words, and as it comes across each word, it looks up the word's definition in a dictionary and executes the definition. Absolutely anything can be a word in Forth, including numbers and punctuation. If the interpreter finds a number that has no definition, it pushes it onto the stack.

Forth uses postfix notation for arithmetic. Postfix is a little different than normal programming. For example, to add the numbers 5 and 4 together you would enter "4 5 +" (remember the spaces). This makes sense because the interpreter will see 4 and then 5 and push them onto the stack. Next it will see +, which is a word with the definition "take the top two values from the stack, add them, and push back the answer." If we use the Forth language word '.' we can print out the top stack value -- 9, in this case. To create new words, we use the words ':' and ';' which start and stop the compiler respectively and put our definition between them. We can now create a word "hello" which prints out "hello world" using the '.' word as in:

: hello . "Hello world" ;

By entering some of this into your Palm device, you can get Quartus Forth to perform operations. Figure B shows some of this in action.

FIGURE B

With simple words and arithmetic you can make your own definitions in this program.

As you can imagine, there's more to it than that, but that's the basic mechanism. A Forth program consists of word definitions. Don't think of these as traditional computer functions; you'll only get a headache. A word can be almost anything, including punctuation. Words often act on values on the stack, but not always, consuming them and putting results back on the stack.

Now let's look at how Quartus Forth works with your Palm device.

Palm programming in Forth
Quartus Forth programs are created using memo records. The distribution contains a library of about 60 memo records that define useful word collections for MemoDB access, reading .DOC format files, or handling IDs and events. To create a new program, simply create a new memo and start it with a backslash, a space, and the name of the program followed by optional comments.




[ Prev | Next ]

ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
-- Advertisement --

ONLINE GROUP CALENDAR - FOR UP TO 100 OF YOUR CLOSEST FRIENDS
Stay organized and in control with 24/7 access to all of your important events, projects and files --whether you're at work, at home or on the road.

You can share your calendar, projects and files so everyone in your office is up to date. Plus, search your entire group to find times when everyone is available to meet, manage company resources and much more.

Organize your entire team for as low as $9.95 per year (and yes, that's where the decimal place is supposed to be!)

Tap here to get started right away.

-- Advertisement --

SECURE YOUR SITE WITH AN IRONCLAD SSL CERTIFICATE
An IronClad SSL Certificate helps you build an impenetrable fortress around your customer's credit card information. IronClad SSL Certificates are:

  • Fully validated
  • Up to 256-bit encryption
  • Up to 10 years validity
  • Stringent authentication
  • Around-the-clock customer support

Build trust. Protect your customers. Grow your online business.

Tap here now and be IronClad with SSL tonight.

Copyright © 1998-2008, ZATZ Publishing. All rights reserved worldwide.
Editor's Login