looking for tips on how to implement "ruby-style" Domain Specific Language in Python

Jonathan Gardner jgardner at jonathangardner.net
Tue Jan 6 23:20:01 CET 2009

On Jan 6, 12:24 pm, J Kenneth King <ja... at agentultra.com> wrote:
> Jonathan Gardner <jgard... at jonathangardner.net> writes:
> > On Jan 6, 8:18 am, sturlamolden <sturlamol... at yahoo.no> wrote:
> >> On Jan 6, 4:32 pm, mark <mark.fi... at googlemail.com> wrote:
> >> > I want to implement a internal DSL in Python. I would like the syntax
> >> > as human readable as possible.
> >> Also beware that Python is not Lisp. You cannot define new syntax (yes
> >> I've seen the goto joke).
> > This isn't really true. You can, for instance, write a program (in
> > Python) that takes your pseudo-Python and converts it into Python.
> > This is what a number of templating libraries such as Mako do.
> Which is not even close to being the same.
> Lisp - the program source is also the data format
> Python - the program source is a string
> I could go on a really long rant about how the two are worlds apart, but
> I'll let Google tell you if you're really interested.

I get that Lisp is special because you can hack on the reader as it is
reading the file in. This is strongly discouraged behavior, as far as
I know, despite the number of cute hacks you can accomplish with it.

But consider that this really isn't different than having a program
read in the lisp-with-modification source and spitting out pure lisp,
to be read by an honest-to-gosh lisp program later.

If that's the case, then Lisp and Python really aren't that different
in this regard, except that you don't have the option of modifying the
reader as it reads in the file.

More information about the Python-list mailing list