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

@ -1,7 +1,7 @@
public abstract class Abs {
abstract public int method1(double value);
abstract protected int method2(String name);
int add(int a, int b){
return a+b;
}
public abstract int method1(double value);
protected abstract int method2(String name);
int add(int a, int b) {
return a + b;
}
}

View file

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

View file

@ -0,0 +1,55 @@
// version 1.1
interface Announcer {
fun announceType()
// interface can contain non-abstract members but cannot store state
fun announceName() {
println("I don't have a name")
}
}
abstract class Animal: Announcer {
abstract fun makeNoise()
// abstract class can contain non-abstract members
override fun announceType() {
println("I am an Animal")
}
}
class Dog(private val name: String) : Animal() {
override fun makeNoise() {
println("Woof!")
}
override fun announceName() {
println("I'm called $name")
}
}
class Cat: Animal() {
override fun makeNoise() {
println("Meow!")
}
override fun announceType() {
println("I am a Cat")
}
}
fun main(args: Array<String>) {
val d = Dog("Fido")
with(d) {
makeNoise()
announceType() // inherits Animal's implementation
announceName()
}
println()
val c = Cat()
with(c) {
makeNoise()
announceType()
announceName() // inherits Announcer's implementation
}
}

View file

@ -0,0 +1,3 @@
classdef (Abstract) AbsClass
...
end

View file

@ -0,0 +1,3 @@
methods (Abstract)
abstMethod(obj)
end

View file

@ -0,0 +1,3 @@
properties (Abstract)
AbsProp
end

View file

@ -1,9 +1,12 @@
type
Comparable = generic x, y
Comparable = concept x, y
(x < y) is bool
Container[T] = generic c
c.len is ordinal
items(c) is iterator
for value in c:
type(value) is T
Stack[T] = concept s, var v
s.pop() is T
v.push(T)
s.len is Ordinal
for value in s:
value is T

View file

@ -0,0 +1,60 @@
-- Example showing a class that defines an interface in ooRexx
-- shape is the interface class that defines the methods a shape instance
-- is expected to implement as abstract methods. Instances of the shape
-- class need not directly subclass the interface, but can use multiple
-- inheritance to mark itself as implementing the interface.
r=.rectangle~new(5,2)
say r
-- check for instance of
if r~isa(.shape) then say "a" r~name "is a shape"
say "r~area:" r~area
say
c=.circle~new(2)
say c
-- check for instance of shape works even if inherited
if c~isa(.shape) then say "a" c~name "is a shape"
say "c~area:" c~area
say
-- a mixin is still a class and can be instantiated. The abstract methods
-- will give an error if invoked
g=.shape~new
say g
say g~name
say "g~area:" g~area -- invoking abstract method results in a runtime error.
-- the "MIXINCLASS" tag makes this avaiable for multiple inhertance
::class shape MIXINCLASS Object
::method area abstract
::method name abstract
-- directly subclassing the the interface
::class rectangle subclass shape
::method init
expose length width
use strict arg length=0, width=0
::method area
expose length width
return length*width
::method name
return "Rectangle"
-- inherits the shape methods
::class circle subclass object inherit shape
::method init
expose radius
use strict arg radius=0
::method area
expose radius
numeric digits 20
return radius*radius*3.14159265358979323846
::method name
return "Circle"

View file

@ -0,0 +1,51 @@
-- Example showing an abstract type in ooRexx
-- shape is the abstract class that defines the abstract method area
-- which is then implemented by its two subclasses, rectangle and circle
-- name is the method inherited by the subclasses.
-- author: Rony G. Flatscher, 2012-05-26
-- changed/edited: Walter Pachl, 2012-05-28 28
-- highlighting: to come
r=.rectangle~new(5,2)
say r
say r~name
say "r~area:" r~area
say
c=.circle~new(2)
say c
say c~name
say "c~area:" c~area
say
g=.shape~new
say g
say g~name
say "g~area:" g~area -- invoking abstract method results in a runtime error.
::class shape
::method area abstract
::method name
return "self~class~id:" self~class~id
::class rectangle subclass shape
::method init
expose length width
use strict arg length=0, width=0
::method area
expose length width
return length*width
::class circle subclass shape
::method init
expose radius
use strict arg radius=0
::method area
expose radius
numeric digits 20
return radius*radius*3.14159265358979323846

View file

@ -0,0 +1,9 @@
! ABSTRACT HASH KEY TYPE ;
LISTVAL CLASS HASHKEY;
VIRTUAL:
PROCEDURE HASH IS
INTEGER PROCEDURE HASH;;
PROCEDURE EQUALTO IS
BOOLEAN PROCEDURE EQUALTO(K); REF(HASHKEY) K;;
BEGIN
END HASHKEY;

View file

@ -0,0 +1,20 @@
! COMMON HASH KEY TYPE IS TEXT ;
HASHKEY CLASS TEXTHASHKEY(T); VALUE T; TEXT T;
BEGIN
INTEGER PROCEDURE HASH;
BEGIN
INTEGER I;
T.SETPOS(1);
WHILE T.MORE DO
I := 31*I+RANK(T.GETCHAR);
IF DEBUG THEN BEGIN
OUTIMAGE;
OUTTEXT("HASHMAPS.TEXTHASHKEY.HASH=");
OUTINT(I,0);
OUTIMAGE;
END;
HASH := I;
END HASH;
BOOLEAN PROCEDURE EQUALTO(K); REF(HASHKEY) K;
EQUALTO := T = K QUA TEXTHASHKEY.T;
END TEXTHASHKEY;

View file

@ -0,0 +1,21 @@
class Stream{ // Mostly virtural base class
var [proxy protected]
isBroken = fcn { _broken.isSet() },
isClosed = fcn { return(_closed.isSet() or _broken.isSet()); };
fcn init{
var [protected]
_closed = Atomic.Bool(True),
_broken = Atomic.Bool(False),
whyBroken = Void;
}
fcn clear { _closed.clear(); _broken.clear(); return(self.topdog); }
fcn open { return(topdog.init(vm.pasteArgs())); }
fcn toStream { return(self); }
fcn close { _closed.set(); return(self.topdog); }
fcn flush { return(self.topdog); }
fcn read { throw(Exception.TheEnd); } // destructive or advance
fcn readln { throw(Exception.TheEnd); }
fcn write(x) { return(self.topdog); }
fcn writeln(x) { return(self.topdog); }
fcn walker { return((0).walker(*,wap((self.topdog.read.fpM(""))))); }
}

View file

@ -0,0 +1,5 @@
class DevNull(Stream){
var [const] fileName = "DevNull"; // compatibility with File
fcn init { Stream.init() }
fcn write(x) { return(0); }
}