SlideShare a Scribd company logo
Fantom


Programming language for JVM, CLR, and JS



                                  2012, Kamil Toman
             http://fantomery.org/katox/fantom-en.pdf
What Is Fantom
●   Language for multiple platforms
●   Object oriented
●   Functional
●   Balance of static and dynamic typing
●   Well-known "c-like" syntax

● Opensource (AFL 3.0)
Productivity
●   Literals
●   Type inference
●   Functions
●   Closures
●   Mixins
●   Integration (FFI)
●   DSL support
Literals
● Lists
  [,]
  [ 10, 20, 30 ]
  [ "a", "b", [ "c", "d" ], "e" ]
● Maps
  [:]
  [ "x" : 10.0d, "y" : 3.14f ]
  [ 10 : "x", 20 : [ "p", "q", "r" ] ]
● Types (introspection)
  sys::Str#, Str#
● Slots (introspection)
  Str#plus, Int#plusDecimal, Uuid#fromStr
Literals (2)
● Uri
    `http://fantom.org`
    `http://myserver.com/edit?n=Ron&s=Smith`
    `/home/fantom/checkitout.fan`
● Duration
    1ns, 1ms, 1sec, 1min, 1hr, 1day
●   Range
    [ 10..20, 30..<40, -3..-1 ]
Type Inference
● u := Uuid()
    // u.typeof -> sys::Uuid
●   s := "some string"
    // s.typeof -> sys::Str
●   list := [10, 20, 30]
    // list.typeof -> sys::Int[]
    listObj := ["a", 1]
    // listObj.typeof -> sys::Obj[]
● map := ["x" : 10, "y" : 3]
    // map.typeof -> [sys::Str : sys::Int]
●   mapNum := ["x" : 10.0d, "y" : 3.14f]
    // mapNum.typeof -> [sys::Str : sys::Num]
Functions and Closures
● Functions - signature |A a, B b, ..., H h -> R|
    double := |Int a -> Int| { 2 * a }
    v := |->| {}
● Methods - just functions wrappers
    |Int a, Int b ->Int| plus := Int#plus.func
●   Closures - expressions that return functions
    Str prefix := ""
    print := |Obj o -> Str| { prefix + o.toStr }
