Introduction to JVM Languages
and Fantom
@jph98
Welcom
e...
What I’ll Cover
JVM languages and a brief history
Where Fantom fits into the JVM language
landscape
Characteristics of the Fantom and a few
examples
JVM Languages
Java
Source Code
JIT Compiler
x86 Native Code
JIT Compiler
x86_64 Native Code
Bytecode
Compiler Compiler
Fantom
Source Code
JVM JVM
Why do we need JVM languages?
More expressive, dynamic, functional
Reduce amount of “boiler plate” code
A way of modernising and pushing the
language forward
Da Vinci Machine Project
Project to extend the JVM for supporting other
languages:
- Tail call optimisation
- Interface injection
- Dynamic invocation
- Continuations
Language Categories
General purpose languages focusing on a
specific paradigm
Languages translated from other languages
Paradigm specific or multi paradigm languages
Quiz
Anybody care to guess how many JVM
languages there are?
2007
Clojure
JVM Language History
1997
Jython/JPython
1998
Bluedragon/CFML
2000
Beanshell
2001
JRuby
Processing
Judoscript
2003
Groovy
Gosu
Scala
2008
Ioke
2011
Kotlin
Ceylon
Xtend
General Purpose Languages
Functional Languages (e.g. Frege)
Dynamically Typed Languages (e.g. JRuby)
Multi Paradigm Languages (e.g. Scala)
Languages Translated to the JVM
Ada
JGNAT
Go JGo
Lisp
CLforJava
JS
Nashorn
Pascal Free
Pascal
Prolog JLog
Python Jython
R
Renjin
REXX Netrexx
Ruby JRuby
Scheme Bigloo
Tcl Jacl
Specific Purpose Languages
Parallel Programming
- Ateji (Commercial)
- Chapel (Developed by Cray)
- X10 (Developed by IBM)
Visualisation and animation
- Processing
CLR Languages (CLI)
.NET CLR also has a number of languages:
Boo (Python esque) P# (Prolog)
IKVM (Java)
Phalanger (PHP)
IronRuby
IronPython
Overview
Originally called Fan, created by Brian Frank
and Andy Frank
Academic Free License
I’m covering this as an alternative to the
standard Scala, Clojure yada yada...
Intent
Provide a language that compiles to:
- JVM (Java) - JavaFFI
- CLR (.NET) - DotnetFFI
- Browser (Javascript) -
Produces fcode (intermediate CLR/JVM/JSVM)
code
Ecosystem Overview
Focus on providing elegant API’s
Provides a REPL
Modules in the form of Pods
Desktop (FWT) and web (Webmod)
Characteristics
Object Oriented, Functional
Static and Dynamic Typing (Choice of)
64 bit Float, Int, Decimal + Str, Bool
Duration, Uri, Slot, Range, List, Map
Fantom Language Features
Classes
Public and abstract
Can also be Final, Const or Internal
Example...
Mixins
Like interfaces, but with method
implementations. Public defender methods.
Can group a number of slots together for reuse
Can’t contain state, you need to provide own
Mixing Static and Dynamic
person.addAddress(“New Bond House”);
person->addAddress(“New Bond House”);
Reducing Boilerplate Code
Concise in places, optional setters/getters
Null safe fields, elvis operator
Accessors, optional sets/gets
Accessors: class Person {
Str name
Int age
}
Null Check Operators (Elvis)
name ?: “No name specified”
Variables can also be marked nullable or non-nullable
Closures
Closure can be thought of as a function that
can be stored in a variable
Can access variables in same scope as defined
Useful for event handling
Closure Examples
10.times |i| {
echo(i)
}
10.times {
echo(it)
}
Closure Examples
Str first := “Bart”
Str last := “Simpson”
f := |->Str| { return first + “ “ + last }
Actor Concurrency System
Works around a message passing model
Actor is responsible for specific tasks
Lets take a look at a counter example...
Concurrency with Actors
pool := ActorPool()
["one", "two", "three", "four"].each {
a := Actor(pool) |Str name| {
echo("Thread $name says Hello World!")
}
a.send(it)
}
FFI - Foreign Function Interface
JavaFFI - Java type system into Fantom
DotnetFFI - not available yet
Use native classes to provide functionality
DSL’s - Domain Specific Languages
StrDSL
RegexDSL
Can write your own using the DslPlugin
Conclusions
Impressive set of features for the language
Some useful constructs to avoid boilerplate
code
Main focus in Java and JS. Looking for .NET
contributors for the DotNetFFI.
Conclusions
There’s a lot more to cover here in terms of
learning…
Where are the JVM languages going?
Java 8, Java 9… inclusions...
Top Related