Added the []= overloadable operator and implemented it for vector, map, and string
This commit is contained in:
1
tests/test_bracket_assign.expected_results
Normal file
1
tests/test_bracket_assign.expected_results
Normal file
@@ -0,0 +1 @@
|
||||
bracket assign: index: 4, rhs: 9
|
||||
16
tests/test_bracket_assign.krak
Normal file
16
tests/test_bracket_assign.krak
Normal file
@@ -0,0 +1,16 @@
|
||||
import io:*
|
||||
|
||||
obj BracketAssign {
|
||||
fun operator[]=(index:int, rhs:int) {
|
||||
print("bracket assign: index: ")
|
||||
print(index)
|
||||
print(", rhs: ")
|
||||
println(rhs)
|
||||
}
|
||||
}
|
||||
|
||||
fun main():int {
|
||||
var test:BracketAssign
|
||||
test[4] = 9
|
||||
return 0
|
||||
}
|
||||
@@ -4,4 +4,5 @@
|
||||
3
|
||||
20
|
||||
2
|
||||
30
|
||||
4
|
||||
|
||||
@@ -10,9 +10,11 @@ fun main():int {
|
||||
println(m[3])
|
||||
m.set(3,4)
|
||||
m.set(4,20)
|
||||
m[6] = 30
|
||||
println(m[1])
|
||||
println(m[4])
|
||||
println(m[2])
|
||||
println(m[6])
|
||||
println(m[3])
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -6,3 +6,4 @@ hope
|
||||
hope3
|
||||
new way!
|
||||
a
|
||||
now win!
|
||||
|
||||
@@ -16,6 +16,10 @@ fun main(): int {
|
||||
var newWay = string::string("new way!")
|
||||
io::println(newWay)
|
||||
io::println(newWay[5])
|
||||
newWay.set(1, 'o')
|
||||
newWay[5] = 'i'
|
||||
newWay[6] = 'n'
|
||||
io::println(newWay)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,5 +25,10 @@ find test
|
||||
0
|
||||
1
|
||||
2
|
||||
set and []= test
|
||||
4
|
||||
8
|
||||
9
|
||||
7
|
||||
done
|
||||
Destroyed: 0
|
||||
|
||||
@@ -111,6 +111,13 @@ fun main(): int {
|
||||
println(multipleFindTest.find_index(2))
|
||||
println(multipleFindTest.find_index(3))
|
||||
|
||||
println("set and []= test")
|
||||
var setTest = vector(4,5,6)
|
||||
setTest.add(7)
|
||||
setTest.set(1,8)
|
||||
setTest[2] = 9
|
||||
setTest.do(fun(it: int) println(it);)
|
||||
|
||||
println("done")
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user