NCBOR 2014 | Efficiënt programmeren van beheer met Asset Management (1C)
Programmeren met Algebra
description
Transcript of Programmeren met Algebra
Programmeren met Algebra
André van Delft6 februari 2012
Presentatie op Grotius College Delft
CV• 1979-1985 Studie Wiskunde in Leiden• 1982-1985 Studie Bedrijfskunde in Delft/Rotterdam• 1985-1989 Promotieplaats Informatica in Leiden• 1989-2006 Software-ontwikkelaar op contractbasis• 2006-2012 Wetenschapper bij NATO/NC3A
• Onderzoek & Ontwikkeling van Programmeertalen– Parallelisme– Grootheden & Eenheden– Rare talen
Alan Kay
Programmeren moeilijk sinds 1995• Meerdere taken tegelijk: threading
– Hoofdtaak Main thread– Langdurige taken Background thread– Schermafhandeling GUI 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 = searchButtonshowSearchingText = @gui: {outputTA.text = "…"}showSearchResults = @gui: {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)*} || progressMonitorprogressMonitor = {*Thread.sleep( 250)*} @gui:{searchTF.text+=here.pass} ...
live = searchSequence... || exit
searchCommand = searchButton + Key.EntercancelCommand = cancelButton + Key.Escape
exitCommand = exitButton + windowClosing
exit = exitCommand @gui: while(!areYouSure)cancelSearch = cancelCommand @gui: showCanceledText
searchSequence = searchGuard searchCommand; showSearchingText searchInDatabase showSearchResults / cancelSearch
Process AlgebraWiskundige theorie over processenBergstra&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:
http://code.google.com/p/subscript/• www.rosettacode.org …
Hello Worldhttp://rosettacode.org/wiki/Hello_world/Text
C: #include <stdio.h>
int main(void){ printf(”Hello, World!\n”); return 0;}
HQ9+: H
C0H:
C1R: Hello_world/Text
100 Doors http://rosettacode.org/wiki/100_doors
C: #include <stdio.h>
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 - 2main = generator(2,1000000) ==> (..==>sieve) =={toPrint}==> printer
generator(s,e) = for(i<-s to e) <=i sieve = =>p:Int? @toPrint:<=p; ..=>i:Int? if (i%p!=0) <=i
printer = ..=>i:Int? println,i
<==>(i:Int) = {}