OSCON - Emerging Languages - Seph (2011/07/27)
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
638
On Slideshare
637
From Embeds
1
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 1

http://twitter.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Ola  Bini computational  metalinguist   ola.bini@gmail.com http://olabini.com/blogtorsdag 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  Grouptorsdag den 28 juli 2011
  • 3. Language  design Communication Expressiveness Simplicity Homoiconicity Language  flexibilitytorsdag den 28 juli 2011
  • 4. Expressivenesstorsdag den 28 juli 2011
  • 5. A  precursor:  Ioketorsdag den 28 juli 2011
  • 6. The  position  of   Ioketorsdag den 28 juli 2011
  • 7. Some  examplestorsdag den 28 juli 2011
  • 8. 0 fact = 1 Number fact = method(self * (self - 1) fact) 10 fact printlntorsdag 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 printlntorsdag 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" charsedits1 = 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]))) ;insertsknownEdits2 = 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
  • 15. IChecktorsdag 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
  • 21. Conditionstorsdag 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 ) printlntorsdag 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 ) printlntorsdag 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 slatetorsdag den 28 juli 2011
  • 26. Some  drawbackstorsdag den 28 juli 2011
  • 27. Slow!torsdag den 28 juli 2011
  • 28. VERY  mutabletorsdag den 28 juli 2011
  • 29. No  concurrencytorsdag den 28 juli 2011
  • 30. Library  supporttorsdag den 28 juli 2011
  • 31. Experimenttorsdag den 28 juli 2011
  • 32. No  real  life  use!torsdag den 28 juli 2011
  • 33. JSR292torsdag den 28 juli 2011
  • 34. MethodHandletorsdag den 28 juli 2011
  • 35. Combinator  librarytorsdag den 28 juli 2011
  • 36. CallSitetorsdag den 28 juli 2011
  • 37. ClassValuetorsdag den 28 juli 2011
  • 38. InvokeDynamictorsdag den 28 juli 2011
  • 39. Bootstrap  Methodstorsdag den 28 juli 2011
  • 40. Sephtorsdag den 28 juli 2011
  • 41. Featurestorsdag den 28 juli 2011
  • 42. Dynamic  typingtorsdag den 28 juli 2011
  • 43. Polymorphic   dispatchtorsdag den 28 juli 2011
  • 44. Prototype  based  OO AKA  delegationtorsdag den 28 juli 2011
  • 45. Immutable  objectstorsdag den 28 juli 2011
  • 46. TCOtorsdag den 28 juli 2011
  • 47. Mutable  lexical  scopestorsdag den 28 juli 2011
  • 48. Light  weight threadstorsdag den 28 juli 2011
  • 49. Clojure  STMtorsdag den 28 juli 2011
  • 50. Module  systemtorsdag den 28 juli 2011
  • 51. Some  examplestorsdag den 28 juli 2011
  • 52. fact = #(n, if(n == 0, 1, n * fact(n - 1))) fact(10) printlntorsdag den 28 juli 2011
  • 53. fact = #(n, acc = #(acc, n, if(n == 0, acc, acc(n * acc, n - 1))) acc(1, n)) fact(10) printlntorsdag 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) printlnfib indexed(from: 1) droppedWhile(second < 1000) first first printlntorsdag 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) printlntorsdag den 28 juli 2011
  • 60. Implementationtorsdag den 28 juli 2011
  • 61. Simple  dispatchtorsdag 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
  • 64. Argumentstorsdag 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
  • 66. Intrinsicstorsdag den 28 juli 2011
  • 67. TCOtorsdag den 28 juli 2011
  • 68. public class SThread { public MethodHandle tail; }// SThreadtorsdag 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
  • 75. Current/Futuretorsdag den 28 juli 2011
  • 76. Questions? OLA BINI http://olabini.com @olabini obini@thoughtworks.comtorsdag den 28 juli 2011