Examples fixed, some bugs found

This commit is contained in:
Andrey Breslav
2010-12-30 17:01:13 +03:00
parent df5bba0a00
commit f3f4a361d0
17 changed files with 57 additions and 48 deletions
+3 -2
View File
@@ -1,3 +1,5 @@
fun foo() {
addMouseListener(object MouseAdapter() {
private var clickCount = 0;
@@ -19,5 +21,4 @@ val GOD = object {
};
// Groovy like syntax: too many things to assume
addMouseListener([mouseClicked : {e => doFoo()}]);
}
+6 -6
View File
@@ -11,16 +11,16 @@ class BinaryTree<T> : IMutableSet<T> {
private var root : TreeNode
private var version = 0
override var size : Int { get; private set; }
// override var size : Int { get; private set; }
this(compare : Comparison<T>) {
this.compare = asMatchableComparison(comparison)
}
this() : this(naturalOrder<T>) {
this() : this(naturalOrder<T>()) {
}
private extension [operator] fun T.compareTo(other : T) : Int = compare(this, other)
private [operator] fun T.compareTo(other : T) : Int = compare(this, other)
override fun contains(item : T) : Boolean {
return contains(root, item)
@@ -129,7 +129,7 @@ class BinaryTree<T> : IMutableSet<T> {
override fun iterator() : IIterator<T> = mutableIterator()
override fun mutableIterator() : IMutableIterator<T> = new IMutableIterator() {
override fun mutableIterator() : IMutableIterator<T> = object IMutableIterator {
val version = BinaryTree.this.version
val down = Stack<TreeNode>()
val up = Stack<TreeNode>()
@@ -172,9 +172,9 @@ class BinaryTree<T> : IMutableSet<T> {
}
}
override val hasNext : Boolean {
override val hasNext : Boolean
get() = !down.isEmpty || !up.isEmpty
}
override fun remove() {
checkVersion()
+3 -3
View File
@@ -19,11 +19,11 @@ fun mostSignificantBit(x : INumber) = (x and oneBit(x.bits - 1) != 0) as Int
fun countOnes(x : INumber) = if (x == 0) 0 else mostSignificantBit(x) + countOnes(x shl 1)
extension fun Int.matchMask(mask : Int) = this and mask == mask
fun Int.matchMask(mask : Int) = this and mask == mask
interface class INumber<T : this> : IComparable<T> {
virtual class INumber<T : this> : IComparable<T> {
val bits : Int
[operator] fun plus(other : T) : T
[operator] fun shl(bits : Int) : T
...
// ...
}
+6 -6
View File
@@ -22,22 +22,22 @@ class AntBuilder {
abstract class ClassPathEntry {}
class Module : ClassPathEntry {
fun classpath(entries : ClassPathEntry...) { ... }
fun classpath(entries : ClassPathEntry/*...*/) { /*...*/ }
var targetLevel : String
fun src(src : String) { ... }
fun src(src : String) { /*...*/ }
}
class Library : ClassPathEntry {
fun classpath(entries : ClassPathEntry...) { ... }
fun classpath(entries : ClassPathEntry/*...*/) { /*...*/ }
}
fun library(initializer : Library.{ () : Library}) {
fun library(initializer : { Library.() : Library}) {
val lib = new Library()
lib.initializer()
return lib
}
fun classpath...
fun classpath(/*...*/)
fun module...
fun module(/*...*/)
}
+1 -1
View File
@@ -6,7 +6,7 @@ type f_tuple = {((T, E)) : X}
//type f_tuple = {((T, E)) => X}
type hof = { (X) : {(T) : Y} }
//type hof = { (X) => {(T) => Y} }
type hof2 = { {(X) : Y} : {(Y) : Z} }
type hof2 = { ({(X) : Y}) : {(Y) : Z} }
//type hof2 = { {(X) => Y} => {(Y) => Z} }
+2 -2
View File
@@ -1,6 +1,6 @@
sealed class Vertex<V>(val data : V)
class Vertex<V>(val data : V)
sealed class Edge<V, E>(val from : V, val data : E, val to : V)
class Edge<V, E>(val from : V, val data : E, val to : V)
class Graph<V, E> {
+1 -1
View File
@@ -1,4 +1,4 @@
interface class IPushPop<T> {
virtual class IPushPop<T> {
val isEmpty : Boolean
fun push(item : T)
fun pop() : T
+3 -2
View File
@@ -1,2 +1,3 @@
l filter {it.x} map {it.foo} aggregate {a, b => a + b}
fun foo() {
l filter {it.x} map {it.foo} aggregate {(a, b) => a + b}
}
+2 -2
View File
@@ -16,10 +16,10 @@ class List<T> {
}
extension Map<E> for T
extension Map<E, T>
where
T : Iterable<E>,
class object T : Buildable<E, T> {
class object T : Buildable<E, T> for T {
fun map<R>(f : {(E) : R}) : T<R> = {
val builder = T.newBuilder()
+3 -3
View File
@@ -1,4 +1,4 @@
sealed class Queue<T> : IPushPop<T> {
class Queue<T> : IPushPop<T> {
private class Item<T>(val data : T, var next : Item<T>)
private var head : Item<T> = null
@@ -26,8 +26,8 @@ sealed class Queue<T> : IPushPop<T> {
result
}
override val isEmpty {
override val isEmpty
get() = head == null
}
}
+3 -3
View File
@@ -1,4 +1,4 @@
sealed class Stack<T> : IPushPop<T> {
class Stack<T> : IPushPop<T> {
private val data = new ArrayList<T>();
override fun push(item : T) {
@@ -7,7 +7,7 @@ sealed class Stack<T> : IPushPop<T> {
override fun pop() = data.removeLast()
override val isEmpty { // TODO: This is UGLY :(
override val isEmpty
get() = data.isEmpty
}
}
+1 -2
View File
@@ -29,6 +29,5 @@ class UnionFind {
}
}
extension val Int.isOdd : Boolean {
val Int.isOdd : Boolean
get() = this % 2 != 0
}
+3 -3
View File
@@ -2,12 +2,12 @@
These declarations are "shallow" in the sense that they are not really compiled, only the type-checker uses them
*/
interface class ReadOnlyArray<out T> : ISized {
virtual class ReadOnlyArray<out T> : ISized {
[operator] fun get(index : Int) : T
}
interface class WriteOnlyArray<in T> : ISized { // This is needed to keep IIterator's <T> covariant
virtual class WriteOnlyArray<in T> : ISized { // This is needed to keep IIterator's <T> covariant
[operator] fun set(index : Int, value : T)
}
class MutableArray<T> : ReadOnlyArray<T>, WriteOnlyArray<T> {...}
class MutableArray<T> : ReadOnlyArray<T>, WriteOnlyArray<T> {/*...*/}
+7 -7
View File
@@ -5,7 +5,7 @@ class ArrayList<T> : IMutableList<T> {
override fun iterator() : IIterator<T> = mutableIterator()
override fun mutableIterator() : IMutableIterator<T> = new IMutableIterator() { // T is inferred
override fun mutableIterator() : IMutableIterator<T> = object IMutableIterator() { // T is inferred
private val index = 0
private var myVersion = version
@@ -21,9 +21,9 @@ class ArrayList<T> : IMutableList<T> {
data[index++]
}
override val hasNext {
override val hasNext
get() = index < used
}
override fun remove() {
checkVersion()
@@ -43,13 +43,13 @@ class ArrayList<T> : IMutableList<T> {
throw new IndexOutOfBoundsException(index)
}
override val isEmpty {
override val isEmpty
get() = used == 0
}
override val size {
override val size
get() = used
}
override fun set(index : Int, value : T) {
checkIndex(index)
+5 -5
View File
@@ -4,9 +4,9 @@ virtual class IEquality {
}
virtual class IHashable : IEquality {
val hashCode() : Integer {
val hashCode : Integer
get() = (this as java.lang.Object).hashCode()
}
}
virtual class IMap<K, V> {
@@ -16,7 +16,7 @@ virtual class IMap<K, V> {
fun containsKey(key : K) : Boolean
}
class HashableWrapper(wraps val obj : Any) : IHashable
class HashableWrapper wraps (val obj : Any) : IHashable
// equals and hashCode implementations are inherited
[inline] fun Any.hashable() : HashableWrapper = new HashableWrapper(this)
@@ -48,11 +48,11 @@ class HashMap<K, V> : IMap<K, V> {
class StrategyHashMap<K, V>(hashingStrategy : IHashingStrategy<K>) : IMap<K, V> {
this() where (K : IHashable) : this(new DefaultHashingStrategy<K>()) {}
// where !(K : IHashable)
// where !(K : IHashable)
this() : this(new JavaObjectHashingStrategy<K>()) {}
this() where (K : IHashable) : this(new DefaultHashingStrategy<K>()) {}
//...
}