Programmeren met Algebra André van Delft 6 februari 2012 Presentatie op Grotius College Delft
CV Studie Wiskunde in Leiden Studie Bedrijfskunde in Delft/Rotterdam Promotieplaats Informatica in Leiden Software-ontwikkelaar op contractbasis Wetenschapper bij NATO/NC3A Onderzoek & Ontwikkeling van Programmeertalen – Parallelisme – Grootheden & Eenheden – Rare talen
Alan Kay
Programmeren moeilijk sinds 1995 Meerdere taken tegelijk:threading – HoofdtaakMain thread – Langdurige takenBackground thread – SchermafhandelingGUI thread Gebeurtenissen (event handling) & communicatie – Toetsenbord, muis, touch screen – GPS, sensoren – Internet, Bluetooth Programmeertalen: C C++ Java, C# Scala Geen oplossing…
GUI-applicatie - 1 Invoerveld Zoekknop Zoeken… Resultaten
GUI-applicatie - 2 val searchButton = new Button("Go”) { reactions.+= { case ButtonClicked(b) => enabled = false outputTA.text = "Starting search...” new Thread(new Runnable { def run() { Thread.sleep(3000) SwingUtilities.invokeLater(new Runnable{ def run() {outputTA.text="Search ready” enabled = true }}) }}).start }
GUI-applicatie - 3 live = searchSequence... searchSequence = searchCommand showSearchingText searchInDatabase showSearchResults searchCommand = searchButton showSearchingText {outputTA.text = "…"} showSearchResults {outputTA.text = "…"} searchInDatabase = {* Thread.sleep(3000) *}
GUI-applicatie - 4 Zoeken:knop of Enter-toets Afbreken:knop of Escape-toets Exit:knop of ; daarna: “Are you sure?”… Alleen zoeken als tekstveld gevuld is Voortgang tonen
GUI-applicatie - 5 searchGuard = if(!searchTF.text.isEmpty). anyEvent(comp)... searchInDatabase = {*Thread.sleep(3000)*} || progressMonitor progressMonitor = {*Thread.sleep( live = searchSequence... || exit searchCommand = searchButton + Key.Enter cancelCommand = cancelButton + Key.Escape exitCommand = exitButton + windowClosing exit = while(!areYouSure) cancelSearch = showCanceledText searchSequence = searchGuard searchCommand; showSearchingText searchInDatabase showSearchResults / cancelSearch
Process Algebra Wiskundige theorie over processen Bergstra&Klop, Amsterdam, 1982 x y = x y + y x + x|y x+y = y+x (x+y)+z = x+(y+z) x+x = x (x+y)·z = x·z+y·z (x·y)·z = x·(y·z) O+x = x O·x = O 1·x = x x·1 = x δ+x = x δ·x = δ ε·x = x x·ε = x (x+ε)·y = x·y + ε·y = x·y + y
Werking: Templates & Call Graphs {Hello}+ε; {World} (x+ε)·y = x·y + ε·y = x·y + y
Slot Eenvoudig en efficiënt Nu 2000 regels Scala Nog veel te doen en te ontdekken Open Source: …
Hello World C: #include int main(void) { printf(”Hello, World!\n”); return 0; } HQ9+: H C0H: C1R: Hello_world/Text
100 Doors C: #include int main() { int door, square, increment; for (door = 1, square = 1, increment = 1; door <= 100; door++ == square && (square += increment += 2)) printf("door #%d is %s.\n", door, (door == square? "open" : "closed")); return 0; } C1R: 100_doors Stupid This means that nearly every C1R "solution" in Rosetta is simply a heading, followed by string which gives the path name to the C solution. This is a form of redundancy that is effectively spam. David St. Hubbins: It's such a fine line between stupid, and uh... Nigel Tufnel: Clever. David St. Hubbins: Yeah, and clever.
Zeef van Eratosthenes - 1
Zeef van Eratosthenes - 2 main = generator(2, ) ==> (..==>sieve) =={toPrint}==> printer generator(s,e) = for(i<-s to e) <=i sieve = if (i%p!=0) <=i printer =..=>i:Int? println,i (i:Int) = {}