Intro to io

888 views
805 views

Published on

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
888
On SlideShare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
11
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Intro to io

  1. 1. Intro to IoWednesday, 28 November, 12
  2. 2. Intro to Io * Not really an IntroWednesday, 28 November, 12
  3. 3. Me • Jeremy Tregunna • iOS & Mac developer • Aspiring hardware designer (FPGAs, etc) • Twitter: @jtregunna • App.net: @jtregunna • GitHub: @jeremytregunnaWednesday, 28 November, 12
  4. 4. Slideshare • Small fonts, check this out to follow along better: http://www.slideshare.net/jtregunna/intro-to-io Github • Code! https://github.com/jeremytregunna/intro-to-ioWednesday, 28 November, 12
  5. 5. What is it? • Object-oriented • Classless design (based on Prototypes)Wednesday, 28 November, 12
  6. 6. What is it? • Object-oriented • Classless design (based on Prototypes) 1 Elephant := Object clone do( 2 earSize := “medium” 3 height := “big” 4 color := Color greyColor 5 ) 6 7 Dumbo := Elephant clone do( 8 earSize = “large” 9 canFly := true 10 height := “short” 11 wearsBowtie := true 12 )Wednesday, 28 November, 12
  7. 7. What is it? • Object-oriented • Classless design (based on Prototypes) 1 Elephant := Object clone do( 2 earSize := “medium” 3 height := “big” 4 color := Color greyColor 5 ) 6 7 Dumbo := Elephant clone do( 8 earSize = “large” 9 canFly := true 10 height := “short” 11 wearsBowtie := true 12 ) • Open Source • Magical tool belt • SlowWednesday, 28 November, 12
  8. 8. Fundamentals • Objects receive messages • Messages are first class entities 1 msg := message(+ 2 * 5) 2 1 doMessage(msg) == 11 # same as: 1 + 2 * 5 • Objects are unavoidable Every message send is received by some object, 100% of the time. • Operators are implemented as methods 1 1 + 2 * 5 # is really: 1 +(2) *(5) 2 foo := 42 # is really: setSlot(“foo”, 42) • Concurrency first class Cooperative threadingWednesday, 28 November, 12
  9. 9. Operators • Operators are messages, they have a precedence. • Precedence is defined in the OperatorTable • Two types of operators, binary and assignment. 1 /* Binary */ 1 + 2 2 /* Assign */ foo := 42 • You can define your own 1 # operators.io 2 OperatorTable addOperator("blah", 14) 3 blah := method(x, "#{x}#{x}" interpolate println) 4 doFile("opertest.io") 1 # opertest.io 2 message(blah "bar") println 3 blah "bar" • All operators must be defined before the parser parses code that uses them!!!Wednesday, 28 November, 12
  10. 10. Conditionals • If statement isn’t a statement 1 if := method(c, 2 (c != nil and c != false) ifTrue(return call evalArgAt(1)) ifFalse(return call evalArgAt(2)) 3 )Wednesday, 28 November, 12
  11. 11. Conditionals • If statement isn’t a statement 1 if := method(c, 2 (c != nil and c != false) ifTrue(return call evalArgAt(1)) ifFalse(return call evalArgAt(2)) 3 ) • Only needs one primitive to implement. 1 # Using “evalArgAt()” we can selectively evaluate an arbitrary argument 2 true ifTrue := method(call evalArgAt(0); self) 3 true ifFalse := true 4 false ifTrue := false 5 false ifFalse := method(call evalArgAt(0); self)Wednesday, 28 November, 12
  12. 12. Conditionals • If statement isn’t a statement 1 if := method(c, 2 (c != nil and c != false) ifTrue(return call evalArgAt(1)) ifFalse(return call evalArgAt(2)) 3 ) • Only needs one primitive to implement. 1 # Using “evalArgAt()” we can selectively evaluate an arbitrary argument 2 true ifTrue := method(call evalArgAt(0); self) 3 true ifFalse := true 4 false ifTrue := false 5 false ifFalse := method(call evalArgAt(0); self) • Full if() support? 1 if := method(c, 2 call argAt(1) isNil ifTrue(return (c != nil and c != false)) # if() then() ... form 3 (c != nil and c != false) ifTrue(return call evalArgAt(1)) ifFalse(return call evalArgAt(2)) 4 ) 5 Object then := nil 6 Object else := nil 7 true then := method(call evalArgAt(0); self) 8 true else := true 9 false then := false 10 false else := method(call evalArgAt(0); self) • Looks familiar...Wednesday, 28 November, 12
  13. 13. Metaprogramming • Here be dragons!Wednesday, 28 November, 12
  14. 14. Metaprogramming • Here be dragons! • Higher order messaging • Messages are our AST • Messages are mutable at runtime 1 Number add := method(n, self + n) 2 5 add(2) == 7 3 Number sub := Number getSlot(“add”) do(message next setName(“-”)) 4 5 sub(2) == 3 5 5 add(2) == 3 # ???Wednesday, 28 November, 12
  15. 15. Metaprogramming • Here be dragons! • Higher order messaging • Messages are our AST • Messages are mutable at runtime 1 Number add := method(n, self + n) 2 5 add(2) == 7 3 Number sub := Number getSlot(“add”) do(message next setName(“-”)) 4 5 sub(2) == 3 5 5 add(2) == 3 # ??? • Don’t forget to cloneWednesday, 28 November, 12
  16. 16. Metaprogramming • Here be dragons! • Higher order messaging • Messages are our AST • Messages are mutable at runtime 1 Number add := method(n, self + n) 2 5 add(2) == 7 3 Number sub := Number getSlot(“add”) do(message next setName(“-”)) 4 5 sub(2) == 3 5 5 add(2) == 3 # ??? • Don’t forget to clone 1 Number sub := Number getSlot(“add”) clone do(message next setName(“-”)) 2 5 sub(2) == 3 3 5 add(2) == 7Wednesday, 28 November, 12
  17. 17. Concurrency • Lightweight threading (coroutines) • Independent of the C Stack* • Cooperative scheduling of coroutines * - For pure Io code only.Wednesday, 28 November, 12
  18. 18. Concurrency greeter := Object clone do( newSlot("coro"); newSlot("waitingCoro") run := method( coro = coroDo( pause names := list("Fred", "Wilma", "Betty", "Barney") names foreach(i, name, if(i == names size - 1, "#{name}" interpolate println System exit , "#{name}, " interpolate print ) waitingCoro resume ) ) ) hello := method( "Hello " print setWaitingCoro := Coroutine currentCoro coro resume ) ) greeter run; greeter hello # Hello Fred, Wilma, Betty, BarneyWednesday, 28 November, 12

×