slashbinbash.de / Sikkel / Java Integration

There is limited support for Java integration. There are three different ways to communicate with Java:

  1. Load Java classes from a directory
  2. Load Java classes from a Jar file
  3. Load Java classes that implement the IBinding interface

The interpreter has to know where to find the classes before it can load them.

Import Java Classes

Java

package de.slashbinbash.sikkel;

public class TestClass {
    public static int testA(int a, int b) {
        return a + b;
    }

    public static String testB() {
        return "test";
    }
}

Import all methods with class namespace import

(require system)

(import de.slashbinbash.sikkel.TestClass)

(TestClass.testA 10 15)
    => 25
(TestClass.testB)
    => "test"

Import all methods with import-static

(require system)

(import-static de.slashbinbash.sikkel.TestClass.*)

(testA 42 8)
    => 50
(testB)
    => "test"

Import single method with import-static

(require system)

(import-static de.slashbinbash.sikkel.TestClass.testA)

(testA 8 12)
    => 20
(testB)
    => error: undefined

Constraints:

Import IBinding

Load classes that implement the IBinding interface:

Java

package de.slashbinbash.sikkel;

public class Test implements IBinding {
    @Override
    public Atom eval(Interpreter terp, NList list) {
        return new NInt(42);
    }
}

Sikkel

(require system)

(define test (import-ibinding de.slashbinbash.sikkel.Test))

(test)
    => 42