Choice of language

Bob Glickstein bobg at
Tue May 16 19:02:22 CEST 2000

Chuck Esterbrook writes:
> Given the success, maturity, functionality and stability of the
> Python programming language, as well as the ease of embedding and
> extending it, has anyone in the Latte community considered creating
> a Python version of Latte?

Well it certainly sounds like you have!

I only know a little about Python thus far (and I like what I know),
but I believe it would be wholly unsuitable for and/or very difficult
to adapt to the job that Latte does (as is also the case with many
other successful, mature languages).  The main problem is that Latte
documents must mix together code and text in a syntactically pleasing
way.  I believe Latte achieves this in the most syntactically friendly
way possible, because the syntax of the code portions of Latte is
very, very simple: there are {...}  constructs and \... constructs,
and that's it.  If you want to include {, }, or \ in text, you escape
it with a backslash: \{, \}, and \\.  The choice of { } and \ was made
because those characters occur rarely in (English) text, so collisions
between code and text are minimal.

Python, on the other hand, has numerous syntactic constructs, all of
which have to be distinguishable from text.  This would dramatically
increase the need for quoting and escaping in Latte, which would
violate the overriding design consideration.

Also, because Python's syntax is line-oriented and because whitespace
is significant, it would be much harder to mix together code and text
and preserve the layout of the original.  For instance, if this were a
Latte paragraph, I could embed a call to {\function} like so and the
output of the function would appear integrated into the paragraph,
with the surrounding whitespace intact.  Latte uses a particular model
to represent the lexical structure of the input document, including
the whitespace surrounding each word and code construct, that does not
appear workable with Python's lexical structure.

On the other hand, I don't want to discourage you if what you'd like
to do is Pythonize Latte.  Here's what you'd have to do: concoct a
syntax that allows you to represent text and code together, and then
write a parser for it that can produce a parse tree in the same format
as that produced by Latte's existing reader.cxx/grammar.y.  You'll
probably need a new subclass of Latte_Obj to represent regions of
Python code, and the eval() of your new subclass would call the Python
interpreter and convert the output into other Latte_Objs (like
Latte_Lists, Latte_Groups, and Latte_Strs).  Finally, you might want
to wire up the Latte intrinsics in definitions.cxx to be callable from
Python, although most of the intrinsics have Python equivalents, so
this may not be strictly necessary.

If you decide to undertake this project, please let me know.  I'd be
most curious to follow its progress and provide what assistance I can.

- Bob

PS: For the benefit of other readers of this message: Latte can be
found at <>.

More information about the Python-list mailing list