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

michael homer programming languages
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Michael Homer

slide-2
SLIDE 2

Programming Languages

2

slide-3
SLIDE 3

Research focus

  • Making programming more

accessible to non-programmers.

  • Making (sub-)language creation

more available to programmers

  • Packaging

3

slide-4
SLIDE 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

slide-5
SLIDE 5

Extending the language

aDSL ModuleX

dialect "aDSL" ... ... use {x} on(arg) ...

dslhlpr aDSL

dialect "dslhlpr" ... method use(arg1)

  • n(arg2) {

...

}

5

slide-6
SLIDE 6

Restricting the language

6

slide-7
SLIDE 7

Turtle graphics

import "turtle" as turtle def red = turtle .red ... var lineWidth := 1 var lineColour := black method forward(dist) { turtle .move(dist, lineColour, lineWidth)

}

method turnRight(ang) { turtle .turnRight(ang)

}

... method repeat(n)times(blk) { var counter := 1 while {counter <= n} do { blk.apply counter := counter + 1

} }

method atModuleEnd(mod) { turtle . start

}

7

slide-8
SLIDE 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

slide-9
SLIDE 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

} }

209 LOC total

Brand Objects for Nominal Typing. Jones, Homer, and Noble. ECOOP’15.

9

slide-10
SLIDE 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

slide-11
SLIDE 11

Combining tiled and textual programming

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

slide-12
SLIDE 12

Tiled Grace

http://ecs.vuw.ac.nz/˜mwh/minigrace/tiled/

Combining Tiled and Textual Views of Code. Homer and Noble. VISSOFT’14.

12

slide-13
SLIDE 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.

2 4 6 5 10 15 20

Total number of switches of view count

13

slide-14
SLIDE 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.”

5 10 1 Agree 2 3 4 Neutral 5 6 7 Disagree

Finding errors in the code was easy count

Finding errors in the code was easy 1 Agree 2 3 4 Neutral 5 6 7 Disagree

14

slide-15
SLIDE 15

Engagement

0:15 0:30 0:45 1:00 1:30 2:00 2:30 3:00 3:30 4:00 4:30 5:00 6:00 7:00 8:00 9:00 10:00 11:00 12:00 13:00 14:00 10 20 30

count Time spent unprompted on Task 5 (minutes)

More or less time than this Less More

70% used system when they didn’t have to.

15

slide-16
SLIDE 16

Engagement

0% 10% 20% 30% 40% 1 Agree 2 3 4 Neutral 5 6 7 Disagree

The system was fun to use Percentage choosing each option

How many technologies used Ten or fewer More than ten

16

slide-17
SLIDE 17

Ongoing

  • Gradual typing
  • Concatenative programming
  • Package management
  • Object inheritance

17

slide-18
SLIDE 18

Outlook

18

slide-19
SLIDE 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

slide-20
SLIDE 20

Michael Homer

slide-21
SLIDE 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

slide-22
SLIDE 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

slide-23
SLIDE 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

slide-24
SLIDE 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

slide-25
SLIDE 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

slide-26
SLIDE 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

slide-27
SLIDE 27

Prefixes

Methods are uniquely identified by their prefix of required parts.

Declaration Prefix 1

a(x) b(y) c(z)

a b c 2

a(x) b(y) ?c(z)

a b 3

a(x) ?b(y) c(z)

a 4

a(x) +b(y) c(z)

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

slide-28
SLIDE 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

slide-29
SLIDE 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

slide-30
SLIDE 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

slide-31
SLIDE 31

Control structures

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

31

slide-32
SLIDE 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

slide-33
SLIDE 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

slide-34
SLIDE 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

  • rderby s.gpa, s.age, s.id

select s.name 34

slide-35
SLIDE 35

selectProjection .do { p −> return data.select(p)

}

thenBys.do { ifPresent −> for (ifPresent) do { t −> data := data.thenBy(t)

} }

