Tea
Tea is a high-level scripting language for the Java platform, begun in mid-1997 at the Portuguese software house PDM&FC by Jorge Nunes. It borrows Tcl's word-at-a-time syntax and Scheme's semantics - real closures, functions as first-class objects - and runs entirely inside a JVM, where it was used as the application-logic language of the I*Tea application server behind Portuguese home-banking and ISP-management systems. Public releases ran from Tea 1.2 in 2000 to 3.2.6 in 2011; the Tea 4 line never left beta and the last commit was made in February 2020
Created by Jorge Nunes, at PDM&FC - Projecto, Desenvolvimento, Manutencao, Formacao e Consultoria, a software house in Lisbon, Portugal. Nunes is the author of the language and of nearly all of the early source tree; the June 2000 white paper is co-signed by Joao Paulo Luis and Luis Miguel Campos, and Joao Paulo Luis (the initials jpsl in the commit log) did most of the Tea 4 and Tea Engine work a decade later. The project has been on GitHub under Nunes's own account since 2012
Tea is a scripting language for the Java platform, written in Lisbon by Jorge Nunes at the software house PDM&FC. Its own home page summarised it in one sentence that has not been improved on since: Tea is a high level scripting language for the Java environment. It combines the best features from Scheme, Tcl and Java.
That is an accurate description and a strange one. Tea looks like Tcl — statements are lines of whitespace-separated words, the first word naming a function, with $ for variable substitution and square brackets for command substitution. It behaves like Scheme — functions are first-class objects, lambda produces genuine lexical closures, and control flow is a set of ordinary functions rather than syntax. And it lives entirely inside a JVM, where its reason for existing was to be embedded in Java systems that needed a scripting layer.
Encyclopaedias and download archives often list the language as TEA in capitals, which is how the release tarballs were named (TEA-2.0.1, TEA-3.0.0); the project itself always wrote it Tea.
Where it came from
The white paper PDM&FC published in June 2000 is unusually direct about the motivation:
When work first began on the Tea programming language in mid 1997 there were no interpreters for scripting languages that could be used from within a pure Java environment. Three years later there are now at least two mainstream scripting languages with interpreters written in Java, these being Tcl and Python.
That is the whole story in two sentences. In 1997 a Java shop that wanted a scripting language had nothing to embed — Jython and Jacl were still ahead — and PDM&FC was building web applications for Portuguese banks and telcos that needed exactly that: a fast-turnaround language for presentation logic, sitting on top of Java components, in a process that could not be restarted for every change. Rather than port an existing language, they wrote one, on the argument that the existing candidates had limitations of their own worth escaping.
The language was therefore in production for years before anyone outside PDM&FC could download it. The project’s own history.txt starts on 24 September 1999, and its first entry is already the housekeeping of a working system — trimming the set of functions the autoload module pulls in at start-up — with autoloading of natively implemented classes following in October and the switch from OROMatcher to gnu.regexp in November. The oldest public announcement that survives is for the Tea Development Kit 1.2.0 on 11 November 2000. Tea 2.0.0, on 18 February 2001, was the first release with a proper web page behind it, and the first in which the Java API for writing extensions was made public and documented — which is why so many catalogues record Tea as a 2001 language. Tea 3.0.0 followed on 24 September the same year.
The language
A Tea program is a sequence of statements; a statement is a sequence of words; the first word is the function and the rest are its arguments. There is no operator syntax and no statement syntax. Arithmetic is a function call:
define square ( x ) {
* $x $x
}
echo [square 4]
define creates a variable or function in the current context, $x substitutes a variable’s value, and [ ... ] runs a command and substitutes its result. A function returns the value of its last statement, so * $x $x is the body and the return value at once.
Because if and while are functions and not keywords, their branches have to be passed as objects. That is what braces produce — a code block, a first-class value that can be stored, passed and executed later:
define factorial ( n ) {
if { < $n 2 } {
is 1
} {
* $n [factorial [- $n 1]]
}
}
define x 1
while { <= $x 10 } {
echo $x
set! x [+ $x 1]
}
define lst ("One" "Two" 3 4 "Five")
foreach elem $lst {
echo $elem
}
The functional core shows itself in closures, which the tutorial demonstrates with the canonical example:
define make-adder ( n ) {
lambda ( x ) { + $x $n }
}
define adder5 [make-adder 5]
define adder8 [make-adder 8]
echo [adder5 2]
echo [adder8 2]
A new context is created whenever a code block is executed, and it is a child of the context in which the block was referenced, so the n captured by the lambda stays alive with it. define writes into the current context; global writes into the top one.
Types, and the split from Tcl
Superficially Tea reads like Tcl, and the white paper is at pains to say that the resemblance is misleading:
For instance, in Tcl everything is a string while in Tea every object has a certain type. As for comparing with Scheme, there is no macro mechanism like in Scheme. There is no need for one, actually.
The built-in types are symbols, strings, numeric objects, booleans, lists, code blocks and functions, plus a single null object. Variables are untyped — they hold references, and two variables can reference the same object — but what they reference is typed.
The Tea Object System
Object orientation is not built into the language either. It is a library, TOS, delivered as the functions class, method and new, with single inheritance, dynamic typing, and classes that are themselves ordinary objects:
class Rectangle (
_width
_height
)
method Rectangle constructor ( w h ) {
set! _width $w
set! _height $h
}
method Rectangle getArea () {
* $_width $_height
}
class Square Rectangle ()
method Square constructor ( size ) {
$super constructor $size $size
}
All members are private, in a stricter sense than most languages mean by the word: they are reachable only from methods of the class that declared them, not from methods of derived classes.
Autoloading
One design decision deserves more credit than it got. Both Java-implemented and Tea-implemented library code are loaded lazily — a class or function’s defining file is executed only the first time something actually calls it. On the JVMs of 1999, in a long-running application server, that mattered a great deal; the white paper sells it as leading to very efficient memory usage, and it is why Tea’s standard library could grow modules for XML, LDAP, JDBC and networking without every script paying for them.
Embedding
Tea is an embedded language first: it was made to be dropped into a Java system, not to run scripts from a shell prompt (though tsh, the Tea shell, does exactly that). Extensions are Java classes registered as Tea modules, and from Tea 3.2.0 in January 2006 the tea.java module let scripts reach in the other direction and manipulate Java objects directly.
The tidiest form of the arrangement arrived late. The teaEngine adaptor was already being offered as a standalone teaEngine-0.7.0.jar to drop alongside tea-3.x.y.jar by 2007; in September 2010 it was merged into the Tea 4 trunk, making Tea a JSR-223 script engine like any other:
| |
The engine documentation notes, with some justice, that Tea exists as a 100% Pure Java scripting language long before the JSR 223 — the standard caught up with the language rather than the other way round.
Runtime requirements
These changed over the language’s life and are worth stating precisely, because the claims are not interchangeable. The 2001 site said the runtime required a JVM conforming to Java 1.1 and named Sun’s JVMs and Kaffe as choices. The project wiki, written for Tea 4, says Tea runs anywhere with a Java 1.6 JVM or higher. Building Tea 4 from source, per the repository’s own README, needs JDK 1.8 and Maven 3.3 or later. Regular expressions originally required gnu.regexp 1.0.8 as an external library and XML processing required a third-party SAX parser such as IBM’s XML4J; both dependencies were removed in favour of the standard JRE facilities in February and March 2010.
Licensing
Tea was never quite free software and never quite proprietary. The 2001 licensing page offered it free of charge for non-commercial use and asked commercial users — whether shipping it standalone or embedded in a larger Java system — to write to [email protected]. Encyclopaedia entries describing Tea as a proprietary language with a non-free interpreter are describing that era, and are now out of date: in April 2011 the Tea 4 tree was relicensed, and the source distribution today ships the GNU GPL version 3 alongside a note that PDM&FC will also license it under a specific agreement.
Other people’s Tea
Two third-party efforts are worth recording, both from 2008 and both aimed at getting out from under the interpreter. destea, published on CPAN as Language::Tea by Mario Silva, Daniel Ruoso and Flavio Glock, translated Tea source into Java; its README is honest about the limits, noting that it cannot yet make a plausible translation of closures and that Tea’s habit of reassigning a variable to a different type translates into a Java compile error. TeaClipse, a Google Code project labelled with the initials of Worcester Polytechnic Institute, was a JavaCC- and JJTree-based compiler and syntax-highlighting editor for a subset of the language.
The WPI connection is not accidental — a Major Qualifying Project by Khue Huynh and Leena Razzaq, dated 2002 in the WPI repository, built a distance-learning system for Tea programming — but the total volume of outside work on the language remains small.
Not the other Tea
Searches for this language collide with an unrelated one. Tea is also the name of a typed template language created at Starwave and later the Walt Disney Internet Group, which lives on with the TeaServlet in the open-source TeaTrove project and was long used at ESPN.com. The two share nothing but a name: PDM&FC’s Tea is an interpreted general-purpose scripting language with Scheme semantics, Disney’s Tea is a compiled template language for generating pages. Reference pages that attribute a proprietary bytecode format, or a mention in O’Reilly’s Java Servlet Programming, to the language described here should be treated with suspicion.
Where it stands
Tea is dormant in the ordinary sense of the word. The 3.2.x maintenance branch ended with 3.2.6 on 20 July 2011. Tea 4, which brought the JSR-223 engine, the GPL and the removal of the last external dependencies, reached 4.0.0-beta06 in February 2012 and stopped; the master branch still declares itself 4.0.0b10-SNAPSHOT. Commits trickled on — Jacoco coverage reports and a release-tarball tool in 2017, a Checkstyle bump in 2019 — and ended on 1 February 2020 with a change to the Travis CI configuration. PDM&FC is still in business; its Tea pages are gone.
Why it matters
Tea is a clean specimen of a problem that a whole generation of language design was answering at once. Between 1997 and 2001, several groups reached the same conclusion — that the JVM was becoming the place where business software ran, that Java itself was too slow to write and too rigid to change in place, and that what was missing was a scripting layer for it. Jython, Jacl, BeanShell, Groovy and eventually JSR-223 itself all came out of that pressure. Tea got there first, in mid-1997, from a Lisbon software house that needed one for its own home-banking work and simply wrote it.
It is also a small, coherent demonstration of a design idea that has aged well: build a language whose syntax has almost nothing in it, and put the control structures, the object system and the module system into the library, as functions taking code blocks. if is a function; class is a function; foreach is a function. That is the Tcl and Lisp lesson applied to a Java runtime, and it is why the whole language can be described in the eight tutorial decks that survive in the project wiki. What Tea lacked was never expressiveness — it was a community outside the company that built it, and the moment mainstream alternatives arrived on the JVM, that shortfall decided things.
Timeline
Notable Uses & Legacy
The I*Tea application server
PDM&FC's own Java application server, described in the June 2000 white paper as one of the major uses of Tea and totally based on Java. Tea was the language in which the server's application logic was written, and the 2001 tutorial slides repeat the description. Every other deployment named below was built on top of it
Portuguese internet home banking
The white paper names three internet home-banking applications for major Portuguese banks - BPSM (Banco Pinto & Sotto Mayor), BTA (Banco Totta & Acores) and CPP (Credito Predial Portugues) - all built on the I*Tea application server, with Tea coding the whole of the presentation-layer logic
Telepac ISP management system
An integrated management system for Telepac, then the largest ISP in Portugal, described in the white paper as involving over a million lines of code and running 24/7 as a business-critical system, with CRM components including customer self-service and help-desk applications, plus billing modules. Tea was the programming language of the system
Online brokerage at L. J. Carregosa
An online brokerage application, cited in the white paper as about to enter production at the time of writing in mid-2000 and in the 2001 tutorial slides as a large research database with content-management tools for research information implemented in Tea
TeaDoc
The language's own documentation generator, shipped in the source tree under apps/teadoc and written entirely in Tea - roughly two dozen Tea classes that parse doc comments out of Java and Tea sources and emit HTML. It is the largest readable Tea program that survives, and doubles as the reference sample of Tea's object system in real use