layout | image |
---|---|
home |
/assets/logo-picture.jpg |
Jactl is a powerful scripting language for Java-based applications whose syntax borrows from Java and Groovy, with a dash of Perl thrown in for good measure. See Jactl Language Features for a quick overview of some of the language features or Jactl Language Guide for a full description of the language.
Jactl is intended to be integrated into Java applications where it provides a secure, locked-down, way for customers/users to be able to customise the application behaviour.
It is especially suited to event-loop/reactive applications due to its built-in suspend/resume mechanism based on continuations that ensures it never blocks the execution thread on which it is running.
Here is some simple Jactl code:
int fib(int x) {
return x <= 2 ? 1 : fib(x-1) + fib(x-2);
}
println 'fib(20) = ' + fib(20);
Since in Jactl semicolons are optional, typing is optional, return
is optional for the last expression
of a function, and double-quoted strings allow for embedded expressions, so the previous example
can also be written like this:
def fib(x) { x <= 2 ? 1 : fib(x-1) + fib(x-2) }
println "fib(20) = ${fib(20)}"
A simple quicksort:
def qsort(x) {
switch (x) {
[],[_] -> x
[h,*t] -> qsort(t.filter{it < h}) + h + qsort(t.filter{it >= h})
}
}
Here is a more advanced example which streams the input as lines, searches for markdown headings and generates a table of contents:
// Sanitise text to make suitable for a link
def linkify = { s/ /-/g; s/[^\w-]//g }
// Find all top level headings in input and generate markdown for table of contents:
stream(nextLine).filter{ /^# /r }
.map{ $1 if /^# (.*)/r }
.map{ "* [$it](#${ linkify(it.toLowerCase()) })" }
.each{ println it }
To get a feel for how the language looks and the type of language features that Jactl offers see the Language Features page.
You can download the Jactl library and find the source code for Jactl at GitHub: jactl
To start playing with Jactl and for testing out code interactively, you can use the Read-Evaluate-Print-Loop (REPL) utility.
To see how to use Jactl from the command line see the page about command line scripts.
To learn how to integrate Jactl into your application see the Integration Guide.
To integrate Jactl into a Vert.x based application have a look at the jactl-vertx library.
To learn more about the language itself read the Language Guide.