Targets

About targets

Keen currently supports two targets: Java and JavaScript. The default is Java.

Commands that use Java:

  • keen foo.keen
  • keen run foo.keen
  • keen build foo.keen
  • keen test foo.keen (see Tests)

Commands that use JavaScript:

  • keen run foo.keen --node-js
  • keen build foo.keen --out foo.js
  • keen test foo.keen --node-js

The target is considered global state.
So, non-global, non-unsafe functions behave the same regardless of the target.

Some functions only work on a particular target.
A function that only works in Java will use the java spec.
A function that only works in JavaScript will use the js spec.

Testing the target

It's possible to call a java or js function from a regular function by first testing java or js.
These are functions returning bool, but Keen treats them specially.

import java/io/PrintStream java/lang/System keen/js main void() global if java java-only-function elif js js-only-function else throw todo java-only-function void() global, java trusted println out, "This will only appear if the target is Java" js-only-function void() global, js _ = trusted call-property js-global["console"], "info", "This will only appear if the target is JavaScript"

The functions java and js are global, since the target is considered global state.
Use trusted to erase global if the behavior is the same in any target.

import keen/js java/lang/Math main void() log square-root 4 square-root float(a float) trusted if java sqrt a elif js to call-property js-global["Math"], "sqrt", a.to else throw todo

Main target

A main function can use a target.

import keen/js main void() global, js _ = trusted call-property js-global["console"], "info", "JS only!"