Need a metavalue singleton kinda thingy as a reserved key...

Noah noah at noah.org
Sun Aug 11 18:20:24 CEST 2002


Oh, so you want a motivation for doing this?

I'm creating a generic Finite State Machine class.
As part of the input to the FSM you specify a map from
    (input_symbol, state)  -->  (action, next_state)
The input_symbol can be any object or value you want.
I want a convenient way for the user to specify
special symbols that the FSM treats differently
than regular symbols. For example, some types of
special symbols might be "MATCH_ANY", "MATCH_ALWAYS", 
"LAMBDA", "DEFAULT_MATCH". These meta-symbols are
special in that the FSM will check for a match on them
before or after other possible transitions. 
I suppose I could specify the special meta-transitions 
using a separate method so that there is no ambiguity, but 
my initial goal was to limit the number of methods.

And I admit this is a bit pedantic anyway since I have never
seen anybody use an FSM to match anything except characters.
Originally I used None as a meta-symbol for "ANY", but then 
I came to a situation where I actually wanted to match None
Later I came up with more than one meta symbol, but
I had only one None :-) ...

Since I could not cleanly do what I wanted I thought
that maybe I was looking at this the wrong way.

Yours,
Noah

-----Original Message-----
From: holger krekel [mailto:pyth at devel.trillke.net]
Sent: Sunday, August 11, 2002 7:46 AM
To: Noah
Cc: python-list at python.org
Subject: Re: Need a metavalue singleton kinda thingy as a reserved
key...


Noah wrote:
> I have a class where you can add values to a dictionary.
> I want to have a special meta key that I can use to reserve a spot
> in the dictionary. The problem is that the keys in the dictionary
> can be almost anything including None, so I can't use None as my
> reserved value. Plus I may want to defined more than one reserved key. 
> Is there a smarter way to create meta values to denote reserved keys?

Would you mind describing the problem where this is supposed to be
the solution for? 

    holger





More information about the Python-list mailing list