The release notes for 0.9.9 claim that one can slice
lists. However, there seems to be no get method in the
library to actually support this.
Example:
package slicing;
void main (String[] args) {
let array = [0, 1, 2, 3, 4, 5];
let slice = array[2..4];
for (e: slice)
println(e);
}
This results in:
~/programming/nice/slicing/slicing.nice: line 5, column 20:
No possible call for get.
Arguments: (t66[], nice.lang.Range<nice.lang.int>)
Possibilities:
nice.lang.boolean get(nice.lang.long x,nice.lang.int bit)
nice.lang.double get(nice.lang.double[],nice.lang.int)
nice.lang.float get(nice.lang.float[],nice.lang.int)
nice.lang.char get(nice.lang.char[],nice.lang.int)
nice.lang.long get(nice.lang.long[],nice.lang.int)
nice.lang.int get(nice.lang.int[],nice.lang.int)
nice.lang.short get(nice.lang.short[],nice.lang.int)
nice.lang.byte get(nice.lang.byte[],nice.lang.int)
nice.lang.boolean get(nice.lang.boolean[],nice.lang.int)
<T> T get(T[],nice.lang.int)
Object get(nice.lang.Dictionary<?, ?>, ?Object)
nice.lang.char get(java.lang.String s,nice.lang.int index)
<K, K0, V0, V | K <: K0, V <: ?V0> ?V0
get(nice.lang.Map<K, V>,K0)
<T> T get(nice.lang.List<T>,nice.lang.int)
<T, V> V get(java.lang.reflect.Field,T)
compilation failed with 1 error
Daniel Dawson
Email: ddawson at icehouse dot net
Logged In: YES
user_id=929365
If you include nice.functional, you get the methods. However
then you also get this error:
Ambiguity for symbol get. Possibilities are :
<T> nice.lang.List<T> get(nice.lang.List<T>
list,nice.lang.Slice<nice.lang.int> slice)
<T> nice.lang.List<T> get(nice.lang.List<T>
list,nice.lang.Slice<nice.lang.int> slice)
so its still broken.
Logged In: YES
user_id=929365
Ah, the problem is that the `..` operator can return either
a Slice<int> or a Range<int>. Range<int> extends Slice<int>
and implements List<int>, which means that the list[1..2]
could be a list[Range] which could call either
get(List,Slice) or get(List, List), leading to the ambiguity.
Logged In: YES
user_id=929365
So if you add this to your
stdlib/nice/functional/list-operators.nice or to everything
that imports it, then it will work:
<T> Slice<T> sl(Slice<T> t) = t;
override <T> List<T> get(List<T> list, Range<int> slice){
return list[sl(slice)];
}