The scijava-jupyter-kernel
is polyglot which means you can use multiple languages in the same notebook. Available languages are :
All those script languages are executed by the Scijava Scripting Mechanism. It means that any languages added to Scijava Script will work on scijava-jupyter-kernel
.
You can specify a language per cell with the following shebang-like syntax : #!groovy
. It needs to be on the first line of the cell. If nothing is specified, Groovy is the default language or the last selected language is used.
Now let's see some of the specific feature of the scripting languages.
In [1]:
#!groovy
println "The Groovy version is " + GroovySystem.version
Out[1]:
In [2]:
class HelloWorld {
def greet( name ){
"Hello ${name}!"
}
}
def hm = new HelloWorld()
println hm.greet("Groovy")
Out[2]:
In [3]:
def pickEven(n, block) {
for (int i=2; i <= n; i += 2) {
block(i)
}
}
pickEven(10) {
println it
}
Out[3]:
In [4]:
#!python
import sys
print(sys.version)
Out[4]:
In [5]:
# Code is from http://introtopython.org/classes.html
class Rocket(object):
# Rocket simulates a rocket ship for a game,
# or a physics simulation.
def __init__(self):
# Each rocket has an (x,y) position.
self.x = 0
self.y = 0
def move_up(self):
# Increment the y-position of the rocket.
self.y += 1
# Create a fleet of 5 rockets, and store them in a list.
my_rockets = [Rocket() for x in range(0,5)]
# Move the first rocket up.
my_rockets[0].move_up()
# Show that only the first rocket has moved.
for rocket in my_rockets:
print("Rocket altitude:", rocket.y)
Out[5]:
Hashtable hashtable = new Hashtable(); Date date = new Date(); hashtable.put( "today", date );
// Print the current clock value print( System.currentTimeMillis() );
// Loop for (int i=0; i<5; i++) print(i);
In [2]:
#!clojure
(println *clojure-version*)
Out[2]:
In [14]:
(let [fn-list [+ - * /]]
(println ((apply juxt fn-list) 1 2)))
Out[14]:
In [1]:
#!javascript
print("Hello World :-)");
Out[1]:
In [2]:
time = 18
if (time < 10) {
greeting = "Good morning";
} else if (time < 20) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
print(greeting)
Out[2]:
In [3]:
var cars = ["BMW", "Volvo", "Saab", "Ford"];
var text = "";
for (var i = 0; i < cars.length; i++) {
text += cars[i] + "\n";
}
print(text);
Out[3]:
In [4]:
#!scala
scala.util.Properties.versionMsg
Out[4]:
In [5]:
class Point(val xc: Int, val yc: Int) {
var x: Int = xc
var y: Int = yc
def move(dx: Int, dy: Int) {
x = x + dx
y = y + dy
println("Point x location : " + x);
println("Point y location : " + y);
}
}
val pt = new Point(10, 20);
// Move to a new location
pt.move(10, 10);
Out[5]: