SlideShare ist ein Scribd-Unternehmen logo
1 von 76
Downloaden Sie, um offline zu lesen
Ola	
  Bini
                           computational	
  metalinguist	
  
                                 ola.bini@gmail.com
                              http://olabini.com/blog



torsdag den 28 juli 2011
Ola	
  Bini
                       Swedish	
  language	
  geek

                       Works	
  for	
  ThoughtWorks	
  in	
  Chicago

                       JRuby	
  core	
  committer

                       Designer	
  of	
  Ioke	
  and	
  Seph

                       Member	
  of	
  JSR292	
  Expert	
  Group




torsdag den 28 juli 2011
Language	
  design
                       Communication
                       Expressiveness
                       Simplicity
                       Homoiconicity
                       Language	
  flexibility




torsdag den 28 juli 2011
Expressiveness

torsdag den 28 juli 2011
A	
  precursor:	
  Ioke

torsdag den 28 juli 2011
The	
  position	
  of	
  
                              Ioke

torsdag den 28 juli 2011
Some	
  examples

torsdag den 28 juli 2011
0      fact = 1
         Number fact = method(self * (self - 1) fact)

         10 fact println




torsdag den 28 juli 2011
"Command line arguments:" println
       System programArguments each(println)




torsdag den 28 juli 2011
fib = method(
       fn(a, b, [b, a + b]) iterate(1, 1) mapped(first)
     )

     (fib indexed(from: 1) takeWhile(second < 1000) last first + 1) println
     fib indexed(from: 1) droppedWhile(second < 1000) first first println




torsdag den 28 juli 2011
bottle = method(i,
         case(i,
          0, "no more bottles of beer",
          1, "1 bottle of beer",
          "#{i} bottles of beer"))

        (99..1) each(i,
          "#{bottle(i)} on the wall, " println
          "take one down, pass it around," println
          "#{bottle(i - 1)} on the wall.n" println
        )
torsdag den 28 juli 2011
use("mandarin")

                                        =                    (
                                        =     (          ,           :           ,   :,
                                             -=
                                             +=
                               )

                                        =     (
                                   "<             : #{                       }       : #{      }>"
                               )
                           )

                                   =                 (               : " ",               : 142.0)
                                   =                 (               : " ",               : 45.7)

                                             (23.0,              :           ,   :    )
                                             (10.0,              :           ,   :    )
                                            (57.4,           :           )




