-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add examples to document features #305
Changes from all commits
59102b7
aac6cb1
7be1b10
0529d7b
17042b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,89 @@ | ||||||||||
import immutable/list | ||||||||||
|
||||||||||
interface DataBase[R] { | ||||||||||
//will save name to database | ||||||||||
def addEntry(entry: R): Unit | ||||||||||
|
||||||||||
//returns list of currently saved names | ||||||||||
def getEntries(): List[R] | ||||||||||
|
||||||||||
//prints all names to console | ||||||||||
def printEntries(): Unit | ||||||||||
} | ||||||||||
|
||||||||||
record Student( | ||||||||||
firstName: String, | ||||||||||
lastName: String, | ||||||||||
id: Int | ||||||||||
) | ||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
def myApplication(){ db: DataBase[Student] } = { | ||||||||||
var currentId = 0; | ||||||||||
def nextId():Int = { | ||||||||||
val c = currentId; | ||||||||||
currentId = currentId +1; | ||||||||||
return c; | ||||||||||
} | ||||||||||
def newStudent(firstName: String, lastName: String): Student = { | ||||||||||
Student(firstName, lastName, nextId()); | ||||||||||
} | ||||||||||
|
||||||||||
db.addEntry(newStudent("Max","Marschall")); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
db.addEntry(newStudent("Peter","Lustig")); | ||||||||||
db.addEntry(newStudent("Pierre","Drole")); | ||||||||||
db.addEntry(newStudent("Airan","Sayüt")); | ||||||||||
|
||||||||||
db.printEntries[Student]() | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the type annotation necessary? |
||||||||||
println("db current state:") | ||||||||||
println(db.getEntries[Student]()) | ||||||||||
} | ||||||||||
|
||||||||||
def makeNewDB(){ r: Region }:DataBase[Student] at { r } = { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
//create database instance | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
var names: List[Student] in r = []; | ||||||||||
def firebase = new DataBase[Student] { | ||||||||||
|
||||||||||
def addEntry(entry: Student) = { | ||||||||||
names = Cons[Student](entry, names) | ||||||||||
} | ||||||||||
|
||||||||||
def getEntries() = { | ||||||||||
return names; | ||||||||||
} | ||||||||||
|
||||||||||
def printEntries() = { | ||||||||||
names.foreach(){ name => println(name); ()} | ||||||||||
} | ||||||||||
}; | ||||||||||
return firebase | ||||||||||
} | ||||||||||
|
||||||||||
def main() = { | ||||||||||
|
||||||||||
//create database instance | ||||||||||
var names: List[Student] = []; | ||||||||||
var idCounter = 0; | ||||||||||
def firebase = new DataBase[Student] { | ||||||||||
|
||||||||||
def addEntry(entry: Student) = { | ||||||||||
names = Cons[Student](entry, names) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, is the type annotation necessary? |
||||||||||
} | ||||||||||
|
||||||||||
def getEntries() = { | ||||||||||
return names; | ||||||||||
} | ||||||||||
Comment on lines
+74
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
def printEntries() = { | ||||||||||
names.foreach(){ name => println(name); ()} | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
} | ||||||||||
}; | ||||||||||
|
||||||||||
region r { | ||||||||||
def fb2 = makeNewDB(){ r }; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Typically we omit empty value sections |
||||||||||
myApplication(){ fb2 } | ||||||||||
} | ||||||||||
|
||||||||||
//run application | ||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def main() = { | ||
var time = currentTimeNanos(); | ||
var timeMillis = time / 1000000; | ||
println("time millis: " ++ show(timeMillis)) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. printing the time in a "test" is difficult because you don't know what the expected result will be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why "name"?