YS on jank, bb and ys
Last Friday we got a YS program running on Go using Glojure.
Today we'll show how to run it on 3 other Clojure platforms:
- jank
- Clojure hosted by C++ on LLVM
- bb
- Clojure using SCI
and GraalVM
- ys
- YS can run Clojure from a YS
ys -c
compile command
jank🔗
jank is a work in progress, but if you can get it to compile, you can run at least some YS code through it.
Again, we use ys -c
to compile the code to Clojure.
In this example, we write it to a temporary file and then run it with jank
run
.
$ ys -ce '
defn rng(a b): range(a b:inc)
defn or?(a b): a:empty?.if(b a)
say =: println
doseq x (1 .. 16): !:say
or?:
str:
zero?(x % 3).when("Fizz")
zero?(x % 5).when("Buzz")
=>: x
' | jank run $(f=$(mktemp);cat>$f;echo $f)
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
nil
bb🔗
bb (aka Babashka) is a Clojure interpreter that is GraalVM compiled. It is very mature.
$ ys -ce '
defn rng(a b): range(a b:inc)
defn or?(a b): a:empty?.if(b a)
say =: println
doseq x (1 .. 16): !:say
or?:
str:
zero?(x % 3).when("Fizz")
zero?(x % 5).when("Buzz")
=>: x
' | bb /dev/stdin
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
ys🔗
The ys
YS interpreter can run a lot of Clojure code.
As long as it has access to the Java classes used in the code.
Here we use ys
twice.
It's a bit silly.
But it shows that ys
can run Clojure code with the ys -C
flag.
The -c
flag is used to compile the code to Clojure.
The -C
flag is used to not compile the code to Clojure.
(It's already Clojure!)
$ ys -ce '
defn rng(a b): range(a b:inc)
defn or?(a b): a:empty?.if(b a)
say =: println
doseq x (1 .. 16): !:say
or?:
str:
zero?(x % 3).when("Fizz")
zero?(x % 5).when("Buzz")
=>: x
' | ys -C -
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
What's Next?🔗
I guess we could have also shown this evaluated by:
- Clojure - For the JVM
- ClojureScript - For the browser and Node.js
or any of the other emerging Clojure platforms.