Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion State machine representation
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Dave Roberts  
View profile  
 More options Feb 1 2004, 1:44 pm
Newsgroups: comp.lang.lisp
From: Dave Roberts <ld...@re-move.droberts.com>
Date: Sun, 01 Feb 2004 18:44:19 GMT
Local: Sun, Feb 1 2004 1:44 pm
Subject: Re: State machine representation

Kenny Tilton wrote:
>> 1. Just represent state machines simply with an integer or symbol state
>> variable and a case or cond form which switches on the current state. The
>> forms associated with any case/cond clause then determine the next state.

> That's what I have done with some simple machines. Symbols definitely,
> for readability, plus numbers would not work with CASE.

Right. Doesn't seem like it scales as well, however. Lots of top-level
namespace pollution. Probably the most simple way to get it done, however.
For simple programs, this seems like what I would use if I didn't have a
macro language built up to define state machines nicely (my eventual goal).

>> 2. Represent each state with a different function, bound at top-level.
>> The state machine can then be represented as a list or structure, with
>> those functions operating on it.

>> 3. Represent the state machine with a closure. Basically:
>> (defun make-state-machine ....
>>   (let ((statevar1)
>>         (statevar2)
>>         (current-state))
>>     (flet ((state1 (input) ...)
>>            (state2 (input) ...))
>>       (setq current-state state1)
>>       (lambda (input) (funcall current-state input)))))

> Not bad.

Thanks, I'm learning. I sense that closures are powerful constructs, but I'm
sort of struggling for how/when to use them. Typically, it seems like you
can always get something done another way, and so I struggle with when to
use that tool.

-- Dave


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.