Pnuts Highlights


First Impression - Hello World


Second Impression - Higher-Level Functions, Loops and Data Types


Full Access to the Java API

Pnuts provides far more expressive power than Java, yet retains access to all Java classes. Many times the code can be written nearly identically. You can choose when to use the more expressive Pnuts features. This makes Pnuts very easy for Java developers to pick up.


Automatic Bean Property Access

Built-In Syntax for Arrays and Lists


Built-In Syntax for Maps


More Array, List, and Map Examples

Nested Arrays
Ranges
Operator Overloading


Element Selection for Arrays and Collections


Generators and Generator Selection


Loop and Index Strings


Literal Strings


Exception Handling

Pnuts gives detailed error messages when an exception occurs. The Pnuts script and line number even appears in the Java stacktrace. Also, error messages are localized.

Performance

Pnuts scripts can be compiled to JVM bytecode for ultimate performance. Pnuts can be run in interpreted mode, it can compile on the fly, or scripts can be compiled beforehand.

Pnuts is one of the fastest scripting languages for the JVM. One secret of the efficient implementation is sophisticated method caching. Usually Pnuts does not use the Reflection API to call methods, even when accessing JavaBean properties. Pnuts generates method proxies on the fly and reuses them. The Reflection API is used only when a method proxy can't be used because of a classloader mismatch. It is true that searching appropriate methods from actual arguments is expensive, but the impact is almost completely invisible, thanks to the method cache. In fact, method calls in Pnuts are even faster than that of Ruby.

Click the images below for more information.








Modules

The core Pnuts language is kept small and simple. More advanced functionality is provided by a powerful extension module system. This makes Pnuts syntax simple and easy to learn while not losing any advanced functionality. Many other languages tend to add more and more to the core of the language and eventually end up monolithic, difficult to read, and harder to learn.

Pnuts has over 70 modules available here, here, and in source control. Here are some examples of the various modules: IO functions, aspect oriented scripting, Hibernate, POSIX functions, HTML parsing, functional programming, VB script emulation, JSR-223, Jakarta BSF, Win32 COM object access, regular expressions, etc.



pnuts.servlet Module: Pnuts Server Side Scripting

Pnuts can be used in a servlet container (eg, Tomcat) as the server side scripting language for web applications. Pnuts script can be embedded into HTML pages. This allows Pnuts to be used as a replacement for JSP, PHP, ASP, etc. Pnuts includes a debugger that can be used to step through and inspect your web application scripts. The full power of Java with the ease of scripting in Pnuts makes for a powerful web development tool.

The pnuts.servlet module also includes the ability to perform regex based URL rewriting (eg, Apache's mod_rewrite). This can simplify URLs and help with search engine optimization.



pnuts.xml Module: XML Node Access


pnuts.xml Module: XML Node Creation


pnuts.lib Module: Aggregate Mode

When aggregate mode is on, field access of a Collection applies the operation to each element and returns a Collection of results.
When aggregate mode is on, "Collection[boolExpr]" returns a Collection containing elements where the boolean expression is true.
The same can also be done without aggregate mode.
When aggregate mode is on, "Collection.property = value" sets the bean property or public field on all elements and "Collection[boolExpr] = value" does so where the boolean expression is true.
When aggregate mode is on, the binary operations +, -, and * are defined for java.util.Set.


metaobject Module: Prototype Based Programming


pnuts.jdbc Module

Many modules, such as pnuts.jdbc, simply provide a higher level API over an existing Java API. In most cases this allows you to write much less code. However, since access to all of Java is still available, you can use the standard Java API if you like.


Written for the JVM

Many other langauges have a mismatch between the JVM and their own type system and other semantics. Pnuts was written from the beginning to be a JVM langauge.



Conclusion

With Pnuts, you get easy to write code with far more expressive power than the default JVM language (Java).



Resources

The Pnuts Language
Pnuts User's Guide
Pnuts syntax quick reference
Pnuts downloads
Quickstart Guide
Other articles

Author: Nathan Sweet