Case-logic
Blake
blake at kingdomrpg.com
Wed Oct 27 05:15:57 UTC 2004
On Tue, 26 Oct 2004 19:26:02 -0700 (PDT), Chris Muller
<afu.nkyobject at yahoo.com> wrote:
> I don't see any harm in case-logic for checking hot keys..
I've been meaning to ask the group this, since I remember picking up the
anti-case message from Meyer (coincidentally enough, in his Eiffel books)
but I'm trying to figure out how I'd program a state machine without it.
Well, I can see how to do it, but I don't think I "get it" since it
doesn't seem easier or clearer to do it that way.
Can anyone recommend some state-machine type stuff in the codebase for me
to look at? Or thoughts on how you'd code something like the code below?
(Some background: I'm writing a book for kids on programming. I learned to
program in Basic and despite the fact that it gave me a strong taste for
finding better ways of doing things, I really don't want to inflict that
on another generation.<s> That means, in part, rooting out my own bad
habits so as not to pass them on.)
===Blake===
WHILE (i<=len(expr))
IF c>="A" and c<="Z" THEN 'we're at a function call
...
ELSE IF C="[" THEN 'we're at a user defined variable
...
ELSE IF C="_" THEN 'we're at a system value
...
ELSE IF at("operator", expect)>0 and at(C, "+-*/<=>")>0 THEN 'operator
...
ELSE IF at(c+d, ".A.O.N") > 0 THEN 'logical operator
...
ELSE IF at(C, numeric)>0 or ((C="-" .or. D="+") and at(D, numeric)>0)
THEN 'we're at a literal constant
...
ELSE IF C = "," THEN
...
ELSE IF C="(" THEN 'we're grouping terms or in a procedure
...
ELSE IF C=")" THEN 'we're ending a group of terms
...
ELSE IF C=" " THEN 'ignore spaces
...
END WHILE
More information about the Squeak-dev
mailing list
|