diff --git a/examples/src/Color.jetl b/examples/src/Color.jetl index 2c2c4278ff1..c4642656639 100644 --- a/examples/src/Color.jetl +++ b/examples/src/Color.jetl @@ -1,4 +1,4 @@ -enum class Color(val r, g, b : Int) { +enum class Color(val r : Int , val g :Int , val b : Int) { RED : Color(255, 0, 0) GREEN : Color(0, 255, 0) BLUE : Color(0, 0, 255) diff --git a/examples/src/Factories.jetl b/examples/src/Factories.jetl index fa8d464897e..53d4b78ca33 100644 --- a/examples/src/Factories.jetl +++ b/examples/src/Factories.jetl @@ -3,10 +3,10 @@ class Foo(bar : Bar) { private val cache = HashMap() // Factory method: - Foo() = Foo(null); + fun Foo() = Foo(null); // Factory method: - Foo(bar : Bar) = cache.cachedLookup(bar, this(bar)) + fun Foo(bar : Bar) = cache.cachedLookup(bar, this(bar)) } fun doFoo() { @@ -16,7 +16,7 @@ class Foo(bar : Bar) { // To create an object of Foo val foo = Foo() -or +// or val foo = Foo(Bar()) // Subclass (Foo must be marked as extendable/open, i.e. ont sealed) @@ -24,7 +24,7 @@ class FooSub(S : String) : Foo() { // Delegates to Foo created as a result of th } -extension Map.cachedLookup(key : K, lazy value : V) : V { +fun Map.cachedLookup(key : K, lazy value : V) : V { var v = this[key] if (v == null) { v = value diff --git a/examples/src/collections/IIterable.jetl b/examples/src/collections/IIterable.jetl index 2ef19c0caed..5e69296338c 100644 --- a/examples/src/collections/IIterable.jetl +++ b/examples/src/collections/IIterable.jetl @@ -1,3 +1,3 @@ -interface class IIterable { +virtual class IIterable { fun iterator() : IIterator } diff --git a/examples/src/collections/IIterator.jetl b/examples/src/collections/IIterator.jetl index 2ec8bc66cae..faeb4d40a5c 100644 --- a/examples/src/collections/IIterator.jetl +++ b/examples/src/collections/IIterator.jetl @@ -1,4 +1,4 @@ -interface class IIterator { +virtual class IIterator { fun next() : T val hasNext : Boolean @@ -14,7 +14,7 @@ interface class IIterator { if (len == 0) return 0 var count = 0; - for (i in [from .. from + length - 1]) { + for (i in from .. from + length - 1) { if (!hasNext) return count buffer[i] = next() diff --git a/examples/src/collections/IList.jetl b/examples/src/collections/IList.jetl index 70f1e2cfb2e..6daa67bac0f 100644 --- a/examples/src/collections/IList.jetl +++ b/examples/src/collections/IList.jetl @@ -1,4 +1,4 @@ -interface class IList : IIterable, ISized { +virtual class IList : IIterable, ISized { [operator] fun get(index : Int) : T val isEmpty : Boolean } \ No newline at end of file diff --git a/examples/src/collections/IMutableIterable.jetl b/examples/src/collections/IMutableIterable.jetl index a60bf71c95c..22b6e017d8e 100644 --- a/examples/src/collections/IMutableIterable.jetl +++ b/examples/src/collections/IMutableIterable.jetl @@ -1,3 +1,3 @@ -interface class IMutableIterable : IIterable { +virtual class IMutableIterable : IIterable { fun mutableIterator() : IMutableIterator } \ No newline at end of file diff --git a/examples/src/collections/IMutableIterator.jetl b/examples/src/collections/IMutableIterator.jetl index 775980ccedc..51111049926 100644 --- a/examples/src/collections/IMutableIterator.jetl +++ b/examples/src/collections/IMutableIterator.jetl @@ -1,4 +1,4 @@ -interface class IMutableIterator : IIterator { +virtual class IMutableIterator : IIterator { fun remove() : T /* diff --git a/examples/src/collections/IMutableList.jetl b/examples/src/collections/IMutableList.jetl index 2b308d8ca86..711f0d6bfc7 100644 --- a/examples/src/collections/IMutableList.jetl +++ b/examples/src/collections/IMutableList.jetl @@ -1,4 +1,4 @@ -interface class IMutableList : IList, IMutableIterable { +virtual class IMutableList : IList, IMutableIterable { fun set(index : Int, value : T) : T fun add(index : Int, value : T) fun remove(index : Int) : T diff --git a/examples/src/collections/IMutableSet.jetl b/examples/src/collections/IMutableSet.jetl index aa4edbee412..eacb0d740ec 100644 --- a/examples/src/collections/IMutableSet.jetl +++ b/examples/src/collections/IMutableSet.jetl @@ -1,4 +1,4 @@ -interface class IMutableSet : ISet, IMutableIterable { +virtual class IMutableSet : ISet, IMutableIterable { fun add(item : T) : Boolean fun remove(item : T) : Boolean } \ No newline at end of file diff --git a/examples/src/collections/ISet.jetl b/examples/src/collections/ISet.jetl index 8c32364dcf9..bfe2753b8df 100644 --- a/examples/src/collections/ISet.jetl +++ b/examples/src/collections/ISet.jetl @@ -1,3 +1,3 @@ -interface class ISet : IIterable, ISized { +virtual class ISet : IIterable, ISized { fun contains(item : T) : Boolean } diff --git a/examples/src/collections/ISized.jetl b/examples/src/collections/ISized.jetl index 0b724f702d5..9f12cb218b0 100644 --- a/examples/src/collections/ISized.jetl +++ b/examples/src/collections/ISized.jetl @@ -1,3 +1,3 @@ -interface class ISized { +virtual class ISized { val size : Int } \ No newline at end of file diff --git a/examples/src/collections/LinkedList.jetl b/examples/src/collections/LinkedList.jetl index 43be0302cea..d1901a24fea 100644 --- a/examples/src/collections/LinkedList.jetl +++ b/examples/src/collections/LinkedList.jetl @@ -6,7 +6,7 @@ class LinkedList : IMutableList { private var head : Item = null private var tail : Item = null - override var size { get; private set; } + override var size get private set; override fun add(index : Int, value : T) { size++ @@ -29,7 +29,7 @@ class LinkedList : IMutableList { } private fun checkIndex(index : Int) { - if (!index in [0..size-1]) { + if (index !in 0..size-1) { throw IndexOutOfBoundsException(index) } } @@ -63,7 +63,7 @@ class LinkedList : IMutableList { private fun itemAt(index : Int) { var result = head - for (i in [1..index]) { + for (i in 1..index) { result = result.next } return result diff --git a/examples/src/collections/List.jetl b/examples/src/collections/List.jetl index 14cd75594d3..e7bee51ca45 100644 --- a/examples/src/collections/List.jetl +++ b/examples/src/collections/List.jetl @@ -3,13 +3,11 @@ enum class List(theSize : Int) : IList { Cons(val value : T, val tail : List) : List(1 + tail.size) - override val size : Int { + override val size : Int get() = theSize - } - override val isEmpty : Boolean { + override val isEmpty : Boolean get() = this == Nil - } override fun iterator() = new IIterator() { private var current = List.this diff --git a/examples/src/io/IOSamples.jetl b/examples/src/io/IOSamples.jetl index 8f0b10ce79f..c51b03a643f 100644 --- a/examples/src/io/IOSamples.jetl +++ b/examples/src/io/IOSamples.jetl @@ -1,8 +1,8 @@ -interface class IAdder { +virtual class IAdder { fun add(item : T) : Boolean } -interface class ICloseable { +virtual class ICloseable { fun close() } @@ -24,20 +24,19 @@ class FileInput : IIterator, JavaCloseableWrapper { override fun next() { if (!nextUsed) { nextUsed = true - return next.as + return next as Byte } return } - - override val hasNext { + + override val hasNext get() { // implicitly throws IOException if (nextUsed && next != -1) { nextUsed = false next = stream.read() // throws IOException } - return next != -1 + return next != -1 } - } } class FileOutput throws IOException : IAdder, JavaCloseableWrapper { diff --git a/examples/src/map/IMap.jetl b/examples/src/map/IMap.jetl index 4f91bd5e996..0b912bb838d 100644 --- a/examples/src/map/IMap.jetl +++ b/examples/src/map/IMap.jetl @@ -1,4 +1,4 @@ -interface class IMap { +virtual class IMap { } \ No newline at end of file diff --git a/examples/src/priorityqueues/BinaryHeap.jetl b/examples/src/priorityqueues/BinaryHeap.jetl index 21188988a2e..1b46d2af79b 100644 --- a/examples/src/priorityqueues/BinaryHeap.jetl +++ b/examples/src/priorityqueues/BinaryHeap.jetl @@ -95,12 +95,11 @@ class BinaryHeap : IPriorityQueue { } -extension fun IMutableList.swap(a : Int, b : Int) { +fun IMutableList.swap(a : Int, b : Int) { val t = this[a] this[a] = this[b] this[b] = t } -extension val IList.lastIndex : Int +val IList.lastIndex : Int get() = this.size - 1 - diff --git a/examples/src/priorityqueues/IPriorityQueue.jetl b/examples/src/priorityqueues/IPriorityQueue.jetl index 01e5f357eaf..b343cd49cc3 100644 --- a/examples/src/priorityqueues/IPriorityQueue.jetl +++ b/examples/src/priorityqueues/IPriorityQueue.jetl @@ -1,4 +1,4 @@ -interface class IPriorityQueue { +virtual class IPriorityQueue { fun extract() : T fun add(item : T) val isEmpty : Boolean diff --git a/examples/src/priorityqueues/PriorityQueueAsPushPop.jetl b/examples/src/priorityqueues/PriorityQueueAsPushPop.jetl index 0bbc006f7e1..2502a91b39f 100644 --- a/examples/src/priorityqueues/PriorityQueueAsPushPop.jetl +++ b/examples/src/priorityqueues/PriorityQueueAsPushPop.jetl @@ -1,7 +1,6 @@ class PriorityQueueAsPushPop wraps(wrapped : IPriorityQueue) : IPushPop { override fun pop() = wrapped.extract() override fun push(item : T) = wrapped.add(item) - override val isEmpty { + override val isEmpty get() = wrapped.isEmpty - } } \ No newline at end of file diff --git a/examples/src/util/Comparison.jetl b/examples/src/util/Comparison.jetl index 1af0c99ff2e..cd8935ff025 100644 --- a/examples/src/util/Comparison.jetl +++ b/examples/src/util/Comparison.jetl @@ -2,15 +2,15 @@ type Comparison = {(T, T) : Int} fun naturalOrder>(a : T, b : T) : Int = a.compareTo(b) -fun castingNaturalOrder(a : Object, b : Object) : Int = a.as>.compareTo(b.as>) +fun castingNaturalOrder(a : Object, b : Object) : Int = (a as Comparable).compareTo(b as Comparable) enum class ComparisonResult { - LS,EQ, GR + LS, EQ, GR } type MatchableComparison = {(T, T) : ComparisonResult} -fun asMatchableComparison(cmp : Comparison) : MatchableComparison = {a, b => +fun asMatchableComparison(cmp : Comparison) : MatchableComparison = {(a, b) => val res = cmp(a, b) if (res == 0) return ComparisonResult.EQ if (res < 0) return ComparisonResult.LS diff --git a/examples/src/util/IComparable.jetl b/examples/src/util/IComparable.jetl index 79d19a364e6..b802c381464 100644 --- a/examples/src/util/IComparable.jetl +++ b/examples/src/util/IComparable.jetl @@ -1,3 +1,3 @@ -interface class IComparable { +virtual class IComparable { fun compareTo(other : T) : Int } \ No newline at end of file