michael homer programming languages
play

Michael Homer Programming Languages 2 Research focus Making - PowerPoint PPT Presentation

Michael Homer Programming Languages 2 Research focus Making programming more accessible to non-programmers. Making (sub-)language creation more available to programmers Packaging 3 Enabling embedded domain-specific languages We


  1. Michael Homer

  2. Programming Languages 2

  3. Research focus • Making programming more accessible to non-programmers. • Making (sub-)language creation more available to programmers • Packaging 3

  4. Enabling embedded domain-specific languages We want to let a programmer write a library that • extends the language, • restricts the language, • or some combination of the two. Graceful Dialects. Homer et al . ECOOP’14. 4

  5. Extending the language dslhlpr aDSL ModuleX aDSL dialect "aDSL" dialect "dslhlpr" ... ... method use(arg1) on(arg2) { ... use { x } on(arg) ... } ... 5

  6. Restricting the language 6

  7. Turtle graphics method repeat(n)times(blk) { import "turtle" as turtle def red = turtle .red var counter := 1 while { counter < = n } do { ... var lineWidth := 1 blk.apply var lineColour := black counter := counter + 1 method forward(dist) { } } turtle .move(dist, lineColour, lineWidth) method atModuleEnd(mod) { } turtle . start method turnRight(ang) { } turtle .turnRight(ang) } ... 7

  8. Helping to write restrictive dialects method checker(ast) { // Loop over every node and examine it for (ast.nodes) do { n − > for (rules) do { r − > ... } } } method rule(block) { rules.push(block) } method when(pred : UnaryPredicate) error(msg : String) { rule { node − > def matches = pred.match(node) if (matches.andAlso { matches.result } ) then { fail(msg) } } } 8

  9. Enforcing nominal types rule { req : QualifiedRequest − > def rType = typeOf(req.receiver) match (rType) case { r : Brand − > ... } } rule { decl : Let − > def eType = typeOf(decl.value) if (BrandType.match(eType)) then { eType.name := decl.name.value } } Brand Objects for Nominal Typing. 209 LOC total Jones, Homer, and Noble. ECOOP’15. 9

  10. GrAPL dialect "grapl" N ← [1, 2, 3, 4] print (N) // Prints [1, 2, 3, 4] print (N + 2) // Prints [3, 4, 5, 6] print (+/N) // Prints 10 // Standard Lotto example. print (L[ | � (L ← (n 6 ? 40))]) // Calculate primes up to 20. print ((P ← (n 1 ↓ ι 20))/ � (P ∈ (P ◦· ∗ P))) 10

  11. Combining tiled and textual programming Combining Tiled and Textual Views of Code. Homer and Noble. VISSOFT’14. 11

  12. Tiled Grace http://ecs.vuw.ac.nz/˜mwh/minigrace/tiled/ Combining Tiled and Textual Views of Code. Homer and Noble. VISSOFT’14. 12

  13. Switching views • Median participant switched 6 times. • 75% switched at least 4 times. • Half of participants spent between 24% and 52% of their time in text view. 6 count 4 2 0 0 5 10 15 20 Total number of switches of view 13

  14. Error reporting “The way of showing errors was amazingly helpful.” “It also gave specific detail about the error.” “Error finding and handling looks great, is very easy and straightforward.” Finding errors in the code was easy 1 Agree 10 2 count 3 4 Neutral 5 5 6 7 Disagree 0 1 2 3 4 5 6 7 Agree Neutral Disagree Finding errors in the code was easy 14

  15. Engagement 14:00 13:00 12:00 Time spent unprompted on Task 5 (minutes) 11:00 10:00 9:00 8:00 7:00 6:00 70% used system More or less 5:00 time than this 4:30 Less when they didn’t 4:00 More 3:30 have to. 3:00 2:30 2:00 1:30 1:00 0:45 0:30 0:15 0 10 20 30 count 15

  16. Engagement 40% Percentage choosing each option 30% How many technologies used Ten or fewer 20% More than ten 10% 0% 1 2 3 4 5 6 7 Agree Neutral Disagree The system was fun to use 16

  17. Ongoing • Gradual typing • Concatenative programming • Package management • Object inheritance 17

  18. Outlook 18

  19. References • Graceful Dialects. European Conference on Object-Oriented Programming (ECOOP), 2014. Michael Homer, Timothy Jones, James Noble, Kim B. Bruce, and Andrew P . Black. • Brand Objects for Nominal Typing. European Conference on Object-Oriented Programming (ECOOP), 2015. Timothy Jones, Michael Homer, and James Noble. • From APIs to Languages: Generalising Method Names. Dynamic Language Symposium (DLS), 2015. Michael Homer, Timothy Jones, and James Noble. • Patterns as Objects in Grace. Dynamic Language Symposium (DLS), 2012. Michael Homer, James Noble, Kim B. Bruce, Andrew P . Black, and David J. Pearce. • Combining Tiled and Textual Views of Code. IEEE Working Conference on Software Visualisation (VISSOFT), 2014. Michael Homer and James Noble. • A Tile-based Editor for a Textual Programming Language. IEEE Working Conference on Software Visualisation (VISSOFT), 2013. Michael Homer and James Noble. 19

  20. Michael Homer

  21. Multi-part method names method check(x) between(low) and(high) { return (x > = low) && (x < = high) } if (x < y) then { print "less" } else { print "Not less" } 21

  22. Repeated parts + before a part means it can appear more than once. method a(x) +b(y) { ... } accepts requests a(1) b(2) a(1) b(2) b(3) a(1) b(2) b(3) b(4) ... ∗ means zero or more times. 22

  23. Parameter binding Parameters in repeated parts are bound as sequences. method a(w) +b(x, y) c(z) { // x and y are sequences here for (x) do { xv − > print(xv) } // w and z are not print (w) } 23

  24. Optional parts ? before a part means it is optional. method a(x) ?b(y) { ... } accepts requests a(1) a(1) b(2) Parameters are also bound as trivial sequences. 24

  25. Grouping parts Parentheses around parts create a group for other modifiers. method a(x) ?(b(y) c(z)) { ... } accepts requests a(1) a(1) b(2) c(3) but not a(1) b(2) a(1) c(3) 25

  26. Alternations | inside a group creates an alternation. method a(x) (b(y) | c(z)) { ... } accepts requests a(1) b(2) a(1) c(3) 26

  27. Prefixes Methods are uniquely identified by their prefix of required parts. Declaration Prefix a(x) b(y) c(z) 1 a b c a(x) b(y) ?c(z) 2 a b a(x) ?b(y) c(z) 3 a a(x) +b(y) c(z) 4 a b Shortest prefix used: there is at most one method in an object that could be selected to respond to any given request. 27

  28. Greedy matching Match request and declaration parts left to right, committing to potential matches eagerly. Greedy matching of parts allows concrete error messages: Error: expected to see part "finally" but saw part "else" instead. 28

  29. Uncallable methods method a(x) ∗ b(y) b(z) {} There is never a b left for the last part to match. However, the requests presumably intended are accepted by: method a(x) +b(y) {} 29

  30. match case... method match(target) +case(cases) { for (cases) do { case − > def mr = case.match(target) if (mr) then { return mr.result } } fail "Match was not exhaustive" } 30

  31. Control structures method if(bool) then(blk) +( elseif (conds) then(blks)) ?else(elseblk) { ... } method try(blk) ∗ catch(catchblk) ? finally ( finallyblk ) { ... } 31

  32. Testing DSL method feature(name) ?background( initialisation ) +(scenario(desc) ?(Given(context) ∗ And(contexts)) When(event) Then(expr) ShouldBe(val) ∗ (And(exprs) ShouldBe(vals))) Based on http://cucumber.io/ ’s testing language 32

  33. Creating a button Declarative construction of a button: gtk.button { document.save } label "Save" image(icons.floppy disk) position(gtk. position . right ) relief (gtk. relief .none) Well-formedness of method name guarantees semantic validity. 33

  34. Embedded DSL: Query language from(students) Where { s − > s.enrolledIn "COMP231" } Where { s − > s.age > 25 } OrderBy { s − > s.gpa } ThenBy { s − > s.age } ThenBy { s − > s.id } Select { s − > s.name } from s in students where s.enrolledIn( "COMP231" ) where s.age > 25 orderby s.gpa, s.age, s.id select s.name 34

  35. selectProjection .do { p − > return data.select(p) } thenBys.do { ifPresent − > for (ifPresent) do { t − > data := data.thenBy(t) } } 35

  36. Library initialisation method button(handler : Block) ( ( label( text : String) | mnemonic(mt : String)) ?(image(textImage : Image) ?position(imagePos:PositionType) ) | namedIcon(name : String, size : IconSize) | image(image : Image) | widget(w : Widget) ) ? relief ( style : ReliefStyle) ?alignment(xalign : Number, yalign : Number) { ... } 36

  37. Greedy matching To match request parts to declaration parts: 1. Match the prefix of both. This is known to match exactly by the method resolution rules. 2. If the current request part is accepted by the current declaration part, commit to it (bind the request arguments into the declaration parameters) and advance the request part. If the declaration part is a group, it matches if the prefix of the group matches the request starting at this point. (a) If the declaration part is not a + or ∗ , advance the declaration part. Go to 2 37

  38. 3. If the current request part is not accepted by the current declaration part: (a) If the current declaration part is a ∗ or ? , advance the declaration part and go to 2. (b) If the current declaration part is a + that has already consumed at least one request part, advance the declaration part and go to 2. (c) Otherwise, report an error “expected part X, saw part Y”. 4. If there are no more declaration parts and there are remaining request parts, report an error. 5. If there are no more request parts, and any remaining declaration part is not optional, report an error. 38

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