Mantra (Hindi for "magical incantation") is a new dynamically-typed programming language that is syntactically similar to Java but with the flexibility and ease of programming of Ruby or Python. Mantra is not an interpreted language. Source code is translated to Java and so mantra programs integrate trivially with plain Java code.
Mantra is meant as a research platform and to teach language design and implementation. Nonetheless, it should prove a nice little language.
Credits. Jean Bovet and I designed the original statically typed version of Mantra. Summer 2007 Yang Jiang implemented a simple dynamically typed language similar to Mantra, which helped me think about what I wanted. I have had some very useful conversations with Peter Burns that helped me narrow down the functionality. Professor Greg Benson has helped me think about the runtime. Talked to John Mitchell about the language definition. Kay Roepke is always helpful to talk to; e.g., he helped to refine the contains and mixin functionality. Tom Burns gave me ideas on dynamic mixins. Boulos (Paul) Aoun suggested the file extension ".om".
Abstract. Mantra is a clear descendant of Java in terms of syntax, but more like Ruby and Python because Mantra is dynamically typed (though mantra has type annotations). Like Ruby, Mantra has real closure support and the closure-following-method-call syntax for passing closures to functions. If Mantra has anything new and interesting, it's POP: pipeline-oriented programming or pipe-oriented programming. The pipeline statement implicitly launches threads on the actors in the pipeline and hooks up their input and output streams. The pipeline statement is directly analogous to pipes and I/O redirection on UNIX commandline.
Mantra is meant as a research platform and to teach language design and implementation. Nonetheless, it should prove a nice little language. Mantra will be very good at scripting like Ruby and Python, but personally I don't think purely dynamically typed languages should be used for very large programs that must be maintained. Mantra makes an excellent compromise with its type annotations. Mantra is still dynamically typed, but you can specify the types of arguments and fields. Type information is very useful for optimizing the generated code and for any syntax/semantics-aware editors. Most importantly, however, the type information is useful for programmers trying to read code. Anyone who uses Python or Ruby knows the annoyance of looking at a library routine whose arguments are "a, b" and not knowing what kind of types they can pass in. See the section below for more information.
The implementation translates Mantra to Java and therefore Mantra has the potential to run much faster than Ruby or Python due to their purely interpreted nature. Current experiments support this expectation. The syntax and semantics of the language are fairly straightforward and the implementation is a devious but relatively small 2500 lines of Java. My current implementation took about five or six weeks. I was originally going to hold my implementation private until spring 2008 because I wanted my students to implement Mantra. Mantra has evolved way past a student project at this point, though, and so I am releasing it so people can try it out and learn from it.
Prashant Deva built a Mantra plug-in for Eclipse that does syntax highlighting and such for Mantra. Portions of the code are Eclipse EPL licensed; rest written by Prashant.
I realized that we need the notion of a tuple like Python. List [1,2] is fundamentally an ordered thing not an aggregate of two elements. A tuple (1,2) treats those as separate elements whereas I can think of the list as one thing if I pass it to a function. A tuple is not accessed like a list and really is used to only hold multiple values. I could use this for parallel assignment, but I don't have that and I'm not sure I want it.…
You can now refer to any regular Java object from within mantra simply by using a variant on the import statement: import java java.util.Vector; Vector v = Vector(); v.add("hi"); v.add(34); println(v.toString()); println(v.get(0)); println(v.get(1)); Field access works as well for now, it translates only string and integer objects to mantra objects. For other objects, it leads them as Java objects wrapped in a JavaProxyObject.
imports allowed with main programs / scripts now. import a::b; println("hi");
added for-each construct.