Finite State Machines in Forth
started 2/18/2003; 6:31:34 PM - last post 2/23/2003; 12:11:12 AM
|
|
John Fraser - Finite State Machines in Forth
2/18/2003; 6:31:34 PM (reads: 413, responses: 5)
|
|
Finite State Machines in Forth
This is an interesting article about how one language tackles the problem of generating state machines. The author also has an interesting tutorial on Forth here.
I know most of the post here are directed at functional languages but I think Forth provides interesting perspective of language design. Specifically the DOE>DOES and IMMEDIATE words.
It is a language that has almost no syntax.
|
|
Michael Vanier - Re: Finite State Machines in Forth
2/19/2003; 1:21:07 AM (reads: 426, responses: 0)
|
|
Forth is an extremely interesting language from a great many perspectives. It was the first language I really fell in love with. It's hackability is almost without equal. As you say, there is almost no syntax (actually too little for my taste; I like the way lisp uses parentheses for grouping, and I like having more literal syntax than Forth has for things like strings). One big disadvantage of Forth is that the language is tied to a particular implementation choice (threaded interpreters) that is not a very effective way to run programs on modern processors. However, it's very easy to implement, which is a worthwhile exercise. I think all computer language fans owe it to themselves to learn Forth.
|
|
John Fraser - Re: Finite State Machines in Forth
2/20/2003; 3:20:18 PM (reads: 391, responses: 0)
|
|
One big disadvantage of Forth is that the language is tied to a particular implementation choice (threaded interpreters) that is not a very effective way to run programs on modern processors
Not so much anymore. Many implementations meta compile to the target platform today. There was a great example on the VM mailing list, but I can't seem to find it anymore.
|
|
Adam Vandenberg - Re: Finite State Machines in Forth
2/21/2003; 7:06:33 PM (reads: 369, responses: 0)
|
|
|
John Fraser - Re: Finite State Machines in Forth
2/22/2003; 11:11:32 AM (reads: 344, responses: 0)
|
|
That was one of my favorite games. That site is pretty cool.
|
|
Patrick Logan - Re: Finite State Machines in Forth
2/23/2003; 12:11:12 AM (reads: 339, responses: 0)
|
|
Tying the comments above about Forth and Lisp syntax: A talk on Scheme discussed previously on LtU, i.e. Swine Before Perl, presented an FSM syntax macro for Scheme.
The syntax named 'automaton' compiles an FSM into a procedure, with each state being a tail recursive nested procedure within the automaton. The following example is an application of the automaton that recogizes lists of symbols that begin with C, have any number of A and D symbols, and end with R.
((automaton init
(init : (c -> loop))
(loop : (a -> loop)
(d -> loop)
(r -> end))
(end : (r -> end)))
'(c a a d d r))
I won't try to argue which syntax, Lisp or Forth, is better. I've programmed many order of magnitud more in Lisp than Forth.
The Forth model has always had some appeal to me, though, for its simplicity and compact implementations. I wish I had had the chance to do real-time device programming in Forth. That's something I'd kept coming across in conversations and reading, but never tried.
|
|
|
|