Add all the A tasks
This commit is contained in:
parent
2dd7375f96
commit
051504d65b
1608 changed files with 18584 additions and 0 deletions
38
Task/Abstract-type/Argile/abstract-type.argile
Normal file
38
Task/Abstract-type/Argile/abstract-type.argile
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use std
|
||||
|
||||
(: abstract class :)
|
||||
|
||||
class Abs
|
||||
text name
|
||||
AbsIface iface
|
||||
|
||||
class AbsIface
|
||||
function(Abs)(int)->int method
|
||||
|
||||
let Abs_Iface = Cdata AbsIface@ {.method = nil}
|
||||
|
||||
.: new Abs :. -> Abs {let a = new(Abs); a.iface = Abs_Iface; a}
|
||||
|
||||
=: <Abs self>.method <int i> := -> int
|
||||
(self.iface.method is nil) ? 0 , (call self.iface.method with self i)
|
||||
|
||||
(: implementation :)
|
||||
|
||||
class Sub <- Abs { int value }
|
||||
|
||||
let Sub_Iface = Cdata AbsIface@ {.method = (code of (nil the Sub).method 0)}
|
||||
|
||||
.: new Sub (<int value = -1>) :. -> Sub
|
||||
let s = new (Sub)
|
||||
s.iface = Sub_Iface
|
||||
s.value = value
|
||||
s
|
||||
|
||||
.: <Sub this>.method <int i> :. -> int {this.value + i}
|
||||
|
||||
(: example use :)
|
||||
|
||||
.:foobar<Abs a>:. {print a.method 12 ; del a}
|
||||
foobar (new Sub 34) (: prints 46 :)
|
||||
foobar (new Sub) (: prints 11 :)
|
||||
foobar (new Abs) (: prints 0 :)
|
||||
Loading…
Add table
Add a link
Reference in a new issue