Special-purpose extension of Python -- new kinds of objects

Robert Dodier robert_dodier at yahoo.com
Sun Dec 28 17:42:42 EST 2003


Hello,

I have an idea, thus far half-baked, to create a language called
Ephemeral, for "flexible modeling & reasoning language".
I'd like some advice about how to go about implementing it.

Ephemeral would be Python plus additional constructs to support
decision analysis -- what's needed are essentially specifications
of probability and utility functions. Let's not worry about whether
such a language would be usefult to anyone. 

The goal here is to merge the description of the probability and
utility stuff with Python in general. I would like for objects
of these new types to appear in ordinary Python functions so that
they can be manipulated. Here's an example:

  # "dn" == "decision network", an Ephemeral construct;
  # this part is parsed separately from the python code
  dn my_example:
    chance X:
      cpd: gaussian [mean: 25, std_dev: 75]
    chance Y:
      cpd: gaussian [mean: 12, std_dev: 19]
    chance Z = X + Y

  # this part is ordinary python code; nodes, cpd, parents, and
  # and posterior are constructed automatically from above description
  def __main__:
    print my_example.nodes          # "[X, Y, Z]"
    print my_example.X.cpd          # "gaussian [mean: 25, std_dev: 75]"
    print my_example.Z.parents      # "[X, Y]"
    print my_example.Z.posterior    # "gaussian [mean: 37, std_dev: 77.4]"


One way to look at this is that it is ordinary Python code with
new kinds of objects embedded in it. Another approach would be to
embed Python functions in a decision network. I think that it will
generally be more powerful and flexible to embed the new stuff in
Python rather than vice versa. How can I start going about this?

Are there other projects that have a similar spirit -- 
extending Python with special purpose language constructs?

Thanks for any comments,
Robert Dodier
--
If I have not seen as far as others, it is because 
giants were standing on my shoulders. -- Hal Abelson




More information about the Python-list mailing list