September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,21 @@
// version 1.1.2
open class Animal(val name: String, var age: Int) {
open fun copy() = Animal(name, age)
override fun toString() = "Name: $name, Age: $age"
}
class Dog(name: String, age: Int, val breed: String) : Animal(name, age) {
override fun copy() = Dog(name, age, breed)
override fun toString() = super.toString() + ", Breed: $breed"
}
fun main(args: Array<String>) {
val a: Animal = Dog("Rover", 3, "Terrier")
val b: Animal = a.copy() // calls Dog.copy() because runtime type of 'a' is Dog
println("Dog 'a' = $a") // implicitly calls Dog.toString()
println("Dog 'b' = $b") // ditto
println("Dog 'a' is ${if (a === b) "" else "not"} the same object as Dog 'b'")
}

View file

@ -0,0 +1,12 @@
s = .s~new
s2 = s~copy -- makes a copy of the first
if s == s2 then say "copy didn't work!"
if s2~name == "S" then say "polymorphic copy worked"
::class t
::method name
return "T"
::class s subclass t
::method name
return "S"

View file

@ -0,0 +1,27 @@
enum NAME, METHOD
procedure me_t()
puts(1,"I is a T\n")
end procedure
constant r_t = routine_id("me_t")
procedure me_s()
puts(1,"I is an S\n")
end procedure
constant r_s = routine_id("me_s")
type T(object o)
-- as o[METHOD] can be overidden, don't verify it!
return sequence(o) and length(o)=2 and string(o[NAME]) and integer(o[METHOD])
end type
type S(T t)
return t[METHOD] = r_s
end type
S this = {"S",r_s}
T that = {"T",r_t}
call_proc(that[METHOD],{})
that = this
call_proc(that[METHOD],{})