●   Bind - bind parameters of existing functions
    op := |Method m, Int a, Int b| { m.callOn(a, [b]) }
    mul := opFunc.bind([Int#mult])             // |Int, Int->Int|
    plus2 := opFunc.bind([Int#plus, 2]) // |Int -> Int|
Mixins
mixin HasColor {
 abstract Str color
 virtual Void sayIt() { echo ("My favourite $color") } }

mixin HasAge {
 abstract Date produced
 virtual Bool isVeteran() { return produced < Date.fromStr("1919-01-01") } }

class Car : HasColor, HasAge {
 override Str color := "evil grey"
 override Date produced := Date.today
 override Void sayIt() { echo("My ${isVeteran ? "veteran" : color} car
produced ${produced.year}.") } }

Car().sayIt   // -> My evil grey car produced 2012.
Java FFI
● Java
  ○ package => Fantom pod
  ○ class => Fantom class
  ○ interface => Fantom mixin
  ○ field => Fantom field
  ○ method => Fantom method
   using [java] javax.swing
   using [java] java.util::Map$Entry as Entry
   f := JFrame(...)

● There are some limitations of Fantom FFI. What's not
   supported
   ○ overloaded methods, primitive multidimensional
      arrays, > 1 level deep inheritance from java classes
Javascript FFI
● source code Fantom -> Js generation (no bytecode)
   @Js
   class GonnaBeJs
   {
     Void sayHi() { Win.cur.alert("Hello!") }
   }

● native peer Js -> Fantom
    // Fantom
   class Foo {
       native Str? f
   }

    // Javascript
   fan.mypod.FooPeer.prototype.m_f = "";
   fan.mypod.FooPeer.prototype.f = function(t) { return this.m_f; }
   fan.mypod.FooPeer.prototype.f$ = function(t, v) { this.m_f = v; }
DSL Support
● Ability to integrate custom language or AST
    modifications of Fantom code
●   Syntax - DslType <|...|>
    echo(Str<|A towel, it says, is about the most massively useful thing an
    interstellar hitchhiker can have.|>)

    Regex<|^[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,4}$|>

    @Select
    User getUser(Int id){
      one(sql<|
       select u.userid, u.name
       from User u,Company c
       where u.id = #{id} and u.companid = c.id and c.isdeleted = 0
      |>)
    }
Practical Shortcuts
● Dynamic typing
    obj->foo // obj.trap("foo", [,])
●   Implicit upcast
    Derived derived := base
●   Optional return for simple expressions
    files.sort |a, b| { a.modified <=> b.modified }
●   isnot keyword
    alwaysFalse := "a" isnot Str
●   Optional parenthesis for functions of arity 0
    yes := "yes".capitalize
Practical Shortcuts (2)
● Optional function calls
    tel := contact?.phone?.mobile
●   Elvis operator
    x ?: def                 // x == null ? def : x
●   it-blocks
    `file.txt`.toFile.eachLine { echo (it) }
    // `file.txt`.toFile().eachLine(|line| { echo (line) })
●   literals for data
    Date.today - 1day // yesterday
●   string interpolation
    res.headers["Authorization"]="Basic " + "$user:$pass".
    toBuf.toBase64
Declarative Style
win := Window
  {
    size = Size(300,200)
    Label {
       text = "Hello world"
       halign=Halign.center },
  }.open

createTable("user") {
   createColumn("user_id", integer) { autoIncrement; primaryKey }
   createColumn("login", varchar(64)) { notNull; unique }
   createColumn("pwd", varchar(48)) { comment("Password hash"); notNull }
   createColumn("role_id", integer) { notNull }
   index("idx_login", ["login"])
   foreignKey("fk_role", ["role_id"], references("role", ["role_id"]))
}
Declarative Style (2)
class Person {
  Str? name
  Str[]? emails
}
phoneBook := [
   Person
   {
     name = "Fantom"; emails = [ "fantom@opera.org", "fantom@gmail.com" ]
   },
   Person
   {
     name = "Nobody"; emails = [ "nobody@nowhere.org", "noob@gmail.com" ]
   }
]
Functional Style
["ox", "cat", "deer", "whale"].map { it.size } // -> [2, 3, 4, 5]
[2,3,4].all { it > 1 }           // -> true
[2,3,4].any { it == 4 }          // -> true

["hello", 25, 3.14d, Time.now].findType(Num#) // -> [25, 3.14]
[1, 1, 2, 3, 2, 1, 1].findAll |i| { i.isEven } // -> [2, 2]

[1, 1, 2, 3, 2, 1, 1].reduce([:]) |[Int:Int]r, Int v->[Int:Int]| { return r[v]=r.get(v,0)+1 }
// -> [1:4, 2:2, 3:1]

phoneBook.findAll | Person p -> Bool | { p.name == "Fantom" }
            .map | Person p -> Str[] | { p.emails }
            .flatten
            .exclude | Str email -> Bool | { s.endsWith("gmail.com") }
            .each { echo (it) }
// -> fantom@opera.org
Safety
● Null & Not-Null types
● Const classes and fields
● Guaranteed functions/closures with no mutations
    (thread safe)
●   Actor system (no shared state)
    ○ Unsafe wrapper - break your rules whenever you
        want to save some time and shoot yourself into foot
Null and Not-Null types
● null assignment must be explicitly allowed in the code
● Default for types is not nullable version
● Automatic conversion
   ○ apparent bugs -> compile error
   ○ could work -> (maybe) runtime error
Null and Not-Null types (2)
class Nullable {                      // © Xored, Inc.
    Void main() {
         Int? nullable := null
         Int nonNullable := 0
         nonNullable = nullable            // runtime err
         nonNullable = null           // compile err
         do3(null)                    // compile err
         do3(nullable)                     // runtime err
    }
    Int do1(Int? arg) { null }  // compile err
    Int do2(Int? arg) { arg }   // runtime err
    Int? do3(Int arg) { arg }
}
Const
● Const classes guarantee their internal state won't
  change
● Const fields must be initialized on object construction
● Const fields must be const types or their values must be
  converted by calling toImmutable for List, Map, Func
Const
class NonConst {                     // © Xored, Inc.
    const Int constField
    Int nonConstField
    Void mutate() {
         constField = 4              // compile err
         nonConstField = 4           // ok
    }
}
class Const {
    new make(Int i, Str[] list) {
         // implicit call of list.toImmutable
         this.list = list
    }
    const Str[] list
}
Actor System
● Concurrency is not handled by thread but by Actors
● Actor is a const class extending concurrent::Actor
● Actors exchange immutable messages, i.e.
    a. serialized content
    b. constant content (allows to pass by reference)
●   Actors typically contain private data, which are mutable
    (thread local analogy)

    // asynchronous incrementation of number send (blocking send operation)
    actor:=Actor(ActorPool()) | Int msg -> Int | { msg + 1 }
    5.times { echo(actor.send(it).get) }
Tooling and Build System
● Out-of-the-box build system using Fantom
  ○ handles standard setup with no additional code
  ○ easy to understand (simple implementation)
  ○ module dependencies and version checking
● Bundled simple testing framework fant
  ○ fits into default build structure
  ○ pretty standard lifecycle (junit like)
  ○ works also for javascript targeted code
using build
class Build : BuildPod {
 new make() {
   podName = "mongo"; summary = "Interface to MongoDB (http://www.mongodb.com)"
   depends = ["sys 1.0", "inet 1.0", "concurrent 1.0"]
   srcDirs = [`test/`, `fan/`, `fan/gridfs/`, `fan/bson/`]
   docSrc = true } }
Modularity - Fantom repo & pods
// start all non-abstract MyService services in project CoolProj
using fanr
repo:=Repo.makeForUri(`http://my-fantom-repo/`)
pods:=repo.query(Str<|"*proj.name=="CoolProj"|>)
pods.each |pod|
{
  echo("$p.name$p.version$p.depends")
  pod.types.each |type|
  {
    if (type.fits(MyService#) && !type.isAbstract)
      type.make->start
  }
}
References
● Open source & docs
  ○ http://fantom.org/
  ○ http://www.talesframework.org/
  ○ http://www.fanzy.net/
  ○ http://langref.org/
  ○ http://rosettacode.org/wiki/Category:Fantom
● Commercial products
  ○ http://skyfoundry.com/skyspark/
  ○ http://www.xored.com/products/f4/
  ○ http://www.kloudo.com/
  ○ http://www.cull.io/

More Related Content

What's hot (20)

C++ L08-Classes Part1
C++ L08-Classes Part1C++ L08-Classes Part1
C++ L08-Classes Part1
Mohammad Shaker
 
The best of AltJava is Xtend
The best of AltJava is XtendThe best of AltJava is Xtend
The best of AltJava is Xtend
takezoe
 
Golang iran - tutorial go programming language - Preliminary
Golang iran - tutorial  go programming language - PreliminaryGolang iran - tutorial  go programming language - Preliminary
Golang iran - tutorial go programming language - Preliminary
go-lang
 
Kotlin
KotlinKotlin
Kotlin
BoKaiRuan
 
MP in Clojure
MP in ClojureMP in Clojure
MP in Clojure
Kent Ohashi
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
Mohammad Shaker
 
Go Lang Tutorial
Go Lang TutorialGo Lang Tutorial
Go Lang Tutorial
Wei-Ning Huang
 
C++ L09-Classes Part2
C++ L09-Classes Part2C++ L09-Classes Part2
C++ L09-Classes Part2
Mohammad Shaker
 
Reflection in Go
Reflection in GoReflection in Go
Reflection in Go
strikr .
 
C++ via C#
C++ via C#C++ via C#
C++ via C#
Egor Bogatov
 
Intro python-object-protocol
Intro python-object-protocolIntro python-object-protocol
Intro python-object-protocol
Shiyao Ma
 
Why my Go program is slow?
Why my Go program is slow?Why my Go program is slow?
Why my Go program is slow?
Inada Naoki
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/Invoke
Dmitri Nesteruk
 
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
Muhammad Ulhaque
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
Scott Wlaschin
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
Mohammad Shaker
 
Free Monads Getting Started
Free Monads Getting StartedFree Monads Getting Started
Free Monads Getting Started
Kent Ohashi
 
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ Programming
Open Gurukul
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?
Kevin Pilch
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on Python
Sumit Raj
 
The best of AltJava is Xtend
The best of AltJava is XtendThe best of AltJava is Xtend
The best of AltJava is Xtend
takezoe
 
Golang iran - tutorial go programming language - Preliminary
Golang iran - tutorial  go programming language - PreliminaryGolang iran - tutorial  go programming language - Preliminary
Golang iran - tutorial go programming language - Preliminary
go-lang
 
Reflection in Go
Reflection in GoReflection in Go
Reflection in Go
strikr .
 
Intro python-object-protocol
Intro python-object-protocolIntro python-object-protocol
Intro python-object-protocol
Shiyao Ma
 
Why my Go program is slow?
Why my Go program is slow?Why my Go program is slow?
Why my Go program is slow?
Inada Naoki
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/Invoke
Dmitri Nesteruk
 
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
Muhammad Ulhaque
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
Scott Wlaschin
 
Free Monads Getting Started
Free Monads Getting StartedFree Monads Getting Started
Free Monads Getting Started
Kent Ohashi
 
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ Programming
Open Gurukul
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?
Kevin Pilch
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on Python
Sumit Raj
 

Similar to Fantom - Programming Language for JVM, CLR, and Javascript (20)

Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
Pray Desai
 
Proposals for new function in Java SE 9 and beyond
Proposals for new function in Java SE 9 and beyondProposals for new function in Java SE 9 and beyond
Proposals for new function in Java SE 9 and beyond
Barry Feigenbaum
 
Google Dart
Google DartGoogle Dart
Google Dart
Eberhard Wolff
 
Google Dart
Google DartGoogle Dart
Google Dart
adesso AG
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
Miles Sabin
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
Skills Matter
 
7li7w devcon5
7li7w devcon57li7w devcon5
7li7w devcon5
Kerry Buckley
 
JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)
jeresig
 
The Future of JavaScript (Ajax Exp '07)
The Future of JavaScript (Ajax Exp '07)The Future of JavaScript (Ajax Exp '07)
The Future of JavaScript (Ajax Exp '07)
jeresig
 
Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
Martijn Verburg
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
Miles Sabin
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharma
Sandesh Sharma
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
Peter Maas
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Language
league
 
The Not Java That's Not Scala
The Not Java That's Not ScalaThe Not Java That's Not Scala
The Not Java That's Not Scala
Justin Lee
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
Eric Pederson
 
core java
core javacore java
core java
Vinodh Kumar
 
Polyglot JVM
Polyglot JVMPolyglot JVM
Polyglot JVM
Arturo Herrero
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
Martijn Verburg
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
Pray Desai
 
Proposals for new function in Java SE 9 and beyond
Proposals for new function in Java SE 9 and beyondProposals for new function in Java SE 9 and beyond
Proposals for new function in Java SE 9 and beyond
Barry Feigenbaum
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
Miles Sabin
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
Skills Matter
 
JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)
jeresig
 
The Future of JavaScript (Ajax Exp '07)
The Future of JavaScript (Ajax Exp '07)The Future of JavaScript (Ajax Exp '07)
The Future of JavaScript (Ajax Exp '07)
jeresig
 
Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
Martijn Verburg
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
Miles Sabin
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharma
Sandesh Sharma
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
Peter Maas
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Language
league
 
The Not Java That's Not Scala
The Not Java That's Not ScalaThe Not Java That's Not Scala
The Not Java That's Not Scala
Justin Lee
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
Eric Pederson
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
Martijn Verburg
 
Ad

Recently uploaded (20)

Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry ReportThe State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Ben Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding WorldBen Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding World
AWS Chicago
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry ReportThe State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Ben Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding WorldBen Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding World
AWS Chicago
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Ad

Fantom - Programming Language for JVM, CLR, and Javascript

  • 1. Fantom Programming language for JVM, CLR, and JS 2012, Kamil Toman http://fantomery.org/katox/fantom-en.pdf
  • 2. What Is Fantom ● Language for multiple platforms ● Object oriented ● Functional ● Balance of static and dynamic typing ● Well-known "c-like" syntax ● Opensource (AFL 3.0)
  • 3. Productivity ● Literals ● Type inference ● Functions ● Closures ● Mixins ● Integration (FFI) ● DSL support
  • 4. Literals ● Lists [,] [ 10, 20, 30 ] [ "a", "b", [ "c", "d" ], "e" ] ● Maps [:] [ "x" : 10.0d, "y" : 3.14f ] [ 10 : "x", 20 : [ "p", "q", "r" ] ] ● Types (introspection) sys::Str#, Str# ● Slots (introspection) Str#plus, Int#plusDecimal, Uuid#fromStr
  • 5. Literals (2) ● Uri `http://fantom.org` `http://myserver.com/edit?n=Ron&s=Smith` `/home/fantom/checkitout.fan` ● Duration 1ns, 1ms, 1sec, 1min, 1hr, 1day ● Range [ 10..20, 30..<40, -3..-1 ]
  • 6. Type Inference ● u := Uuid() // u.typeof -> sys::Uuid ● s := "some string" // s.typeof -> sys::Str ● list := [10, 20, 30] // list.typeof -> sys::Int[] listObj := ["a", 1] // listObj.typeof -> sys::Obj[] ● map := ["x" : 10, "y" : 3] // map.typeof -> [sys::Str : sys::Int] ● mapNum := ["x" : 10.0d, "y" : 3.14f] // mapNum.typeof -> [sys::Str : sys::Num]
  • 7. Functions and Closures ● Functions - signature |A a, B b, ..., H h -> R| double := |Int a -> Int| { 2 * a } v := |->| {} ● Methods - just functions wrappers |Int a, Int b ->Int| plus := Int#plus.func ● Closures - expressions that return functions Str prefix := "" print := |Obj o -> Str| { prefix + o.toStr } ● Bind - bind parameters of existing functions op := |Method m, Int a, Int b| { m.callOn(a, [b]) } mul := opFunc.bind([Int#mult]) // |Int, Int->Int| plus2 := opFunc.bind([Int#plus, 2]) // |Int -> Int|
  • 8. Mixins mixin HasColor { abstract Str color virtual Void sayIt() { echo ("My favourite $color") } } mixin HasAge { abstract Date produced virtual Bool isVeteran() { return produced < Date.fromStr("1919-01-01") } } class Car : HasColor, HasAge { override Str color := "evil grey" override Date produced := Date.today override Void sayIt() { echo("My ${isVeteran ? "veteran" : color} car produced ${produced.year}.") } } Car().sayIt // -> My evil grey car produced 2012.
  • 9. Java FFI ● Java ○ package => Fantom pod ○ class => Fantom class ○ interface => Fantom mixin ○ field => Fantom field ○ method => Fantom method using [java] javax.swing using [java] java.util::Map$Entry as Entry f := JFrame(...) ● There are some limitations of Fantom FFI. What's not supported ○ overloaded methods, primitive multidimensional arrays, > 1 level deep inheritance from java classes
  • 10. Javascript FFI ● source code Fantom -> Js generation (no bytecode) @Js class GonnaBeJs { Void sayHi() { Win.cur.alert("Hello!") } } ● native peer Js -> Fantom // Fantom class Foo { native Str? f } // Javascript fan.mypod.FooPeer.prototype.m_f = ""; fan.mypod.FooPeer.prototype.f = function(t) { return this.m_f; } fan.mypod.FooPeer.prototype.f$ = function(t, v) { this.m_f = v; }
  • 11. DSL Support ● Ability to integrate custom language or AST modifications of Fantom code ● Syntax - DslType <|...|> echo(Str<|A towel, it says, is about the most massively useful thing an interstellar hitchhiker can have.|>) Regex<|^[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,4}$|> @Select User getUser(Int id){ one(sql<| select u.userid, u.name from User u,Company c where u.id = #{id} and u.companid = c.id and c.isdeleted = 0 |>) }
  • 12. Practical Shortcuts ● Dynamic typing obj->foo // obj.trap("foo", [,]) ● Implicit upcast Derived derived := base ● Optional return for simple expressions files.sort |a, b| { a.modified <=> b.modified } ● isnot keyword alwaysFalse := "a" isnot Str ● Optional parenthesis for functions of arity 0 yes := "yes".capitalize
  • 13. Practical Shortcuts (2) ● Optional function calls tel := contact?.phone?.mobile ● Elvis operator x ?: def // x == null ? def : x ● it-blocks `file.txt`.toFile.eachLine { echo (it) } // `file.txt`.toFile().eachLine(|line| { echo (line) }) ● literals for data Date.today - 1day // yesterday ● string interpolation res.headers["Authorization"]="Basic " + "$user:$pass". toBuf.toBase64
  • 14. Declarative Style win := Window { size = Size(300,200) Label { text = "Hello world" halign=Halign.center }, }.open createTable("user") { createColumn("user_id", integer) { autoIncrement; primaryKey } createColumn("login", varchar(64)) { notNull; unique } createColumn("pwd", varchar(48)) { comment("Password hash"); notNull } createColumn("role_id", integer) { notNull } index("idx_login", ["login"]) foreignKey("fk_role", ["role_id"], references("role", ["role_id"])) }
  • 15. Declarative Style (2) class Person { Str? name Str[]? emails } phoneBook := [ Person { name = "Fantom"; emails = [ "[email protected]", "[email protected]" ] }, Person { name = "Nobody"; emails = [ "[email protected]", "[email protected]" ] } ]
  • 16. Functional Style ["ox", "cat", "deer", "whale"].map { it.size } // -> [2, 3, 4, 5] [2,3,4].all { it > 1 } // -> true [2,3,4].any { it == 4 } // -> true ["hello", 25, 3.14d, Time.now].findType(Num#) // -> [25, 3.14] [1, 1, 2, 3, 2, 1, 1].findAll |i| { i.isEven } // -> [2, 2] [1, 1, 2, 3, 2, 1, 1].reduce([:]) |[Int:Int]r, Int v->[Int:Int]| { return r[v]=r.get(v,0)+1 } // -> [1:4, 2:2, 3:1] phoneBook.findAll | Person p -> Bool | { p.name == "Fantom" } .map | Person p -> Str[] | { p.emails } .flatten .exclude | Str email -> Bool | { s.endsWith("gmail.com") } .each { echo (it) } // -> [email protected]
  • 17. Safety ● Null & Not-Null types ● Const classes and fields ● Guaranteed functions/closures with no mutations (thread safe) ● Actor system (no shared state) ○ Unsafe wrapper - break your rules whenever you want to save some time and shoot yourself into foot
  • 18. Null and Not-Null types ● null assignment must be explicitly allowed in the code ● Default for types is not nullable version ● Automatic conversion ○ apparent bugs -> compile error ○ could work -> (maybe) runtime error
  • 19. Null and Not-Null types (2) class Nullable { // © Xored, Inc. Void main() { Int? nullable := null Int nonNullable := 0 nonNullable = nullable // runtime err nonNullable = null // compile err do3(null) // compile err do3(nullable) // runtime err } Int do1(Int? arg) { null } // compile err Int do2(Int? arg) { arg } // runtime err Int? do3(Int arg) { arg } }
  • 20. Const ● Const classes guarantee their internal state won't change ● Const fields must be initialized on object construction ● Const fields must be const types or their values must be converted by calling toImmutable for List, Map, Func
  • 21. Const class NonConst { // © Xored, Inc. const Int constField Int nonConstField Void mutate() { constField = 4 // compile err nonConstField = 4 // ok } } class Const { new make(Int i, Str[] list) { // implicit call of list.toImmutable this.list = list } const Str[] list }
  • 22. Actor System ● Concurrency is not handled by thread but by Actors ● Actor is a const class extending concurrent::Actor ● Actors exchange immutable messages, i.e. a. serialized content b. constant content (allows to pass by reference) ● Actors typically contain private data, which are mutable (thread local analogy) // asynchronous incrementation of number send (blocking send operation) actor:=Actor(ActorPool()) | Int msg -> Int | { msg + 1 } 5.times { echo(actor.send(it).get) }
  • 23. Tooling and Build System ● Out-of-the-box build system using Fantom ○ handles standard setup with no additional code ○ easy to understand (simple implementation) ○ module dependencies and version checking ● Bundled simple testing framework fant ○ fits into default build structure ○ pretty standard lifecycle (junit like) ○ works also for javascript targeted code using build class Build : BuildPod { new make() { podName = "mongo"; summary = "Interface to MongoDB (http://www.mongodb.com)" depends = ["sys 1.0", "inet 1.0", "concurrent 1.0"] srcDirs = [`test/`, `fan/`, `fan/gridfs/`, `fan/bson/`] docSrc = true } }
  • 24. Modularity - Fantom repo & pods // start all non-abstract MyService services in project CoolProj using fanr repo:=Repo.makeForUri(`http://my-fantom-repo/`) pods:=repo.query(Str<|"*proj.name=="CoolProj"|>) pods.each |pod| { echo("$p.name$p.version$p.depends") pod.types.each |type| { if (type.fits(MyService#) && !type.isAbstract) type.make->start } }
  • 25. References ● Open source & docs ○ http://fantom.org/ ○ http://www.talesframework.org/ ○ http://www.fanzy.net/ ○ http://langref.org/ ○ http://rosettacode.org/wiki/Category:Fantom ● Commercial products ○ http://skyfoundry.com/skyspark/ ○ http://www.xored.com/products/f4/ ○ http://www.kloudo.com/ ○ http://www.cull.io/