Re: shared interfaces
On Sunday, 15 February 2015 at 10:43:46 UTC, Andrey Derzhavin wrote: what is wrong in declarations, if I need to declare shared classes D and C? `shared` on a class/interface makes all members shared. And that's all it does. So this: interface IA { void fnA(); } shared class C : IA { override void fnA() {} } is the same as this: interface IA { void fnA(); } class C : IA { override void fnA() shared {} } But you can't override a non-shared method with a shared one, hence the error. So, if you need to override non-shared methods, you can't mark the whole class shared. Instead, you have to mark the shared members individually. Like so: interface IA { void fnA(); } shared interface IC : IA { void fnC(); } class D : IC { override void fnC() shared {} override void fnA() {} }
Re: shared interfaces
On Sunday, 15 February 2015 at 14:59:20 UTC, anonymous wrote: Hm? Works for me. What error do you get, or what doesn't work? Which compiler are you using, which version? The error Error: function main.C.fnA does not override any function, did you mean to override 'main.IA.fnA'? has occured (( I'm using DMD 2.066.1 compiler.
Re: shared interfaces
On Sunday, 15 February 2015 at 14:59:20 UTC, anonymous wrote: Sorry everything is OK. It's my fault. Thanks))
Re: shared interfaces
On Sunday, 15 February 2015 at 11:30:46 UTC, anonymous wrote: On Sunday, 15 February 2015 at 10:43:46 UTC, Andrey Derzhavin wrote: what is wrong in declarations, if I need to declare shared classes D and C? `shared` on a class/interface makes all members shared. And that's all it does. So this: interface IA { void fnA(); } shared class C : IA { override void fnA() {} } is the same as this: interface IA { void fnA(); } class C : IA { override void fnA() shared {} } But you can't override a non-shared method with a shared one, hence the error. So, if you need to override non-shared methods, you can't mark the whole class shared. Instead, you have to mark the shared members individually. Like so: interface IA { void fnA(); } shared interface IC : IA { void fnC(); } class D : IC { override void fnC() shared {} override void fnA() {} } Try to compile your example, it is wrong.
Re: shared interfaces
On Sunday, 15 February 2015 at 12:34:50 UTC, Andrey Derzhavin wrote: On Sunday, 15 February 2015 at 11:30:46 UTC, anonymous wrote: [...] interface IA { void fnA(); } shared interface IC : IA { void fnC(); } class D : IC { override void fnC() shared {} override void fnA() {} } Try to compile your example, it is wrong. Hm? Works for me. What error do you get, or what doesn't work? Which compiler are you using, which version?
ranges reading garbage
Simplified from something bigger: import std.range, std.algorithm, std.stdio; void foo(float[] data, float[] xs, float[] ys) { auto indices = iota(0, data.length, ys.length) .map!(xBase = iota(xBase, xBase + ys.length - 1) .map!(y = only(y, y+ys.length, y+ys.length+1, y+1)) .joiner()) .joiner(); writeln(indices); } void main() { foo([1,2,3,4,5,6,7,8], [0.1,0.2], [10,20,30,40]); } prints things like [0, 4, 5, 1, 1, 1459971595, 1459971596, 2, 2, 1459971596, 1459971597, 3, 4, 8, 9, 5, 5, 4441427819, 4441427820, 6, 6, 4441427820, 4441427821, 7] but the output isn't consistent, the big numbers change on each run.
Wrong overload resolution
This problem appears only if one of the parameters is an interface. Without it or using any other type as a second parameter instead of the interface, it compiles. Also it compiles if the passed interface is null. The example below uses short/ushort, but I found the same behaviour for any combination of integral types of the same bitsize (byte/ubyte/char, ushort/short/wchar, int/uint/dchar, long/ulong) D 2.066.1 interface I {} class C: I {} void func(ushort s, I i) { writeln(ushort overload); } void func(short s, I i) { writeln(short overload); } void call(short s) { C c = new C(); I d = new C(); func(s, c); // ERROR see below //but these are ok func(s, cast(I)c) //ok func(s, d) //ok func(s, null) //ok } main.func called with argument types (short, C) matches both: main.func(short s, I i) main.func(ushort s, I i)
Re: Wrong overload resolution
On Sunday, 15 February 2015 at 23:48:50 UTC, rumbu wrote: This problem appears only if one of the parameters is an interface. Without it or using any other type as a second parameter instead of the interface, it compiles. Also it compiles if the passed interface is null. The example below uses short/ushort, but I found the same behaviour for any combination of integral types of the same bitsize (byte/ubyte/char, ushort/short/wchar, int/uint/dchar, long/ulong) D 2.066.1 interface I {} class C: I {} void func(ushort s, I i) { writeln(ushort overload); } void func(short s, I i) { writeln(short overload); } void call(short s) { C c = new C(); I d = new C(); func(s, c); // ERROR see below //but these are ok func(s, cast(I)c) //ok func(s, d) //ok func(s, null) //ok } main.func called with argument types (short, C) matches both: main.func(short s, I i) main.func(ushort s, I i) it's intereting to note that if func() are rewritten: --- void func(ref ushort s, I i){} void func(ref short s, I i){} --- or even --- void func(const ref ushort s, I i){} void func(const ref short s, I i){} --- the problem doesn't happend.
Re: ranges reading garbage
On Sunday, 15 February 2015 at 18:13:44 UTC, John Colvin wrote: Simplified from something bigger: import std.range, std.algorithm, std.stdio; void foo(float[] data, float[] xs, float[] ys) { auto indices = iota(0, data.length, ys.length) .map!(xBase = iota(xBase, xBase + ys.length - 1) .map!(y = only(y, y+ys.length, y+ys.length+1, y+1)) .joiner()) .joiner(); writeln(indices); } void main() { foo([1,2,3,4,5,6,7,8], [0.1,0.2], [10,20,30,40]); } prints things like [0, 4, 5, 1, 1, 1459971595, 1459971596, 2, 2, 1459971596, 1459971597, 3, 4, 8, 9, 5, 5, 4441427819, 4441427820, 6, 6, 4441427820, 4441427821, 7] but the output isn't consistent, the big numbers change on each run. Reduced some more: import std.algorithm, std.stdio; void main() { int ys_length = 4; auto indices = [0] .map!(xBase = [0].map!(y = ys_length)) .joiner(); writeln(indices); }
Re: ranges reading garbage
John Colvin: prints things like [0, 4, 5, 1, 1, 1459971595, 1459971596, 2, 2, 1459971596, 1459971597, 3, 4, 8, 9, 5, 5, 4441427819, 4441427820, 6, 6, 4441427820, 4441427821, 7] but the output isn't consistent, the big numbers change on each run. Try to replace the only() with: [y, y+ys.length, y+ys.length+1, y+1] Like this: import std.range, std.algorithm, std.stdio; void foo(in float[] data, in float[] xs, in float[] ys) @safe { iota(0, data.length, ys.length) .map!(xBase = iota(xBase, xBase + ys.length - 1) .map!(y = [y, y+ys.length, y+ys.length+1, y+1]) .joiner) .joiner .writeln; } void main() { foo([1,2,3,4,5,6,7,8], [0.1,0.2], [10,20,30,40]); } In Rust the compiler enforces that all stack-allocated data doesn't come from dead stack frames. In D you have to be careful to avoid doing it. In future this kind of bugs will be hopefully avoided by a better tracking of the memory. I am not sure if http://wiki.dlang.org/DIP69 is able to avoid this bug, if it can't, then DIP69 needs to be improved. Bye, bearophile
Re: ranges reading garbage
On 2015-02-15 at 19:43, bearophile wrote: void foo(in float[] data, in float[] xs, in float[] ys) @safe { iota(0, data.length, ys.length) .map!(xBase = iota(xBase, xBase + ys.length - 1) .map!(y = [y, y+ys.length, y+ys.length+1, y+1]) .joiner) .joiner .writeln; } void main() { foo([1,2,3,4,5,6,7,8], [0.1,0.2], [10,20,30,40]); } Odd... Still something is wrong. It prints: [0, 4, 5, 1, 1, 5, 6, 2, 2, 6, 7, 3, 4, 8, 9, 5, 5, 5, 6, 6, 6, 6, 7, 7] instead of this: [0, 4, 5, 1, 1, 5, 6, 2, 2, 6, 7, 3, 4, 8, 9, 5, 5, 9, 10, 6, 6, 10, 11, 7]
Re: ranges reading garbage
On Sunday, 15 February 2015 at 18:43:35 UTC, bearophile wrote: John Colvin: prints things like [0, 4, 5, 1, 1, 1459971595, 1459971596, 2, 2, 1459971596, 1459971597, 3, 4, 8, 9, 5, 5, 4441427819, 4441427820, 6, 6, 4441427820, 4441427821, 7] but the output isn't consistent, the big numbers change on each run. Try to replace the only() with: [y, y+ys.length, y+ys.length+1, y+1] Like this: import std.range, std.algorithm, std.stdio; void foo(in float[] data, in float[] xs, in float[] ys) @safe { iota(0, data.length, ys.length) .map!(xBase = iota(xBase, xBase + ys.length - 1) .map!(y = [y, y+ys.length, y+ys.length+1, y+1]) .joiner) .joiner .writeln; } void main() { foo([1,2,3,4,5,6,7,8], [0.1,0.2], [10,20,30,40]); } In Rust the compiler enforces that all stack-allocated data doesn't come from dead stack frames. In D you have to be careful to avoid doing it. In future this kind of bugs will be hopefully avoided by a better tracking of the memory. I am not sure if http://wiki.dlang.org/DIP69 is able to avoid this bug, if it can't, then DIP69 needs to be improved. Bye, bearophile But std.range.OnlyResult!(size_t, 4) is a value type, I don't see where the stack reference is being leaked.
Re: ranges reading garbage
FG: Odd... Still something is wrong. It prints: [0, 4, 5, 1, 1, 5, 6, 2, 2, 6, 7, 3, 4, 8, 9, 5, 5, 5, 6, 6, 6, 6, 7, 7] instead of this: [0, 4, 5, 1, 1, 5, 6, 2, 2, 6, 7, 3, 4, 8, 9, 5, 5, 9, 10, 6, 6, 10, 11, 7] This is less lazy and gives another result: import std.range, std.algorithm, std.stdio; void foo(in float[] data, in float[] xs, in float[] ys) @safe { iota(0, data.length, ys.length) .map!(xBase = iota(xBase, xBase + ys.length - 1) .map!(y = [y, y+ys.length, y+ys.length+1, y+1]) .join) .join .writeln; } void main() { foo([1,2,3,4,5,6,7,8], [0.1,0.2], [10,20,30,40]); } What a fun program :-) Bye, bearophile
shared interfaces
interface IA { void fnA(); } interface IB { void fnB(); } shared interface IC : IA, IB { void fnC(); } shared class C : IA, IB { override void fnA() // Error: function main.C.fnA does not override any function, did you mean to override 'main.IA.fnA'? { } override void fnB() // Error: function main.C.fnB does not override any function, did you mean to override 'main.IA.fnA'? { } shared class D : IC { override void fnC() { } override void fnA() // Error: function main.D.fnA does not override any function, did you mean to override 'main.IA.fnA'? { } override void fnB() // Error: function main.D.fnB does not override any function, did you mean to override 'main.IB.fnB'? { } } what is wrong in declarations, if I need to declare shared classes D and C?
Re: ranges reading garbage
On Sunday, 15 February 2015 at 19:54:45 UTC, anonymous wrote: Reduced some more: import std.algorithm, std.stdio; void main() { int ys_length = 4; auto indices = [0] .map!(xBase = [0].map!(y = ys_length)) .joiner(); writeln(indices); } And more: import std.stdio; struct MapResult(alias fun) { @property int front() {return fun();} @property auto save() {return typeof(this)();} } void main() { int ys_length = 4; auto dg = {return MapResult!({return ys_length;})();}; writeln(dg().front); /* 4, correct */ writeln(dg().save.front); /* garbage */ }
Lazily Partially Sorted
I would like to implement a variant of Sorted at https://github.com/D-Programming-Language/phobos/pull/2793 that does completeSort of _store lazily instead of eagerly. I guess this is a bit more complex to implement as all accessors of LazySorted, such as opIndex, opSlice, etc (to the underlying storage) needs to be wrapped by a logic that checks whether the underlying storage (_store) is dirty (this.dirtyIndex this._store.length) and if so sorts it. Is there some clever D way to implement this?
Re: How to make a Currency class from std.BigInt?
This library allow to specify the internal base of the arbitrary precision numbers( default is decimal), as well as allows specification of the precision of floating point values. Each floating point number precision can be read with .precision(). Also supports specification of rounding modes. Seems like it would be a nice project for a port to D. http://www.hvks.com/Numerical/arbitrary_precision.html
Re: D1: Error: function ... cannot have an in contract when overriden function
On Saturday, 8 November 2014 at 01:59:56 UTC, Adam D. Ruppe wrote: If it is just that one error, you could always just comment out the in contract and recompile. Sorry it took so long. Extremely busy, but anyway, this is the piece of the code that is causin the problem: code override void text(Dstring txt) // setter in { if(txt.length) assert(!this.image, Button image with text not supported); } body { super.text = txt; } alias Control.text text; // Overload. /code I have no idea what these lines do. Any thoughts? Thanks. josé
Re: D1: Error: function ... cannot have an in contract when overriden function
It checks that you don't set both text and image, because the button doesn't support it.