Duplicate class/interface/struct completely
Given a class/interface/struct, I'd like to duplicate it's design exactly, as if I copied and pasted directly from the source and just changed the name. I need to inspect the contents too. Is this possible with D? Main things I'm thinking will fail are (multiple) alias this unless there is a way to get which variables are aliased to this. The idea is to be able to make sure one can modify a class and drop it in for the original and it work in all cases. With alias this, it can fail unless we can alias it too. struct X { int y; alias this y; } struct XX { mixin DupStruct!X; } If DupStruct cannot handle the alias this then XX can fail to mimic X completely.
Re: Issues with std.net.curl on Win 10 x64
On Monday, 25 March 2019 at 16:25:37 UTC, cptgrok wrote: Am I doing something wrong or is there some issue with curl or something else? I'm pretty new to D and I'm not sure if I need to go right down to raw sockets and re-invent the wheel or if there is some other library that can help. If I get this working, it could potentially save myself and many others hours per week. There is a limit of 50 concurrent messages per thread [1] in byLineAsync also the transmitBuffers argument takes part in. So using multiple byLineAsync at same time/thread is going to block the process, I'm not sure if this is a bug or is by design. You could use download() in a parallel foreach, something like this: import std.stdio; import std.parallelism; import std.net.curl; import std.typecons; void main() { auto connections = 3; // 3 parallel downloads defaultPoolThreads(connections - 1); auto retries = 4; // try up to 4 times if it fails auto logList = [ tuple("dlang.org", "log1.txt"), tuple("dlang.org", "log2.txt"), tuple("dlang.org", "log3.txt"), tuple("dlang.org", "log4.txt"), tuple("dlang.org", "log5.txt"), tuple("dlang.org", "log6.txt")]; foreach (log; parallel(logList, 1)) { HTTP conn = HTTP(); foreach (i; 0 .. retries) { try { writeln("Downloading ", log[0]); download(log[0], log[1], conn); if(conn.statusLine.code == 200) { writeln("File ", log[1], " created."); break; } } catch (CurlException e) { writeln("Retrying ", log[0]); } } } } [1] https://github.com/dlang/phobos/blob/master/std/net/curl.d#L1679
Re: Derive from interface
It depends on what you want. But you can always use composition instead of inheritance for B. I have been using things like alias this, mixin and ufcs to achive multiple iheritence and it works ok for me. On Mon, Mar 25, 2019 at 10:40 PM Michelle Long via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Since D does not support multiple inheritance, is there any way > to effectively achieve this? > > > class A; > class B; > > class C : A, interface!B; > > Then it is as if I have done > > > class A; > interface iB; > class B : iB; > > class C : A, iB; > > But I can then do > > C c = new B; > > (but since I can't make B inherit iB, this is impossible) > > > > > > > > > >
Derive from interface
Since D does not support multiple inheritance, is there any way to effectively achieve this? class A; class B; class C : A, interface!B; Then it is as if I have done class A; interface iB; class B : iB; class C : A, iB; But I can then do C c = new B; (but since I can't make B inherit iB, this is impossible)
design question, gtkd object interdependence
I have a design question about (i guess) object interdependence using gtkd. There is an application class which sets its property mAppWin. The app is passed as an argument to the window constructor. During the window constructor a scale (trackbar) is created which also receives and stores an app reference to later update other elements during an onChange event. The scale can access mApp.mSomeData to set its initial value because app has been passed down. The call to setValue() now triggers onValueChanged() which wants to access the mAppWin property of the app to update a canvas. Since all this happens during the initial 'new AppWin()' call in App, the app's mAppWin property is not set yet, so onValueChanged() will crash. class App : Application { AppWin mAppWin; void onActivate(GioApplication gioApp) { mSomeData = 123; mAppWin = new AppWin(app, [...]); class AppWin : ApplicationWindow { Scale1 mScale1; this(Application application, [...]) { mScale1 = new Scale1(0, 100, 1, app); // (app is application casted) class Scale1 : VScale { App mApp; this([...], App app) { [...] mApp = app; [...] setValue(max * mApp.mSomeData); } void onValueChanged(Range range) { //if (mApp.mAppWin) mApp.mAppWin.mCanvas.update(); // mAppWin not set yet, 0 I have several question in mind: - Is it a bad idea to pass an app around that contains everything for everywhere? - Should the app pass the data for the initial scale value through the window constructor? Or should it set the scale value after initialization is done? - How would the scale update the canvas without keeping/walking through a DOM like this. Maybe some asynchronous messaging? While I could make it work, I wonder what the actual problem is and what it's called like.
Re: Issues with std.net.curl on Win 10 x64
On Monday, 25 March 2019 at 19:02:18 UTC, cptgrok wrote: On Monday, 25 March 2019 at 16:44:12 UTC, Andre Pany wrote: First idea, please switch to x86_64 if possible. This will also be the default of Dub in the next dmd release or the release after. Kind regards Andrew Figured out --arch=x86_64, thanks! Sadly I don't see any change. I'm not having luck finding known curl issues similar to what I am experiencing. I have a sneaking suspicion that the web service I am using is doing some nonsense in the background. Might try a packet capture to better see what's up. Alternatively, you could always give requests a shot: https://code.dlang.org/packages/requests It's the unofficial successor of std.net.curl.
Re: Issues with std.net.curl on Win 10 x64
On Monday, 25 March 2019 at 16:44:12 UTC, Andre Pany wrote: First idea, please switch to x86_64 if possible. This will also be the default of Dub in the next dmd release or the release after. Kind regards Andrew Figured out --arch=x86_64, thanks! Sadly I don't see any change. I'm not having luck finding known curl issues similar to what I am experiencing. I have a sneaking suspicion that the web service I am using is doing some nonsense in the background. Might try a packet capture to better see what's up.
Re: Emulating DLL
On Thursday, 21 March 2019 at 02:27:46 UTC, SrMordred wrote: On Tuesday, 19 March 2019 at 19:50:15 UTC, Craig wrote: Take a look at my lib, its a simple hot-reload external dll lib: https://github.com/SrMordred/reloaded I did´nt use it extensively, but its simple enough to be tweaked at your own need :) Thanks, Looks much more like what I need. I'll have to mess around with it to see how it works though.
Re: Issues with std.net.curl on Win 10 x64
On Monday, 25 March 2019 at 16:25:37 UTC, cptgrok wrote: I need to review syslogs for over 160 systems monthly, and I am trying to write a utility to automate bulk downloads from a custom web service where they are hosted. I need to calculate a date range for the prior month, add start and end date and a serial number to the query string for each system, which is easy, and in a foreach(system; systems) loop in main() I call a function passing the string url in to download and write a log to file. For a small number of systems, it works. [...] First idea, please switch to x86_64 if possible. This will also be the default of Dub in the next dmd release or the release after. Kind regards Andrew
Issues with std.net.curl on Win 10 x64
I need to review syslogs for over 160 systems monthly, and I am trying to write a utility to automate bulk downloads from a custom web service where they are hosted. I need to calculate a date range for the prior month, add start and end date and a serial number to the query string for each system, which is easy, and in a foreach(system; systems) loop in main() I call a function passing the string url in to download and write a log to file. For a small number of systems, it works. My trouble is, using std.net.curl, if I use get(URL) to get the entire text in a single call and write to file, memory usage spirals out of control immediately and within 20 or so calls, gets to about 1.3 GB and the program crashes. If I use byLineAsync(URL), then foreach(line; range) write the lines to file one at a time the memory usage never gets above 5MB but it just hangs always at the 51st call in the loop regardless of what parameters are in the query string, or how much data I have downloaded. The program never terminates, even after hours, but I can't see ANY activity on the process, CPU, mem or network. I can break my download jobs into <=50 systems (and it seems to work), but that seems like sweeping something under the rug, probably leading to future issues. I'm using the 32bit binary from libcurl-7.64.0-WinSSL-zlib-x86-x64.zip on the release archive, and DMD 2.085.0. I've tried curl 7.63 and 7.57 but the behavior is the same. Am I doing something wrong or is there some issue with curl or something else? I'm pretty new to D and I'm not sure if I need to go right down to raw sockets and re-invent the wheel or if there is some other library that can help. If I get this working, it could potentially save myself and many others hours per week.
Re: "if" statement
On Sunday, 24 March 2019 at 12:45:13 UTC, Francesco Mecca wrote: https://run.dlang.io/is/zRcj59 ``` alias Alg = Algebraic!(int, string); void main() { int n = 2; Alg value; value = n == 2 ? 2 : "string"; } ``` The original code used SumType but the effect is the same. I suppose that I could write the following: ``` if(n == 2) value = 2; else value = "string"; ``` Is there a workaround for this that maintains a similar syntactic structure? is this behaviour accepted or should the compiler translate the first case in the second? You could make a Choose function: auto Ch(A,B)(bool c, A a, B b); Then value = Ch(n == 2, n, "string"); Not much different than value = (n == 2) ? Alg(2) : Alg("string"); except you don't have to write Alg all the time. The compiler should translate the first but that requires implicit conversion of any of the types T... to Algebraic!T... . Of course, that should be possible but is it?
Re: Calling D library from other languages on linux using foreign threads
On Saturday, 23 March 2019 at 17:33:31 UTC, tchaloupka wrote: I've no idea what should be done with C's main thread as it can't be attached because it'll hang. In one of forum threads I've also read the idea to not using foreign threads with GC but somehow delegate their work to D's thread. Can this work somehow? But `new Thread()` would still be needed to call from C side or static this() but from C's thread. I've tried this approach here: https://github.com/tchaloupka/dlangsharedlib/tree/master/workaround. I must say, it's an ugly and error prone hack.. :( It seems to be working, but questions remain: * is it ok to initialize D runtime and then use GC in the same C thread (to create worker Thread)? * is this reliable? * should foreign threads work with D's runtime at all? In the current state, D's libs seems to be pretty useless to be used from other languages if GC is needed.
Re: Why this eponymous template does not compile?
On Monday, 25 March 2019 at 09:27:03 UTC, Victor Porton wrote: /tmp/temp_7F3C101460D0.d(9,5): Error: template instance `synchronizedMemoize!f` template `synchronizedMemoize` is not defined, did you mean sychronizedMemoize(alias fun)()? Why the error? Sometimes, template error messages are hard to get. But this one is pretty clear, to the point that it is difficult for a human to point out clearer. :o)
Re: Why this eponymous template does not compile?
On Monday, 25 March 2019 at 09:27:03 UTC, Victor Porton wrote: /// template sychronizedMemoize(alias fun) { void sychronizedMemoize() { } } void f() { } void main() { synchronizedMemoize!f(); } /// /tmp/temp_7F3C101460D0.d(9,5): Error: template instance `synchronizedMemoize!f` template `synchronizedMemoize` is not defined, did you mean sychronizedMemoize(alias fun)()? Why the error? Is it compiler bug? DMD v2.084.1 Typo in eponymous template. syc vs sync.
Why this eponymous template does not compile?
/// template sychronizedMemoize(alias fun) { void sychronizedMemoize() { } } void f() { } void main() { synchronizedMemoize!f(); } /// /tmp/temp_7F3C101460D0.d(9,5): Error: template instance `synchronizedMemoize!f` template `synchronizedMemoize` is not defined, did you mean sychronizedMemoize(alias fun)()? Why the error? Is it compiler bug? DMD v2.084.1
Re: "if" statement
On Sunday, 24 March 2019 at 12:45:13 UTC, Francesco Mecca wrote: https://run.dlang.io/is/zRcj59 ``` alias Alg = Algebraic!(int, string); void main() { int n = 2; Alg value; value = n == 2 ? 2 : "string"; } ``` The original code used SumType but the effect is the same. I suppose that I could write the following: ``` if(n == 2) value = 2; else value = "string"; ``` Is there a workaround for this that maintains a similar syntactic structure? is this behaviour accepted or should the compiler translate the first case in the second? You can achieve the same thing by just constructing your algebraic type earlier: value = n == 2 ? Alg(2) : Alg("string");