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/
Ad

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)

Golang
GolangGolang
Golang
Felipe Mamud
 
Introduction to Go programming language
Introduction to Go programming languageIntroduction to Go programming language
Introduction to Go programming language
Slawomir Dorzak
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
Adam Getchell
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
Short intro to the Rust language
Short intro to the Rust languageShort intro to the Rust language
Short intro to the Rust language
Gines Espada
 
Go debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFxGo debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFx
SignalFx
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
Haripritha
 
An Overview of SystemVerilog for Design and Verification
An Overview of SystemVerilog  for Design and VerificationAn Overview of SystemVerilog  for Design and Verification
An Overview of SystemVerilog for Design and Verification
KapilRaghunandanTrip
 
Writing MySQL UDFs
Writing MySQL UDFsWriting MySQL UDFs
Writing MySQL UDFs
Roland Bouman
 
C# 6.0 Preview
C# 6.0 PreviewC# 6.0 Preview
C# 6.0 Preview
Fujio Kojima
 
Lecture 04 Programming C for Beginners 001
Lecture 04 Programming C for Beginners 001Lecture 04 Programming C for Beginners 001
Lecture 04 Programming C for Beginners 001
MahmoudElsamanty
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
Yuren Ju
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
Guy Komari
 
Let's Go-lang
Let's Go-langLet's Go-lang
Let's Go-lang
Luka Zakrajšek
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Tudor Dragan
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
Eelco Visser
 
C# programming
C# programming C# programming
C# programming
umesh patil
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
Saifur Rahman
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to Elixir
brien_wankel
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
HCMUTE
 
Introduction to Go programming language
Introduction to Go programming languageIntroduction to Go programming language
Introduction to Go programming language
Slawomir Dorzak
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
Adam Getchell
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
Short intro to the Rust language
Short intro to the Rust languageShort intro to the Rust language
Short intro to the Rust language
Gines Espada
 
Go debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFxGo debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFx
SignalFx
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
Haripritha
 
An Overview of SystemVerilog for Design and Verification
An Overview of SystemVerilog  for Design and VerificationAn Overview of SystemVerilog  for Design and Verification
An Overview of SystemVerilog for Design and Verification
KapilRaghunandanTrip
 
Lecture 04 Programming C for Beginners 001
Lecture 04 Programming C for Beginners 001Lecture 04 Programming C for Beginners 001
Lecture 04 Programming C for Beginners 001
MahmoudElsamanty
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
Yuren Ju
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
Guy Komari
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Tudor Dragan
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
Eelco Visser
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
Saifur Rahman
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to Elixir
brien_wankel
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
HCMUTE
 
Ad

Recently uploaded (20)

#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
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/