torsdag den 28 juli 2011
words = method(text, #/[a-z]+/ allMatches(text lower))

train = method(features,
  features fold({} withDefault(1), model, f, model[f] ++. model))

NWORDS = train(words(FileSystem readFully("small.txt")))

alphabet = "abcdefghijklmnopqrstuvwxyz" chars

edits1 = method(word,
 s = for(i <- 0..(word length + 1), [word[0...i], word[i..-1]])
 set(*for(ab <- s, ab[0] + ab[1][1..-1]), ;deletes
    *for(ab <- s[0..-2], ab[0] + ab[1][1..1] + ab[1][0..0] + ab[1][2..-1]), ;transposes
    *for(ab <- s, c <- alphabet, ab[0] + c + ab[1][1..-1]), ;replaces
    *for(ab <- s, c <- alphabet, ab[0] + c + ab[1]))) ;inserts

knownEdits2 = method(word, for:set(e1 <- edits1(word), e2 <- edits1(e1), NWORDS key?(e2), e2))

known = method(words, for:set(w <- words, NWORDS key?(w), w))

correct = method(word,
 candidates = known([word]) ?| known(edits1(word)) ?| knownEdits2(word) ?| [word]
 candidates max(x, NWORDS[x]))


torsdag den 28 juli 2011
import(:javax:swing, :JFrame, :JButton)
                     import java:awt:GridLayout

                     button = JButton new("Press me!") do(
                      addActionListener(fn(e, button text = "Hello from Ioke"))
                      addActionListener(fn(e, "button pressed" println)))

                     JFrame new("My Frame") do(
                      layout = GridLayout new(2, 2, 3, 3)
                      add(button)
                      setSize(300, 80)
                      visible = true)




torsdag den 28 juli 2011
ICheck

torsdag den 28 juli 2011
forAll(int x, int y,
                            where: x < y,
                            [x, y] sort should == [x, y])




torsdag den 28 juli 2011
forAll(int x, int y,
                    where: y < x,
                    classify(trivial) x == y,
                    classifyAs(close) (x - y) abs < 2,

                           [x,y] sort should == [y,x] sort)



torsdag den 28 juli 2011
forAll(list(int) xs,
                     xs reverse reverse should == xs)




torsdag den 28 juli 2011
forEvery(integer x, integer y,
                            [x, y] max should >= [x, y] min)




torsdag den 28 juli 2011
forAll(int x, int y,
                            [x,y] sort should == [x,y])




torsdag den 28 juli 2011
Conditions

torsdag den 28 juli 2011
willFail = method( 10 / 0 )




torsdag den 28 juli 2011
bind(
     rescue(
      Condition Error Arithmetic DivisionByZero,
      fn(c,
        "Division by zero! Failing..." println
        nil)),
     result = willFail
     "got result: #{result}" println
   ) println


torsdag den 28 juli 2011
bind(
     handle(
      Condition Error Arithmetic DivisionByZero,
      fn(c,
        "Division by zero! Restarting..." println
        invokeRestart(:useValue, 3))),
     result = willFail
     "got result: #{result}" println
   ) println


torsdag den 28 juli 2011
arbitrarily sized numbers
          comprehensions              operator shuffling

    decimal numbers        macros reflection/introspection
                                          symbols      homoiconicity
                            ranges                       methods
                messages              dictionaries
      lists              booleans                  pairs
              mixins
    literals                pervasive documentation
           conditions   dynamic typing                     sets
     multi-vm hooks        regular expressions strong typing
                               dynamic places     lexical blocks
   aspects         syntax
     closures                   generalized assignment
                    ratios destructuring
         tuples       icheck                       enumerables
                 java integration      sequences
   prototype based OO                                     blank slate
torsdag den 28 juli 2011
Some	
  drawbacks

torsdag den 28 juli 2011
Slow!

torsdag den 28 juli 2011
VERY	
  mutable

torsdag den 28 juli 2011
No	
  concurrency

torsdag den 28 juli 2011
Library	
  support

torsdag den 28 juli 2011
Experiment

torsdag den 28 juli 2011
No	
  real	
  life	
  use!

torsdag den 28 juli 2011
JSR292

torsdag den 28 juli 2011
MethodHandle

torsdag den 28 juli 2011
Combinator	
  library

torsdag den 28 juli 2011
CallSite

torsdag den 28 juli 2011
ClassValue

torsdag den 28 juli 2011
InvokeDynamic

torsdag den 28 juli 2011
Bootstrap	
  Methods

torsdag den 28 juli 2011
Seph

torsdag den 28 juli 2011
Features

torsdag den 28 juli 2011
Dynamic	
  typing

torsdag den 28 juli 2011
Polymorphic	
  
                             dispatch

torsdag den 28 juli 2011
Prototype	
  based	
  OO
       AKA	
  delegation

torsdag den 28 juli 2011
Immutable	
  objects

torsdag den 28 juli 2011
TCO

torsdag den 28 juli 2011
Mutable	
  lexical
                         	
  scopes

torsdag den 28 juli 2011
Light	
  weight
                              threads

torsdag den 28 juli 2011
Clojure	
  STM

torsdag den 28 juli 2011
Module	
  system

torsdag den 28 juli 2011
Some	
  examples

torsdag den 28 juli 2011
fact = #(n,
                            if(n == 0,
                              1,
                              n * fact(n - 1)))

                           fact(10) println



torsdag den 28 juli 2011
fact = #(n,
                            acc = #(acc, n,
                              if(n == 0,
                                acc,
                                acc(n * acc, n - 1)))
                            acc(1, n))

                           fact(10) println


torsdag den 28 juli 2011
"Command line arguments:" println
            System programArguments each(println)




torsdag den 28 juli 2011
fib = #(
  #(a, b, [b, a + b]) iterate(1, 1) mapped(first)
)

(fib indexed(from: 1) takeWhile(second < 1000) last first + 1) println
fib indexed(from: 1) droppedWhile(second < 1000) first first println




torsdag den 28 juli 2011
bottle = #(i,
            case(i,
             0, "no more bottles of beer",
             1, "1 bottle of beer",
             "#{i} bottles of beer"))

           (99..1) each(i,
             "#{bottle(i)} on the wall, " println
             "take one down, pass it around," println
             "#{bottle(i - 1)} on the wall.n" println
           )