35

slide-36
SLIDE 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

slide-37
SLIDE 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

slide-38
SLIDE 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

slide-39
SLIDE 39

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.

39

slide-40
SLIDE 40

Extending the language

aDSL ModuleX

dialect "aDSL" ... ... use {x} on(arg) ...

dslhlpr aDSL

dialect "dslhlpr" ... method use(arg1)

  • n(arg2) {

...

}

40

slide-41
SLIDE 41

Restricting the language

41

slide-42
SLIDE 42

Pattern matching

match(node) case { v : VarDeclaration | TypeDeclaration

−> ... }

Destructuring:

case { w : WhileDo(condition, body)

−> if (condition == ...) then {

...

} }

Patterns as Objects in Grace. Homer et al. DLS’12.

42

slide-43
SLIDE 43

Building a type checker

rule { req : Request −> match(typeOf(req.in).getMethod(req.name)) case { : NoSuchMethod −> fail "no such method" } case { mt : MethodType −> for (mt.signature) and(req.with) do { s, w −> for (s.params) and(w.args) do { p, a −> if (!typeOf(a).isSubtypeOf(p.decType)) then { fail "argument does not satisfy parameter type" }

} }

return mt.returnType // Type of expression

} }

Brand Objects for Nominal Typing. Jones, Homer, and Noble. ECOOP’15.

43

slide-44
SLIDE 44

Contents

Title slide 1 Programming languages 2 Research focus 3 Enabling embedded domain-specific languages 4 Extending the language . . . . . . . . . . . . . . . . . . . 5 Restricting the language . . . . . . . . . . . . . . . . . . . 6 44

slide-45
SLIDE 45

Turtle graphics . . . . . . . . . . . . . . . . . . . . . . . . 7 Helping to write restrictive dialects . . . . . . . . . . . . . . 8 Enforcing nominal types . . . . . . . . . . . . . . . . . . . 9 GrAPL . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Combining tiled and textual programming 11 Tiled Grace . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Switching views . . . . . . . . . . . . . . . . . . . . . . . 13 Error reporting . . . . . . . . . . . . . . . . . . . . . . . . 14 Engagement . . . . . . . . . . . . . . . . . . . . . . . . . 15 Fun by experience . . . . . . . . . . . . . . . . . . . 16 45

slide-46
SLIDE 46

Ongoing 17 Outlook 18 References 19 Ending slide 21 Multi-part method names 22 46

slide-47
SLIDE 47

Variable Parts 22 Repeated parts . . . . . . . . . . . . . . . . . . . . . . . . 23 Parameter binding . . . . . . . . . . . . . . . . . . . . . . 24 Optional parts . . . . . . . . . . . . . . . . . . . . . . . . 25 Grouping parts . . . . . . . . . . . . . . . . . . . . . . . . 26 Alternations . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Calling methods 27 Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Greedy matching . . . . . . . . . . . . . . . . . . . . . . . 29 Uncallable methods . . . . . . . . . . . . . . . . . . . 30 47

slide-48
SLIDE 48

Examples 30 match . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Control structures . . . . . . . . . . . . . . . . . . . . . . 32 Testing DSL . . . . . . . . . . . . . . . . . . . . . . . . . 33 Creating a button . . . . . . . . . . . . . . . . . . . . . . . 34 Embedded DSL: Query language . . . . . . . . . . . . . . 35 Library initialisation . . . . . . . . . . . . . . . . . . . . . . 37 Greedy matching . . . . . . . . . . . . . . . . . . . . . . . 38 48

slide-49
SLIDE 49

Enabling embedded domain-specific languages 40 Extending the language . . . . . . . . . . . . . . . . . . . 41 Restricting the language . . . . . . . . . . . . . . . . . . . 42 Pattern matching . . . . . . . . . . . . . . . . . . . . 43 Building a type checker . . . . . . . . . . . . . . . . . . . . 44 Contents 45 49