ANN: a mini-language for encapsulating deep-copy operations on Python data structures

Steve Howell showell30 at
Wed Nov 18 09:49:34 CET 2009

During the last few days I have written code in support of a small DDL
language that encapsulates a concise representation of the
manipulations needed to make a deep subcopy of a Python-like data
structure. It is inspired by syntax from mainstream modern languages,
including, of course, Python. The DDL can be converted to an AST. That
AST can be walked to either generate Python code that expresses the
mapping or to generate Python objects that can execute the mapping.
Either of the prior outputs can then subsequently be applied to real
world inputs to create new Python data structures from old ones, using
the mechanisms specified in the original DDL for attribute access,
dictionary lookup, iteration, method invocation, etc.

Here is an example of the DDL (and I hate the terminology "DDL," just
cannot think of anything better):

                'author' {
                    .person 'name',
                    .person 'location' as city,
                        .cost() as expense
                        ] as books}

There are more details here:

Apart from shamelessly plugging my blog, I am hoping to generate
ideas, constructive criticism, etc.

Feel free to comment here or on the blog.  So far there are three
entries on the blog, all pertaining to Python.

The implementation of the idea is quite new, but it is a topic that I
have been pondering for a long time--no matter how expressive your
programming language of choice might be, there are certain programming
tasks that just seem needlessly tedious.  The mini-language above
proposes to solve one problem but solve it well.

I am particularly interested to find out whether somebody has tried
something like this before.

More information about the Python-list mailing list