June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
12
Task/Compound-data-type/Elena/compound-data-type.elena
Normal file
12
Task/Compound-data-type/Elena/compound-data-type.elena
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
struct Point
|
||||
{
|
||||
int prop x :: _x.
|
||||
|
||||
int prop y :: _y.
|
||||
|
||||
constructor new(IntNumber x, IntNumber y)
|
||||
[
|
||||
_x := x.
|
||||
_y := y.
|
||||
]
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
type Point{T<:Real}
|
||||
struct Point{T<:Real}
|
||||
x::T
|
||||
y::T
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
==(u::Point, v::Point) = (u.x == v.x) & (u.y == v.y)
|
||||
-(u::Point) = Point(-u.x, -u.y)
|
||||
+(u::Point, v::Point) = Point(u.x + v.x, u.y + v.y)
|
||||
-(u::Point, v::Point) = Point(u.x - v.x, u.y - v.y)
|
||||
Base.:(==)(u::Point, v::Point) = u.x == v.x && u.y == v.y
|
||||
Base.:-(u::Point) = Point(-u.x, -u.y)
|
||||
Base.:+(u::Point, v::Point) = Point(u.x + v.x, u.y + v.y)
|
||||
Base.:-(u::Point, v::Point) = u + (-v)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,8 @@
|
|||
a = Point(1, 2)
|
||||
b = Point(3, 7)
|
||||
c = Point(2, 4)
|
||||
|
||||
println("a = ", a)
|
||||
println("b = ", b)
|
||||
println("c = ", c)
|
||||
|
||||
println("a + b = ", a+b)
|
||||
println("-a + b = ", -a+b)
|
||||
println("a - b = ", a-b)
|
||||
println("a + b + c = ", a+b+c)
|
||||
println("a == c ", a == c)
|
||||
println("a + a == c ", a + a == c)
|
||||
a, b, c = Point(1, 2), Point(3, 7), Point(2, 4)
|
||||
@show a b c
|
||||
@show a + b
|
||||
@show -a + b
|
||||
@show a - b
|
||||
@show a + b + c
|
||||
@show a == b
|
||||
@show a + a == c
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
case class Point(x:Int=0, y:Int=0)
|
||||
case class Point(x: Int = 0, y: Int = 0)
|
||||
|
||||
val p=Point(1,2)
|
||||
val p = Point(1, 2)
|
||||
println(p.y) //=> 2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue