Re: functional way doing array stuff/ lambda functions
On Sunday, 13 December 2015 at 03:08:33 UTC, Namal wrote: On Saturday, 12 December 2015 at 23:50:55 UTC, Xinok wrote: [...] I tried this, it compiles, but crashes when I try to run it: object.Exception@/usr/include/dmd/phobos/std/algorithm/iteration.d(2481): Enforcement failed ??:? pure @safe void std.exception.bailOut!(Exception).bailOut(immutable(char)[], ulong, const(char[])) [0x43a547] ??:? pure @safe bool std.exception.enforce!(Exception, bool).enforce(bool, lazy const(char)[], immutable(char)[], ulong) [0x43a4c4] ??:? pure @safe int std.algorithm.iteration.__T6reduceS305ep1247productFKxAiZ9__lambda2Z.reduce!(const(int)[]).reduce(const(int)[]) [0x43a2ed] ??:? int ep124.product(ref const(int[])) [0x439d49] ??:? _Dmain [0x43a229] ??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [0x448b9a] ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x448af0] ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [0x448b56] ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x448af0] ??:? _d_run_main [0x448a4d] ??:? main [0x4447ad] ??:? __libc_start_main [0xd9f09ec4] As cryptic as it is this means that the range you passed to reduce is empty. Reduce needs it not to be because as I said it needs a seed and as you didn't pass one explicitely as argument it tries to take the first element of the range (and fails obviously). You can either pass it a seed explicitely or add a non-empty check before the return.
Re: functional way doing array stuff/ lambda functions
On Sunday, 13 December 2015 at 03:08:33 UTC, Namal wrote: This works for me : import std.stdio, std.algorithm, std.range; int[] prim_factors(int n, const int[] P) { int[] v; P.filter!( x => x*x <= n).each!( (i) { while (n % i == 0) { v ~= i; n /= i; if (i == 1) break; // infinite loop otherwise ! } } ); if (n > 1) v ~= n; return v.sort.uniq.array; } void main(string[] args) { int[] P = [1,2,3,4,5]; writeln( prim_factors(10, P).reduce!((r, i) => r*i)() ); }
deep copying / .dup / template object.dup cannot deduce function from argument types
Hi, I just wanted to naively copy an object and used: a = myobj.dup; and get the following error messages: source/app.d(191): Error: template object.dup cannot deduce function from argument types !()(BlockV), candidates are: /Library/D/dmd/src/druntime/import/object.d(1872):object.dup(T : V[K], K, V)(T aa) /Library/D/dmd/src/druntime/import/object.d(1908):object.dup(T : V[K], K, V)(T* aa) /Library/D/dmd/src/druntime/import/object.d(3246): object.dup(T)(T[] a) if (!is(const(T) : T)) /Library/D/dmd/src/druntime/import/object.d(3262): object.dup(T)(const(T)[] a) if (is(const(T) : T)) /Library/D/dmd/src/druntime/import/object.d(3273):object.dup(T : void)(const(T)[] a) Hmm... so, is .dup not the way to go? And, am I correct, that a deep-copy needs to be hand coded? -- Robert M. Münch http://www.saphirion.com smarter | better | faster
Re: D programming video tutorial
On Sunday, 13 December 2015 at 20:29:47 UTC, Pederator wrote: Hi. Does anybody who is familair with D consider to make a comprehensive D programming video tutorial / training / course? This could be encouraging and helpful for people to start with D. It could also help in promoting D programming language. This is a question for all the community, please comment what do you think about this idea, we will know if there is an interest in such a training video, or is it just me. You're not the first, the other threads asking the same thing can be summarized by "Sure, it would be great, but I'm already working on this and that so I have neither the time nor the competence to do it". If you want it to happen make it happen yourself, you might get help once you're started by I've never seen anybody saying "Oh, right, that's exactly my thing and I've never thought of that, I'll give up my weekends from now on to do that".
Re: D programming video tutorial
On Sunday, 13 December 2015 at 20:29:47 UTC, Pederator wrote: Hi. Does anybody who is familair with D consider to make a comprehensive D programming video tutorial / training / course? This could be encouraging and helpful for people to start with D. It could also help in promoting D programming language. This is a question for all the community, please comment what do you think about this idea, we will know if there is an interest in such a training video, or is it just me. It's almost two years old now but I found this series of videos on D: https://www.youtube.com/playlist?list=PL-zvF7DyWePQad_E6Y9J9kbYvM7AjnBD1
Re: D programming video tutorial
On Sunday, 13 December 2015 at 20:45:56 UTC, cym13 wrote: On Sunday, 13 December 2015 at 20:29:47 UTC, Pederator wrote: Hi. Does anybody who is familair with D consider to make a comprehensive D programming video tutorial / training / course? This could be encouraging and helpful for people to start with D. It could also help in promoting D programming language. This is a question for all the community, please comment what do you think about this idea, we will know if there is an interest in such a training video, or is it just me. You're not the first, the other threads asking the same thing can be summarized by "Sure, it would be great, but I'm already working on this and that so I have neither the time nor the competence to do it". If you want it to happen make it happen yourself, you might get help once you're started by I've never seen anybody saying "Oh, right, that's exactly my thing and I've never thought of that, I'll give up my weekends from now on to do that". Didn't know about the other threads. I think that making a video tutorial takes much less work than writing a book, and there are already a few books on D programming language, but no video tutorial. Besides, creator could earn money on the video as well. Many people prefer to learn from video tutorial, especially on the beginning.
Implicit Interface Deduction
interface IA {} interface IB {} interface IC {} interface IAB : IA, IB {} interface IBC : IB, IC {} class C : IA, IB, IC {} // Defining C as : IAB, IBC // is not really scalable ;) void main() { IAB c = new C(); // This doesn't work. } // Any suggestions?
Re: [Dgame] Is there Multiple Window support?
On Sunday, 13 December 2015 at 06:33:55 UTC, Jack wrote: Hello, so I've been experimenting with the framework and I tried to implement a game that has more than two windows. The first window is the main game and the second window is a smaller one with the various commands you can select. So I tried to render sprites onto the first window and the second window, and failed. -- window_1.clear(); window_2.clear(); window_1.draw(sprite_1); window_2.draw(sprite_2); window_1.display(); window_2.display(); --- So far, when two windows are called to clear, draw and display, it didn't render anything. There was no error message, but once I commented out the window_2 calls, it rendered the first window without flaw. So are multiple windows supported here? Should work. Please report an issue on github (https://github.com/Dgame/Dgame) with your description and the reduced example.
D programming video tutorial
Hi. Does anybody who is familair with D consider to make a comprehensive D programming video tutorial / training / course? This could be encouraging and helpful for people to start with D. It could also help in promoting D programming language. This is a question for all the community, please comment what do you think about this idea, we will know if there is an interest in such a training video, or is it just me.
Re: D programming video tutorial
On Sunday, 13 December 2015 at 20:29:47 UTC, Pederator wrote: Does anybody who is familair with D consider to make a comprehensive D programming video tutorial / training / course? I've hired someone out of my own pocket to work on it, with me there to answer questions and review content for correctness. Slow process though, a lot more work goes into these than you'd think...
Re: deep copying / .dup / template object.dup cannot deduce function from argument types
On Sunday, 13 December 2015 at 18:54:24 UTC, Robert M. Münch wrote: Hi, I just wanted to naively copy an object and used: a = myobj.dup; and get the following error messages: source/app.d(191): Error: template object.dup cannot deduce function from argument types !()(BlockV), candidates are: /Library/D/dmd/src/druntime/import/object.d(1872): object.dup(T : V[K], K, V)(T aa) /Library/D/dmd/src/druntime/import/object.d(1908): object.dup(T : V[K], K, V)(T* aa) /Library/D/dmd/src/druntime/import/object.d(3246): object.dup(T)(T[] a) if (!is(const(T) : T)) /Library/D/dmd/src/druntime/import/object.d(3262): object.dup(T)(const(T)[] a) if (is(const(T) : T)) /Library/D/dmd/src/druntime/import/object.d(3273): object.dup(T : void)(const(T)[] a) Hmm... so, is .dup not the way to go? And, am I correct, that a deep-copy needs to be hand coded? `dup` is an array method; it only works on arrays. Structs are value types, so `a = b` will "duplicate" a struct. For classes, you will need to define your own clone function.
Re: D programming video tutorial
On 14/12/15 11:04 AM, Xinok wrote: On Sunday, 13 December 2015 at 20:29:47 UTC, Pederator wrote: Hi. Does anybody who is familair with D consider to make a comprehensive D programming video tutorial / training / course? This could be encouraging and helpful for people to start with D. It could also help in promoting D programming language. This is a question for all the community, please comment what do you think about this idea, we will know if there is an interest in such a training video, or is it just me. It's almost two years old now but I found this series of videos on D: https://www.youtube.com/playlist?list=PL-zvF7DyWePQad_E6Y9J9kbYvM7AjnBD1 Me and Simen Simen Endsjø were working on it. But honestly? Videos like this are very very hard to make. I find book writing much easier.
Re: Implicit Interface Deduction
On 12/13/2015 02:09 PM, Faux Amis wrote: interface IA {} interface IB {} interface IC {} interface IAB : IA, IB {} interface IBC : IB, IC {} class C : IA, IB, IC {} // Defining C as : IAB, IBC // is not really scalable ;) It is not automatic at least because of implementation details: The compiler should not generate a vtbl for every possible interface. Is it acceptable to add IAB and IBC to C? If so, this works: import std.stdio; class C : IA, IB, IC, IAB, IBC { void a() { writeln(__FUNCTION__); } void b() { writeln(__FUNCTION__); } void c() { writeln(__FUNCTION__); } } Ali
Re: Implicit Interface Deduction
On Sun, 13 Dec 2015 23:09:47 +0100, Faux Amis wrote: > interface IA {} > interface IB {} > interface IC {} > interface IAB : IA, IB {} interface IBC : IB, IC {} > > class C : IA, IB, IC {} > // Defining C as : IAB, IBC // is not really scalable ;) > > void main() > { > IAB c = new C(); // This doesn't work. > } > // Any suggestions? If you really can't modify the declaration to suit, there are two options. The first is to use casts. If a function would require something that's both IA and IB, it takes an IA and casts to IB. It can use contracts to ensure that things are of the right type. Ugly, but it works. The second is to use templates to generate the interface you need and appropriate wrapper classes. Then you need to manually wrap variables in those generated wrapper classes wherever you need to pass them. You'll end up with an API like: alias IABC = Union!(IA, IB, IC); void foo(IABC.Interface iabc) {} auto c = new C; foo(IABC.wrap(c)); If you really want to go this way, std.typecons might help. Or I hacked up something horrific here: http://dpaste.dzfl.pl/0464f723580f