This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,28 @@
abstract class X
{
Void method1 ()
{
echo ("Method 1 in X")
}
abstract Void method2 ()
}
class Y : X
{
// Y must override the abstract method in X
override Void method2 ()
{
echo ("Method 2 in Y")
}
}
class Main
{
public static Void main ()
{
y := Y()
y.method1
y.method2
}
}

View file

@ -0,0 +1,4 @@
class AbstractStack()
def .valid?(object) nil
tag AbstractStack some-object # always fails

View file

@ -0,0 +1,8 @@
class StackInterface()
def .valid?(object)
object
and
bound? .enstack
is-instance? .enstack Closure
bound? .destack
is-instance? .destack Closure

View file

@ -0,0 +1,9 @@
class XYZstack(Object)
def .init()
var .items ()
def .enstack(object)
setq .items (cons object .items)
def .destack()
var tmp (car .items)
setq .items (cdr .items)
tmp

View file

@ -0,0 +1 @@
tag StackInterface (XYZstack(.new))

View file

@ -0,0 +1,5 @@
public interface Interface {
int method1(double value)
int method2(String name)
int add(int a, int b)
}

View file

@ -0,0 +1,5 @@
public abstract class Abstract1 {
abstract public int methodA(Date value)
abstract protected int methodB(String name)
int add(int a, int b) { a + b }
}

View file

@ -0,0 +1,3 @@
public abstract class Abstract2 implements Interface {
int add(int a, int b) { a + b }
}

View file

@ -0,0 +1,15 @@
public class Concrete1 implements Interface {
public int method1(double value) { value as int }
public int method2(String name) { (! name) ? 0 : name.toList().collect { it as char }.sum() }
public int add(int a, int b) { a + b }
}
public class Concrete2 extends Abstract1 {
public int methodA(Date value) { value.toCalendar()[Calendar.DAY_OF_YEAR] }
protected int methodB(String name) { (! name) ? 0 : name.toList().collect { it as char }.sum() }
}
public class Concrete3 extends Abstract2 {
public int method1(double value) { value as int }
public int method2(String name) { (! name) ? 0 : name.toList().collect { it as char }.sum() }
}

View file

@ -0,0 +1,12 @@
def c1 = new Concrete1()
assert c1 instanceof Interface
println (new Concrete1().method2("Superman"))
def c2 = new Concrete2()
assert c2 instanceof Abstract1
println (new Concrete2().methodB("Spiderman"))
def c3 = new Concrete3()
assert c3 instanceof Interface
assert c3 instanceof Abstract2
println (new Concrete3().method2("Hellboy"))

View file

@ -0,0 +1,2 @@
abstract «name»
abstract «name» <: «supertype»

View file

@ -0,0 +1,9 @@
:- protocol(datep).
:- public(today/3).
:- public(leap_year/1).
:- public(name_of_day/3).
:- public(name_of_month/3).
:- public(days_in_month/3).
:- end_protocol.