tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
23
Task/Polymorphism/E/polymorphism-1.e
Normal file
23
Task/Polymorphism/E/polymorphism-1.e
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
def makePoint(x, y) {
|
||||
def point implements pbc {
|
||||
to __printOn(out) { out.print(`<point $x,$y>`) }
|
||||
to __optUncall() { return [makePoint, "run", [x, y]] }
|
||||
to x() { return x }
|
||||
to y() { return y }
|
||||
to withX(new) { return makePoint(new, y) }
|
||||
to withY(new) { return makePoint(x, new) }
|
||||
}
|
||||
return point
|
||||
}
|
||||
|
||||
def makeCircle(x, y, r) {
|
||||
def circle extends makePoint(x, y) implements pbc {
|
||||
to __printOn(out) { out.print(`<circle $x,$y r $r>`) }
|
||||
to __optUncall() { return [makeCircle, "run", [x, y, r]] }
|
||||
to r() { return r }
|
||||
to withX(new) { return makeCircle(new, y, r) }
|
||||
to withY(new) { return makeCircle(x, new, r) }
|
||||
to withR(new) { return makeCircle(x, y, new) }
|
||||
}
|
||||
return circle
|
||||
}
|
||||
4
Task/Polymorphism/E/polymorphism-2.e
Normal file
4
Task/Polymorphism/E/polymorphism-2.e
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
def p := makePoint(0.5, 0.5)
|
||||
def c := makeCircle(1, 1, 2)
|
||||
println(p)
|
||||
println(c)
|
||||
Loading…
Add table
Add a link
Reference in a new issue