Embedding questions

Olaf Appelt tholap at compuserve.com
Wed Dec 8 21:52:25 EST 1999


Hi,


I'm maintaining a proprietary half-baked interpreter environment within a
large commercial application (written in C++), that looks mostly like Basic
with some important properties added.
It basically allows people who are no experts in programming to produce
financial software.
GUI and DB access is automatic. Within this environment the 'programmer'
mostly just does some calculations with a lot of ifs and the occasional for
loop.

I would like to replace that beast with Python. Perhaps just using the
interpreter with a simple translation from our Pseudo-BASIC to Python,
perhaps even Python as a language.

After looking at Python for a few hours it looks sane enough to be
digestible for the non-expert programmer (unlike another popular freeware
scripting language ;-) ).
The added functionality we need could probably be done via classes. And here
is already my first problem.
It is important that the programmer can use pre-defined named variables with
particular properties.
In short I need to have types.

All I need can be implemented with classes (I think). Luckily Python allows
defintinition of operator methods so I can make this classes mostly behave
like typical variables.
Sadly I cannot redefine assignment.

class Currency
...

c = Currency ()

c = 5

The above, if I got this correctly would make c first an instance of class
Currency and then re-assign that name to a different variable of type
integer.

That is fine for most temporary variables used during calculations, but at
the end all results have to end up in a set of variables with particular
names, that also have particular type information.

A possible solution would be to define something like

class Currency
...
    def assign (self, other)
        self.value = other
...

but that would look rather ugly:

c.assign (a + b)

instead of the usual

c = a + b

One way to solve this problem is to keep our Basic dialect and simply
translate it (in a primitive compile step) to Python, but I would prefer to
not maintain this language just to keep assignment looking good.

Furthermore I want to avoid having module files lying around in directories.
The code should be compiled, go into database and later be read from db to
be executed. All that without going files. Just strings moved between Python
API and DB.

Is that possible?


Any comments are appreciated.


Olaf






More information about the Python-list mailing list