Search PalmPower's 487 Palm-related article archive 
Home
EasyPrint
News details Click here for the RSS feed's XML code. This is not a browser URL.
Articles-only 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.


« Previous  ·  1  ·  2  ·  3  ·  4  ·  Next »
Other articles you might like
Home > Phones and PDAs > Palm and Treo > Programming (24 articles)
   How PDA software is born
   Program with Simplicity
   Kinectivity 2.0 brings enterprise application developers new tools
Get Weekly Email Updates
Subscribe to our regular weekly email newsletter. It's packed with tips, reviews, deep analysis, and the latest news.
 
Other PalmPower Articles
Palm gets up to date with new Tungsten family of handhelds
Create handwritten email with riteMail
Presenter-to-Go puts PowerPoint presentations on your Palm OS handheld
Looking for the cutting edge
Gain remote access to databases and PLCs
PalmSource Open House showcases what's new in the Palm community
Analysis: handheld market share
More from the ZATZ journals
Computing Unplugged: The iPad defenders have spoken
David Gewirtz Online: CNN commentary and analysis
DominoPower: Application development, William Shatner, and the origin of the universe
OutlookPower: More about disappearing text
-- Advertisement --

Sent Items Organizer
When you need to file your sent email into their proper folders based on keywords or who it's to. It's also perfect for shared mailboxes.

It also adds a "Send And File" toolbar button while you're composing (similar to the way Lotus Notes used to work) for quick and easy filing.

Find out more!

ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 1998-2010, ZATZ Publishing. All rights reserved worldwide.
Editor's Login