[albatross-users] Re: Python embedded like PHP

Ian Bicking ianb at colorstudy.com
Tue Mar 26 02:11:59 EST 2002


On Mon, 2002-03-25 at 08:09, Dave Cole wrote:
> > For this problem, I think the solution is in the interpreter -- your
> > macros are just hard to work with (from what I can see), because
> > they are dynamically scoped and being used in lieu of real
> > functions.  It's not a syntax issue.
> 
> I would really like it if you could explain a little further.
> 
> The macros do sort of work like functions in that they pass arbitrary
> template content to the macro for substitution at the location
> specified by the macro.
> 
> I tried to work out a simple way in which values from the execution
> context namespace could be passed as arguments but couldn't see how to
> do it in a nice fashion

Well, you might be able to help the situation some if you create a new
scope for the macro, and have something like dtml-let -- that way you
could do stuff like.  That way variable assignments inside your macro
will pass out of scope when the macro finishes, and at least not
overwrite things in the main scope.  You can use some form of let to
manipulate the namespace when it doesn't match what the macro expects. 
This is what DTML does, and I assume ZPT uses the same mechanisms (it
only seems to be a change of syntax).

I don't like this at all, though, as there's all sorts of problems that
pop up when you start abstracting things more deeply.  Also, I think
macros are very important, and keeping them python-like is a very nice. 
Then you can define, inside a single template, not only the full page
style, but the style of components of the page.  For instance, I create
pages that create headers with lists underneath them, all entirely
dynamic.  If the template can define what a header and what a list
should look like, then I have much more power over the look of the page.

I'd pass arguments like:

<al-somemacro arg1="value1" arg2="value2">

This seems pretty straight-forward, and also maps directly to keyword
arguments.  You could add the syntax:

<al-somemacro arg1 arg2="value2">

(which isn't XML, but so it goes), which would equivalent to
<al-somemacro arg1="arg1" arg2="value2"> -- basically saying which parts
of the namespace to pass in.  It should also be fairly easy to create
Python functions that do the same thing as the macro.

Some people will still want to pass in entire namespaces... you  could
use inclusion instead of macros in that case, or make another form of
macros.  You could also make another form of setting variables, that
sets them globally (perhaps as constants) -- this is much cleaner than
making every passing variable and loop global.

  Ian





More information about the Albatross-users mailing list