[Baypiggies] puzzle: binding invocation context for a function call during a class declaration

Bill Janssen janssen at parc.com
Wed Jan 5 18:41:50 CET 2011

Bill Janssen <janssen at parc.com> wrote:

> I'm puzzling out how one would ape a declarative language in Python.
> For instance, take a language that has declarations like
>   concept Foo {
>     is-a A;
>     is-a B;
>     part-of X;
>     public int counter;
>     public analogue bar;
>   }
>   expression Bletch {
>     expresses Foo;
>     counter = 3;
>   }
> where "concept", "public", "is-a", "part-of", "int", "analogue",
> "expression", and "expresses" are all keywords.
> Since it's largely declarative, I'd naturally express it in Python as a
> set of class declarations:
>   from mylang import is_a, part_of, Concept, Expression, attribute, public, analogue, expresses
>   class Foo (Concept):
>     is_a(A);
>     is_a(B);
>     part_of(X);
>     counter = attribute(public, int)
>     bar = attribute(public, analogue)
>   class Bletch (Expression):
>     expresses(Foo)
>     counter = 3

I think I've figured out what I need here.

First of all, I'm not going to execute this "code", so I don't need
things to work at execution time.  What I need is the compiler, and
the resulting AST.  If you look at the AST for the following:

   class Foo (Bar):


you get this:

    Stmt([Class('Foo', [Name('Bar')],
      Stmt([Discard(CallFunc(Name('is_a'), [Name('Bletch')], None, None))])

So the interpreter for "mylang" could just run the compiler, and
interpret the AST here, and it would have the info I want to pass.

Thanks for the discussion!


More information about the Baypiggies mailing list