-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevalord.cr
71 lines (58 loc) · 983 Bytes
/
evalord.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class NoisyTriple(TX, TY, TZ)
def initialize(x : TX, y : TY, z : TZ)
@x = x
@y = y
@z = z
end
def to_s(io)
io << "(#{@x}, #{@y}, #{@z})"
end
def x
puts "Reading x."
@x
end
def x=(value)
puts "Writing x."
@x = value
end
def y
puts "Reading y."
@y
end
def y=(value)
puts "Writing y."
@y = value
end
def z
puts "Reading z."
@z
end
def z=(value)
puts "Writing z."
@z = value
end
end
def passthrough(value)
puts "Passing through #{value}."
value
end
u = NoisyTriple(Int32, Int32, Int32).new(10, 20, 30)
puts "u starts as #{u}."
puts
puts "Assignments are evaluated from right to left:"
u.x = u.y = u.z = passthrough(50)
puts "Now u is #{u}."
puts
puts "Increasing..."
u.y += 1
u.z += u.x
puts "Now u is #{u}."
puts
puts "Rotating..."
u.x, u.y, u.z = u.y, u.z, u.x
puts "Now u is #{u}."
puts
a, b = [10], 20
puts "a = #{a}, b = #{b}"
b, a[b] = 0, 30
puts "a = #{a}, b = #{b}"