torsdag den 28 juli 2011
foo: #(n, #(i, n += i))




torsdag den 28 juli 2011
foop = #(n,
              receive(
               (p, i), val = n + i. p <- val. foop(val))),

             foo: #(n,
              p = ->(foop(n))
              #(i,
               p <- (currentProcess, i)
               receive(
                 v, v)))

torsdag den 28 juli 2011
IntSet: Something with(
                             empty?: false,
                             adjoin: #(x, Adjoin with(s: self, obj: x)),
                             ∪: #(x, Union with(left: self, right: x))
                           ),

                           Adjoin: IntSet with(
                             contains?: #(y, obj == y || s contains?(y))
                           ),

                           Union: IntSet with(
                             empty?: #(left empty? && right empty?),
                             contains?: #(y, left contains?(y) || right contains?(y))
                           ),

                           Empty: IntSet with(
                             empty?: true,
                             contains?: #(_, false)
                           ),

                           IntegersMod: IntSet with(
                             contains?: #(y, y % n == 0)
                           ),

                           (s, k, n) = (Empty, 2, 0)
                           while(n < 1_000_000,
                             if(prime?(k),
                               s = s adjoin(k)
                               n++
                             )
                             k++
                           )
                           s contains?(13) println

torsdag den 28 juli 2011
Implementation

torsdag den 28 juli 2011
Simple	
  dispatch

torsdag den 28 juli 2011
receiver.
          activationFor(3, false).
          invokeExact(receiver, arg0, arg1, arg2);




torsdag den 28 juli 2011
if(savedIdentity != receiver.identity()) {
      savedIdentity = receiver.identity();
      savedMH = receiver.activationFor(2, false);
  }
  savedMH.invokeExact(receiver, arg0, arg1);




torsdag den 28 juli 2011
Arguments

torsdag den 28 juli 2011
private SephObject argument_1_42(boolean eval) {
    if(eval) {
       // compiled Seph code to eval the argument
    } else {
        return AST_ARGUMENT_1_42;
    }
 }

 private final static MethodHandle ARGUMENT_1_42_MH =
    findVirtual(lookup().lookupClass(), "argument_1_42",
           methodType(SephObject.class, boolean.class));



torsdag den 28 juli 2011
Intrinsics

torsdag den 28 juli 2011
TCO

torsdag den 28 juli 2011
public class SThread {
                               public MethodHandle tail;
                           }// SThread




torsdag den 28 juli 2011
MethodHandle saved =
                     insertArguments(receiver.
                                activationFor(3, false),
                                0,
                                arg0, arg1, arg2);
                  thread.tail = saved;
                  return SThread.TAIL_MARKER;



torsdag den 28 juli 2011
SephObject result = // real operation
      while(current == SThread.TAIL_MARKER) {
         current = thread.tail.invokeExact();
      }
      return result;




torsdag den 28 juli 2011
Activation	
  slow	
  path
             (useful	
  JSR292	
  trick)


torsdag den 28 juli 2011
MethodType#methodType(Class ret, Class... params)
CallSite#type()
MethodHandles#exactInvoker(MethodType type)
MethodHandles#insertArguments(MethodHandle, int pos, Object... args)
MethodHandles#filterArguments(MethodHandle, int pos, MethodHandle... filters)




torsdag den 28 juli 2011
interface SephObject {
                // ...
                MethodHandle activationFor(int arity);
                // ...
             }




torsdag den 28 juli 2011
class SephCallSite extends CallSite {
   public MethodHandle computeSlowPath() {
     MethodHandle invoker = exactInvoker(type());
     MethodHandle activation = findVirtual(SephObject.class, "activationFor",
                             methodType(MethodHandle.class, int.class));
     MethodHandle boundActivation = insertArguments(activation, 0, arityOfThisCallSite());
     return filterArguments(invoker, 0, boundActivation);
   }
}




torsdag den 28 juli 2011
Current/Future

torsdag den 28 juli 2011
Questions?


                             OLA BINI



                             http://olabini.com       @olabini
                             obini@thoughtworks.com

torsdag den 28 juli 2011

Weitere ähnliche Inhalte

Andere mochten auch

Guide nonprofit-marketing-wisdom-2011
Guide nonprofit-marketing-wisdom-2011Guide nonprofit-marketing-wisdom-2011
Guide nonprofit-marketing-wisdom-2011rlcwm
 
