building a graceful language
play

Building A Graceful Language Design by Instructor Timothy Jones - PowerPoint PPT Presentation

Building A Graceful Language Design by Instructor Timothy Jones Victoria University of Wellington tim@ecs.vuw.ac.nz December 16, 2013 The Language The Language Frustration with languages used for teaching Pascal is old, Java is bloated


  1. Building A Graceful Language Design by Instructor Timothy Jones Victoria University of Wellington tim@ecs.vuw.ac.nz December 16, 2013

  2. The Language The Language Frustration with languages used for teaching Pascal is old, Java is bloated Grace is the absence of everything that indicates pain or difficulty, hesitation or incongruity. — William Hazlitt 1

  3. The Language Goals ◮ Support multiple paradigms ◮ Objects ◮ Scripting/Procedural ◮ Functional ◮ Minimise conceptual burden ◮ Diverse applications within syntactically consistent language 2

  4. The Language First Taste In Java: public class Main { public static void main(String[] args) { System.out.println( "Hello world" ); } } In Grace: print "Hello world" 3

  5. The Language Objects var john := object { def name is public = "John" method say(phrase) { print "John says { phrase } " } print "John has been born!" } 4

  6. The Language Gradually Typed type Person = { name → String say(phrase : String) → Done } var kate : Person := object { def name : String is public = "Kate" method say(phrase : String) → Done { print "Kate says { phrase } " } } 5

  7. The Language Classes class aPerson.named(name ′ ) → Person { def name is public = name ′ method say(phrase) { print " { name } says { phrase } " } } Translates to: def aPerson = object { method named(name ′ ) → Person { object { def name is public = name ′ method say(phrase) { print " { name } says { phrase } " } } } } 6

  8. The Language Blocks First class functions: def double = { x → x + x } double.apply 10 Like numbers and strings, no need for parens in method requests method shifUp(list : List � Number � ) { list.map { x → x + 1 } } 7

  9. The Language Control Structures Methods may be written ‘mixfix’ method substringFrom(start) to(end) { ... } str.substringFrom 3 to 5 Combined with blocks, we can define our own control structures: method while(cond) do(block) { if(cond.apply) then { block.apply while(cond) do(block) } } while { x < y } do { x := x ∗ 2 } 8

  10. The Language Dialects Change the local definitions (but not the syntax) of a module Check that the module conforms to certain rules (eg. must use types, no mutable variables) The entire static type system is just a dialect! 9

  11. The Designers The Designers ◮ Andrew Black ◮ Kim Bruce ◮ James Noble 10

  12. The Designers The Designers ◮ Object Constructors and Dynamic Typing ◮ Kim Bruce ◮ James Noble 10

  13. The Designers The Designers ◮ Object Constructors and Dynamic Typing ◮ Classes and Static Typing ◮ James Noble 10

  14. The Designers The Designers ◮ Object Constructors and Dynamic Typing ◮ Classes and Static Typing ◮ The Mediator 10

  15. The Designers The Audience Designed by Instructors, for Instructors Differences of opinion in the design represent real-world differences of opinion in how OO should be taught Compromise leads to interesting design decisions! 11

  16. Object Inheritance Implementing Inheritance Objects-only? Delegation! def snake = object { def noise = "hiss" method makeNoise { print( self .noise) } } def ratleSnake = object { inherits snake def noise = "rattle" } 12

  17. Object Inheritance Implementing Inheritance Objects-only? Delegation! def snake = object { def noise = "hiss" method makeNoise { print( self .noise) // self is bound to the receiver of makeNoise } } def ratleSnake = object { inherits snake def noise = "rattle" } 12

  18. Object Inheritance The Identity Problem The two objects have separate identities! def snake = object { def this = self def noise = "hiss" method makeNoise { print(this.noise) } } def ratleSnake = object { inherits snake def noise = "rattle" } 13

  19. Object Inheritance ‘Becomes’ Inheritance Solution: an inheriting object merges identities with its super object class aSnake.new { def this = self def noise = "hiss" method makeNoise { print(this.noise) // identity of self is rewritten to be rattleSnake } } def ratleSnake = object { inherits aSnake.new // can only inherit from a fresh object def noise = "rattle" } 14

  20. Object Inheritance Initialisation Problem Objects have different structure at each part of the constructor chain class aSnake.new { def noise = "hiss" self .makeNoise // self is not yet rattleSnake } def ratleSnake = object { inherits aSnake.new def noise = "rattle" method makeNoise { print( self .noise) } } 15

  21. Object Inheritance Constructor Specialisation Every method with a tail-call object has two variants method new { object {} } method new_inherits( self ) { ... } Essentially JavaScript’s new Snake vs. Snake.call( this ) 16

  22. Object Inheritance Abstract methods class aBird.new { method fly { if( self .canFly) then { print "take off!" } else { print "crashed!" } } } def kiwi = object { inherits aBird.new def canFly = false } 17

  23. Object Inheritance Abstract methods class aBird.new { // is this class well-typed? method fly { if( self .canFly) then { print "take off!" } else { print "crashed!" } } } def kiwi = object { inherits aBird.new def canFly = false } 17

  24. Typing Self Typing Self What is the type of self ? The value is never explicitly given a type, so how do you supply it? 18

  25. Typing Self Typing Self What is the type of self ? The value is never explicitly given a type, so how do you supply it? Default is dynamic, add extra information in a dialect 18

  26. Typing Self Typing Self What is the type of self ? The value is never explicitly given a type, so how do you supply it? Default is dynamic, add extra information in a dialect Add annotations to prevent all-or-nothing scenario 18

  27. Status Report How far away are we? ◮ Trial courses starting next year ◮ Tooling and development environments the next major goal ◮ Ready for general consumption by 2015? 19

  28. Links Links gracelang.org ecs.vuw.ac.nz/~mwh/minigrace/js github.com/mwh/minigrace grace-core@cecs.pdx.edu 20

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend