2016-04-30 15:38:28 -04:00
|
|
|
import io:*
|
2015-07-14 19:32:54 -04:00
|
|
|
|
2015-07-14 22:42:25 -04:00
|
|
|
obj test_cons(Object) {
|
|
|
|
|
fun construct(): *test_cons {
|
|
|
|
|
println("construct")
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(other: *test_cons) {
|
|
|
|
|
println("copy_construct")
|
|
|
|
|
}
|
|
|
|
|
fun destruct() {
|
|
|
|
|
println("destruct")
|
|
|
|
|
}
|
|
|
|
|
fun operator=(other: test_cons) {
|
|
|
|
|
println("=")
|
|
|
|
|
}
|
|
|
|
|
fun do() {
|
|
|
|
|
println("do")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun call<T>(it: ref T) {
|
|
|
|
|
it.do()
|
|
|
|
|
}
|
2015-07-14 19:32:54 -04:00
|
|
|
|
2015-07-14 22:42:25 -04:00
|
|
|
fun byRef<T>(it: ref T) {
|
|
|
|
|
it = it + 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun byRef(it: * int) {
|
|
|
|
|
*it = *it + 1
|
|
|
|
|
}
|
2015-07-14 19:32:54 -04:00
|
|
|
|
|
|
|
|
fun byRef(it: ref int) {
|
|
|
|
|
it = it + 1
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-15 00:53:53 -04:00
|
|
|
fun id(it: ref int): ref int {
|
|
|
|
|
return it
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun id<T>(it: ref T): ref T {
|
|
|
|
|
return it
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 19:32:54 -04:00
|
|
|
// what about cosures closing over references?
|
|
|
|
|
|
|
|
|
|
fun main():int {
|
|
|
|
|
var a = 6
|
|
|
|
|
byRef(a)
|
|
|
|
|
println(a)
|
2015-07-14 22:42:25 -04:00
|
|
|
byRef(&a)
|
|
|
|
|
println(a)
|
2015-07-15 00:53:53 -04:00
|
|
|
id(a) = 14
|
|
|
|
|
println(a)
|
2015-07-14 22:42:25 -04:00
|
|
|
var b = 6.7
|
|
|
|
|
byRef(b)
|
|
|
|
|
println(b)
|
|
|
|
|
|
|
|
|
|
var t.construct() : test_cons
|
|
|
|
|
call(t)
|
2015-07-15 00:53:53 -04:00
|
|
|
id(t).do()
|
2015-07-15 13:56:57 -04:00
|
|
|
|
|
|
|
|
var do_copy = id(t)
|
|
|
|
|
do_copy.do()
|
2015-07-14 19:32:54 -04:00
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|