Mua thu cho em ppt
Mua thu cho em pptMua thu cho em ppt
Mua thu cho em pptNguyen Chien
 
Chien Luoc Su Pham Thanh Cong
Chien Luoc Su Pham Thanh CongChien Luoc Su Pham Thanh Cong
Chien Luoc Su Pham Thanh CongNguyen Chien
 
4 Minutes Office Exercises
4  Minutes  Office  Exercises4  Minutes  Office  Exercises
4 Minutes Office ExercisesNguyen Chien
 
USS - University Security System
USS - University Security SystemUSS - University Security System
USS - University Security SystemSauli Quirpa Meza
 
Management Control of Projects
Management Control of ProjectsManagement Control of Projects
Management Control of ProjectsE P John
 
Donor cultivation
Donor cultivationDonor cultivation
Donor cultivationrlcwm
 
Dbms in telecommunication industry
Dbms in telecommunication industryDbms in telecommunication industry
Dbms in telecommunication industryE P John
 
Ethics pepsi
Ethics   pepsiEthics   pepsi
Ethics pepsiE P John
 
Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Seven Habits of Highly Effective Jenkins Users (2014 edition!)Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Seven Habits of Highly Effective Jenkins Users (2014 edition!)Andrew Bayer
 

Andere mochten auch (12)

Guide nonprofit-marketing-wisdom-2011
Guide nonprofit-marketing-wisdom-2011Guide nonprofit-marketing-wisdom-2011
Guide nonprofit-marketing-wisdom-2011
 
Mua thu cho em ppt
Mua thu cho em pptMua thu cho em ppt
Mua thu cho em ppt
 
Chien Luoc Su Pham Thanh Cong
Chien Luoc Su Pham Thanh CongChien Luoc Su Pham Thanh Cong
Chien Luoc Su Pham Thanh Cong
 
4 Minutes Office Exercises
4  Minutes  Office  Exercises4  Minutes  Office  Exercises
4 Minutes Office Exercises
 
USS - University Security System
USS - University Security SystemUSS - University Security System
USS - University Security System
 
Orientation Advising Information
Orientation Advising InformationOrientation Advising Information
Orientation Advising Information
 
Management Control of Projects
Management Control of ProjectsManagement Control of Projects
Management Control of Projects
 
Donor cultivation
Donor cultivationDonor cultivation
Donor cultivation
 
Dbms in telecommunication industry
Dbms in telecommunication industryDbms in telecommunication industry
Dbms in telecommunication industry
 
Who *is* Jenkins?
Who *is* Jenkins?Who *is* Jenkins?
Who *is* Jenkins?
 
Ethics pepsi
Ethics   pepsiEthics   pepsi
Ethics pepsi
 
Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Seven Habits of Highly Effective Jenkins Users (2014 edition!)Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Seven Habits of Highly Effective Jenkins Users (2014 edition!)
 

Kürzlich hochgeladen

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 

Kürzlich hochgeladen (20)

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 

