Mython: Make Python Yours.

One side of a conversation I had with myself:

What is Mython?

Mython is an extensible variant of the Python programming language. Mython makes Python extensible by adding two things: parametric quotation statement, and compile-time metaprogramming. The parametric quote statement is simply syntactic sugar for saying "run some function on this embedded string". Compile-time metaprogramming allows you to evaluate that function on the embedded string at compile time. This gives you added choice, both in terms of what your code looks like, and when you want to evaluate that code.

Can you give me an example?

Sure. Here is an example Mython program:

#! /usr/bin/env mython
from basil.lang.mython.myfront_ast import *
from basil.lang.mython import mybuiltins

def main ():
    quote mycode:
        print "You should see this at eval time!"
    print "You should see this at run time!"

print "You should see this at import time!"

quote [myfront]:
    print "You should see this at compile time!"

if __name__ == "__main__":

This outputs everything in the reverse order than it appears in the code:

$ ./ # see .../basil/lang/mython/tests/
You should see this at compile time!
You should see this at import time!
You should see this at run time!
You should see this at eval time!

This shows use of the myfront() and mython() built-in functions at compile-time, where mython() is used when the quote has no parameter.

Hey! That shows changing the "when something is run", but not changing what the code looks like. What's up with that?

Right. This is a little more complicated because we're still working on code generators. We have several parsers, but embedding a syntax tree doesn't deliver the goods quite like being able to compile down to something that actually evaluates.

Okay, so how do I use Mython?

Currently, you write a Mython script/module. This requires you to get the Basil language development framework, add Basil to your PYTHONPATH, and mython to your PATH. Doing this allows you to run the example, above. Alternately, you can compile your Mython code into a Python bytecode file (.pyc) using the MyFront compiler. For example:

$ rm *.pyc
$ MyFront
You should see this at compile time!
$ ls *.pyc
$ python -m test04
You should see this at import time!
You should see this at run time!
You should see this at eval time!

I don't use a command shell, what do I do then?

Wait until someone else plugs us into an IDE.

Basil? Wasn't this supposed to be about Mython?

The Basil project originally sought to reach "metaprogramming nirvana" by building tools. We've come to see language as the ultimate power tool, thanks in part to arm twisting, err, guidance by a certain dissertation advisor. Mython is a language capable of embedding those tools. Basil can now be seen as a codename for Mython's "standard library".

Where can I get Mython and/or Basil?

If you can't follow the link above, try going to Google Code:

Do you have any documentation?

Most of it's "academic" stuff. Please see Jon Riehl's dissertation (chapter 3 goes into some of the gory details of Mython), or the DSPD paper. When things get more stable, documentation should quickly follow on the Mython wiki.

How can I find out more, or possibly interact with Mython's developers?

There is a Google group:
There is an IRC channel on #mython
You can email the guilty party with a little more searching.

I like some of what Mython does, but what else is out there?

Mython is part of a wave of "super-glue" languages that make language embeddings easy. Some other examples include the following:

Mython will hopefully inter-operate with the above. Some other uber tech that we're looking at embedding, wrapping, and/or using is:

jriehl AT spaceship DORT com
Last modified: Tue Oct 21 13:17:38 CDT 2008