Short Overview of Templet 3.0
A Scripting Language for the Web
18 January 1999

Copyright 1997,1998, 1999 Ellis S. Cohen, All Rights Reserved

The Templet language was developed initially as a server-side scripting language for generating HTML. However, it is suitable for client-side scripting as well, although availability of the client-side plug-in will follow availability of the rest of the system.

As a standalone system, Templet is suitable for many other text generation and string processing tasks, including XML processing. It is, in fact, a complete general-purpose programming language.

Relation to HTML

Templet was designed to integrate well with HTML and derives its main syntactic features from HTML. The principal driving force for Templet 1.0 was to make it as easy as possible for HTML developers to initially use a small set of Templet features that mimicked HTML features. As Templet has evolved, it has grown somewhat more complex, but the essential principle of HTML similarity remains. In particular

Power and Simplicity

Templet 3.0 is a programming language that has great power, yet can support frequently used idioms with great simplicity. For example, by combining its loop, string list, and substitution features, one can write
  [foreach Sandi|Andee|Kathleen]
    I loved [$].<br>
  [/foreach]
which will display

A local variable could have been used to store the list of names, so the display above could also have been generated by

  [do &names = Sandi|Andee|Kathleen]
  [foreach &names]
    I loved [$].<br>
  [/foreach]
Adding optional clauses provides even more power:
  [foreach Sandi|Andee|Kathleen][:trim][:separate ", and "]
    I loved [$]
  [/foreach]!
generates

Dynamic generation of input controls is just as easy. For example
  I loved
  <SELECT>
    [foreach Sandi|Andee|Kathleen]
      <OPTION VALUE="[$]">[$]
    [/foreach]
  </SELECT>
generates

Database extraction is almost as easy. The DB.SELECT function uses standard SQL, except the SQL itself can be dynamically generated in the same way that other text is. To display all marriages recorded in the Marriages table in the past year, write:

  [do
    &cutoff = [date];
    &cutoff.year--;
  ]
  [DB.SELECT husband, wife, marrydate
    FROM Marriages
    WHERE marrydate > [&cutoff]
  ]
      [$husband] was married to [$wife] on [$marrydate].<br>
  [/SELECT]
which could generate Including the appropriate HTML will generate a table instead:
  <TABLE BORDER=1 CELLSPACING=1>
    <TR>
    [foreach Husband|Wife|Date]
      <TD><B>[$]</B></TD>
    [/foreach]
    </TR>
  [do
    &cutoff = [date];
    &cutoff.year--;
  ]
  [DB.SELECT husband, wife, marrydate
    FROM Marriages
    WHERE marrydate > [&cutoff]
  ]
    <TR>
    [foreach [$husband]|[$wife]|[$marrydate]]
      <TD>[$]</TD>
    [/foreach]
    </TR>
  [/SELECT]
  </TABLE>
could generate

Features

Templet's syntactic and semantic model borrows features from a somewhat eclectic set of programming languages including (in alphabetical order) Alphard, APL, Java, Javascript, Perl, Scheme (and other LISPs), and Smalltalk.

The Templet 3.0 design is distinguished by the following features:

Templet comes with a wide variety of built-in and library classes, including Class, Object, String, List, Dictionary, SortedList, SortedDictionary, Date, Time, Timestamp, Function, Environment, Conductor, Promise, LazyList, Enumeration, Stream, PatternMatcher, Thread, Lock, Database and Query.

Templet also includes classes that provide significant server-side functionality and web support, including transparent construction of URLs for links, (frame & image) sources, and forms. Exercising these URLs invokes specified server-side Templet functions, passing along request-specific values and/or automatically generated session-id's, which are either encoded in the URL or provided via cookies. These classes also provide functions that simplify construction of input elements, especially those with dynamically-determined initial values.

As a web-driven back-end, Templet can either run as a Java servlet or as a separate Templet server, depending on a servlet, other server plug-in or CGI program to pass appropriate HTTP requests on to the Templet server; other configurations can be readily supported.

Templet's built-in functions are implemented in Java; user-defined functions can be implemented in Java as well. Public Java API's for all Templet object are available for use within user-defined functions.

There is no present support for a security model. Currently we assume that all code is server-side and open. Any access controls (e.g. private fields) are to support programming safety rather than security.

For more information on Templet's features, see

  1. System Entities
  2. Environments
  3. Application and Parameters
  4. Constructing Values and Variables
  5. Fields and Aliases
  6. Infix Mode
  7. Advanced Parameter Topics
  8. Conductors
  9. Defining Functions
  10. Defining Classes
  11. Enumerations, Streams, Promises and LazyLists
  12. Compilation
  13. User-Defined Aliases and Mediators
  14. Web and Database Support

You can also find out about the history of Templet.

Contact Ellis S. Cohen (e.cohen@acm.org) for more information on availability or on how you can participate in the implementation.

Disclaimer