OSCON - Emerging Languages - Seph (2011/07/27)

  • 1. Ola  Bini computational  metalinguist   ola.bini@gmail.com http://olabini.com/blog torsdag den 28 juli 2011
  • 2. Ola  Bini Swedish  language  geek Works  for  ThoughtWorks  in  Chicago JRuby  core  committer Designer  of  Ioke  and  Seph Member  of  JSR292  Expert  Group torsdag den 28 juli 2011
  • 3. Language  design Communication Expressiveness Simplicity Homoiconicity Language  flexibility torsdag den 28 juli 2011
  • 5. A  precursor:  Ioke torsdag den 28 juli 2011
  • 6. The  position  of   Ioke torsdag den 28 juli 2011
  • 8. 0 fact = 1 Number fact = method(self * (self - 1) fact) 10 fact println torsdag den 28 juli 2011
  • 9. "Command line arguments:" println System programArguments each(println) torsdag den 28 juli 2011
  • 10. fib = method( fn(a, b, [b, a + b]) iterate(1, 1) mapped(first) ) (fib indexed(from: 1) takeWhile(second < 1000) last first + 1) println fib indexed(from: 1) droppedWhile(second < 1000) first first println torsdag den 28 juli 2011
  • 11. bottle = method(i, case(i, 0, "no more bottles of beer", 1, "1 bottle of beer", "#{i} bottles of beer")) (99..1) each(i, "#{bottle(i)} on the wall, " println "take one down, pass it around," println "#{bottle(i - 1)} on the wall.n" println ) torsdag den 28 juli 2011
  • 12. use("mandarin") = ( = ( , : , :, -= += ) = ( "< : #{ } : #{ }>" ) ) = ( : " ", : 142.0) = ( : " ", : 45.7) (23.0, : , : ) (10.0, : , : ) (57.4, : ) torsdag den 28 juli 2011
  • 13. words = method(text, #/[a-z]+/ allMatches(text lower)) train = method(features, features fold({} withDefault(1), model, f, model[f] ++. model)) NWORDS = train(words(FileSystem readFully("small.txt"))) alphabet = "abcdefghijklmnopqrstuvwxyz" chars edits1 = method(word, s = for(i <- 0..(word length + 1), [word[0...i], word[i..-1]]) set(*for(ab <- s, ab[0] + ab[1][1..-1]), ;deletes *for(ab <- s[0..-2], ab[0] + ab[1][1..1] + ab[1][0..0] + ab[1][2..-1]), ;transposes *for(ab <- s, c <- alphabet, ab[0] + c + ab[1][1..-1]), ;replaces *for(ab <- s, c <- alphabet, ab[0] + c + ab[1]))) ;inserts knownEdits2 = method(word, for:set(e1 <- edits1(word), e2 <- edits1(e1), NWORDS key?(e2), e2)) known = method(words, for:set(w <- words, NWORDS key?(w), w)) correct = method(word, candidates = known([word]) ?| known(edits1(word)) ?| knownEdits2(word) ?| [word] candidates max(x, NWORDS[x])) torsdag den 28 juli 2011
  • 14. import(:javax:swing, :JFrame, :JButton) import java:awt:GridLayout button = JButton new("Press me!") do( addActionListener(fn(e, button text = "Hello from Ioke")) addActionListener(fn(e, "button pressed" println))) JFrame new("My Frame") do( layout = GridLayout new(2, 2, 3, 3) add(button) setSize(300, 80) visible = true) torsdag den 28 juli 2011
  • 16. forAll(int x, int y, where: x < y, [x, y] sort should == [x, y]) torsdag den 28 juli 2011
  • 17. forAll(int x, int y, where: y < x, classify(trivial) x == y, classifyAs(close) (x - y) abs < 2, [x,y] sort should == [y,x] sort) torsdag den 28 juli 2011
  • 18. forAll(list(int) xs, xs reverse reverse should == xs) torsdag den 28 juli 2011
  • 19. forEvery(integer x, integer y, [x, y] max should >= [x, y] min) torsdag den 28 juli 2011
  • 20. forAll(int x, int y, [x,y] sort should == [x,y]) torsdag den 28 juli 2011
  • 22. willFail = method( 10 / 0 ) torsdag den 28 juli 2011
  • 23. bind( rescue( Condition Error Arithmetic DivisionByZero, fn(c, "Division by zero! Failing..." println nil)), result = willFail "got result: #{result}" println ) println torsdag den 28 juli 2011
  • 24. bind( handle( Condition Error Arithmetic DivisionByZero, fn(c, "Division by zero! Restarting..." println invokeRestart(:useValue, 3))), result = willFail "got result: #{result}" println ) println torsdag den 28 juli 2011
  • 25. arbitrarily sized numbers comprehensions operator shuffling decimal numbers macros reflection/introspection symbols homoiconicity ranges methods messages dictionaries lists booleans pairs mixins literals pervasive documentation conditions dynamic typing sets multi-vm hooks regular expressions strong typing dynamic places lexical blocks aspects syntax closures generalized assignment ratios destructuring tuples icheck enumerables java integration sequences prototype based OO blank slate torsdag den 28 juli 2011
  • 27. Slow! torsdag den 28 juli 2011
  • 32. No  real  life  use! torsdag den 28 juli 2011
  • 40. Seph torsdag den 28 juli 2011
  • 43. Polymorphic   dispatch torsdag den 28 juli 2011
  • 44. Prototype  based  OO AKA  delegation torsdag den 28 juli 2011
  • 46. TCO torsdag den 28 juli 2011
  • 47. Mutable  lexical  scopes torsdag den 28 juli 2011
  • 48. Light  weight threads torsdag den 28 juli 2011
  • 52. fact = #(n, if(n == 0, 1, n * fact(n - 1))) fact(10) println torsdag den 28 juli 2011
  • 53. fact = #(n, acc = #(acc, n, if(n == 0, acc, acc(n * acc, n - 1))) acc(1, n)) fact(10) println torsdag den 28 juli 2011
  • 54. "Command line arguments:" println System programArguments each(println) torsdag den 28 juli 2011
  • 55. fib = #( #(a, b, [b, a + b]) iterate(1, 1) mapped(first) ) (fib indexed(from: 1) takeWhile(second < 1000) last first + 1) println fib indexed(from: 1) droppedWhile(second < 1000) first first println torsdag den 28 juli 2011
  • 56. bottle = #(i, case(i, 0, "no more bottles of beer", 1, "1 bottle of beer", "#{i} bottles of beer")) (99..1) each(i, "#{bottle(i)} on the wall, " println "take one down, pass it around," println "#{bottle(i - 1)} on the wall.n" println ) torsdag den 28 juli 2011
  • 57. foo: #(n, #(i, n += i)) torsdag den 28 juli 2011
  • 58. foop = #(n, receive( (p, i), val = n + i. p <- val. foop(val))), foo: #(n, p = ->(foop(n)) #(i, p <- (currentProcess, i) receive( v, v))) torsdag den 28 juli 2011
  • 59. IntSet: Something with( empty?: false, adjoin: #(x, Adjoin with(s: self, obj: x)), ∪: #(x, Union with(left: self, right: x)) ), Adjoin: IntSet with( contains?: #(y, obj == y || s contains?(y)) ), Union: IntSet with( empty?: #(left empty? && right empty?), contains?: #(y, left contains?(y) || right contains?(y)) ), Empty: IntSet with( empty?: true, contains?: #(_, false) ), IntegersMod: IntSet with( contains?: #(y, y % n == 0) ), (s, k, n) = (Empty, 2, 0) while(n < 1_000_000, if(prime?(k), s = s adjoin(k) n++ ) k++ ) s contains?(13) println torsdag den 28 juli 2011
  • 62. receiver. activationFor(3, false). invokeExact(receiver, arg0, arg1, arg2); torsdag den 28 juli 2011
  • 63. if(savedIdentity != receiver.identity()) { savedIdentity = receiver.identity(); savedMH = receiver.activationFor(2, false); } savedMH.invokeExact(receiver, arg0, arg1); torsdag den 28 juli 2011
  • 65. private SephObject argument_1_42(boolean eval) { if(eval) { // compiled Seph code to eval the argument } else { return AST_ARGUMENT_1_42; } } private final static MethodHandle ARGUMENT_1_42_MH = findVirtual(lookup().lookupClass(), "argument_1_42", methodType(SephObject.class, boolean.class)); torsdag den 28 juli 2011
  • 67. TCO torsdag den 28 juli 2011
  • 68. public class SThread { public MethodHandle tail; }// SThread torsdag den 28 juli 2011
  • 69. MethodHandle saved = insertArguments(receiver. activationFor(3, false), 0, arg0, arg1, arg2); thread.tail = saved; return SThread.TAIL_MARKER; torsdag den 28 juli 2011
  • 70. SephObject result = // real operation while(current == SThread.TAIL_MARKER) { current = thread.tail.invokeExact(); } return result; torsdag den 28 juli 2011
  • 71. Activation  slow  path (useful  JSR292  trick) torsdag den 28 juli 2011
  • 72. MethodType#methodType(Class ret, Class... params) CallSite#type() MethodHandles#exactInvoker(MethodType type) MethodHandles#insertArguments(MethodHandle, int pos, Object... args) MethodHandles#filterArguments(MethodHandle, int pos, MethodHandle... filters) torsdag den 28 juli 2011
  • 73. interface SephObject { // ... MethodHandle activationFor(int arity); // ... } torsdag den 28 juli 2011
  • 74. class SephCallSite extends CallSite { public MethodHandle computeSlowPath() { MethodHandle invoker = exactInvoker(type()); MethodHandle activation = findVirtual(SephObject.class, "activationFor", methodType(MethodHandle.class, int.class)); MethodHandle boundActivation = insertArguments(activation, 0, arityOfThisCallSite()); return filterArguments(invoker, 0, boundActivation); } } torsdag den 28 juli 2011
  • 76. Questions? OLA BINI http://olabini.com @olabini obini@thoughtworks.com torsdag den 28 juli 2011