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

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Kürzlich hochgeladen (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

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