A scripting language for Java-based applications
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.
Familiar Syntax
Subset of Java/Groovy syntax with a touch of Perl mixed in.
Compiles to Java Bytecode
Compiles to bytecode for fast execution times. Supports Java 8 (and later).
Never Blocks
Built-in continuation mechanism allows scripts to suspend execution while waiting for asynchronous reponses and then resume from where they left off. Execution thread is never blocked while waiting for a long-running response.
Secure
Scripts are tightly controlled. They can only perform operations provided as language functions by the application in which Jactl is embedded.
Checkpointing Execution State
Execution state can be checkpointed and persisted or distributed over a network to allow scripts to be recovered and resumed from where they left off after a failure.
No Dependencies
Jactl does not have any dependencies on any other libraries (apart from an embedded instance of the stand-alone ASM library).
REPL and Commandline Scripts
As well as being integrated into Java applications, Jactl can run as commandline scripts and has a REPL for interactively trying out Jactl code.
Open Source
Jactl is open sourced here under the Apache License 2.0.
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.
Simple Example
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)}"
More Advanced Example
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 }
Getting Started
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.
Posts
Announcing Jactl 2.0.0
Jactl 2.0.0 is a major release that fixes a few bugs and adds some new language features. The biggest new feature is powerful pattern matching with destructuring via a new switch expression.
Pattern Matching and Destructuring
The forthcoming Jactl release (2.0.0) introduces switch expressions which provide the same functionality as switch statements/expressions in Java but, in addition, also provides the ability to do powerful pattern matching with destructuring that is common in many functional languages.
Advent Of Code 2023 - Day 9
An easy day where we had to calculate the next number for each of a given set of number series. After stumbling on a stupid mistake with an iterative approach, the recursive approach worked first time and ended up as a much nicer solution.
Advent Of Code 2023 - Day 8
Another fun day. As usual part 2 could not be brute forced so needed some lateral thinking.
Advent Of Code 2023 - Day 7
Today did not require too much cleverness but there were a couple of traps to watch out for.
Advent Of Code 2023 - Day 6
Once again, an even day seems to be easier than an odd day. I am sure it is just a coincidence.
Advent Of Code 2023 - Day 5
Part 2 of day 5 was a bit of a challenge to get right. A nice feeling to have completed it.
Advent Of Code 2023 - Day 4
A fairly straightforward day after giving the brain cells a workout yesterday.
Advent Of Code 2023 - Day 3
After an easyish day 2, the difficulty level bumped up a bit again for day 3.
Advent Of Code 2023 - Day 2
Day 2 - Easier than day 1. Mostly a parsing exercise.
Advent Of Code 2023 - Day 1
Another year has come around quickly and so another chance to have some fun solving the Advent Of Code puzzles for 2023. Once again, I will be attempting to solve these puzzles using Jactl. The version I am using is the latest version (1.3.1 as of time of writing).
Announcing Jactl 1.3.0
Jactl 1.3.0 fixes a few minor bugs and adds some language features. The main new feature is to support the ability to checkpoint script instance execution state and have it restored and resumed on another instance after a failure.
Proof of Concept: 20,000 Payments per Second with Checkpoint Replication
Jactl 1.3.0 introduces the ability to checkpoint the current execution state of a script and have it restored and resumed elsewhere after a failure. In order to test this new feature, I implemented a proof-of-concept project that simulates a payment processing system that accepts payment requests, performs some operations by interacting with multiple external systems and then returns a response. The payment processing system checkpoints its state when required and if a failure occurs, payments in flight will have their state restored and resumed to make sure that no payment is lost.
Advent Of Code 2022 - Day 25
Day 25: Full of Hot Air
Advent Of Code 2022 - Day 24
Day 24: Blizzard Basin
Advent Of Code 2022 - Day 23
Day 23: Unstable Diffusion
Advent Of Code 2022 - Day 22
Day 22: Monkey Map
Advent Of Code 2022 - Day 21
Day 21: Monkey Math
Advent Of Code 2022 - Day 20
Day 20: Grove Positioning System
Advent Of Code 2022 - Day 19
Day 19: Not Enough Minerals
Joey: Jactl Orchestration Engine
I am often asked what the point is in having yet another language for the JVM. Apart from the fun of writing a compiler and being able to run actual programs using my own language, I wanted a language where the execution state could be captured and persisted such that if the server where the application is running fails, the execution state can be restored and resumed on another machine.
Advent Of Code 2022 - Day 18
Day 18: Boiling Boulders
Advent Of Code 2022 - Day 17
Day 17: Pyroclastic Flow
Advent Of Code 2022 - Day 16
Day 16: Proboscidea Volcanium
Advent Of Code 2022 - Day 15
Day 15: Beacon Exclusion Zone
Advent Of Code 2022 - Day 14
Day 14 - Regolith Reservoir
Advent Of Code 2022 - Day 13
Day 13 - Distress Signal
Advent Of Code 2022 - Day 12
Day 12 - Hill Climbing Algorithm
Advent Of Code 2022 - Day 11
Day 11 - Monkey in the Middle
Advent Of Code 2022 - Day 10
Day 10 - Cathode-Ray Tube
Advent Of Code 2022 - Day 9
Day 9 - Rope Bridge
Advent Of Code 2022 - Day 8
Day 8 - Treetop Tree House
Advent Of Code 2022 - Day 7
Day 7 - No Space Left On Device
Advent Of Code 2022 - Day 6
Day 6 - Tuning Trouble
Advent Of Code 2022 - Day 5
Day 5 - Supply Stacks
Advent Of Code 2022 - Day 4
Day 4 - Camp Cleanup
Advent Of Code 2022 - Day 3
Day 3 - Rucksack Reorganisation
Advent Of Code 2022 - Day 2
Day 2 - Rock Paper Scissors
Advent Of Code 2022 - Day 1
In order to have some fun and exercise Jactl on some coding problems I have decided to solve the programming challenges from last year’s Advent of Code - 2022. Every year the Advent of Code publishes a challenge for each day of the Advent calendar.
Welcome to Jactl
Jactl is a new programming language for JVM based applications. It provides a secure way for application developers to provide customisation and extension capabilities to their users but can also be used for commandline scripts. An interactive REPL is provided for testing out code snippets.
subscribe via RSS