Re: Error running concurrent process and storing results in array
On Thursday, 21 May 2020 at 07:38:45 UTC, data pulverizer wrote: Started uploading the code and writing the article for this. The code for each language can be run, see the script.x files in each folder for details and timings. https://github.com/dataPulverizer/KernelMatrixBenchmark Thanks First draft of the article is done. I welcome comments. I love writing D code but I wanted the article to be as "fair and balanced" as possible. Don't you just love that phrase? Also the article kind of morphed into a more general discussion of the programming languages.
Re: redirect std out to a string?
On Thursday, 21 May 2020 at 15:42:50 UTC, Basile B. wrote: On Thursday, 21 May 2020 at 04:29:30 UTC, Kaitlyn Emmons wrote: is there a way to redirect std out to a string or a buffer without using a temp file? yes: [snip] Alternatively, setvbuf can be used: void[1024] buf; // buffer must be valid as long as the program is running [1] // (buffer could also be heap-allocated; see Basile's post) void main() { import std.stdio; import std.string : fromStringz; stdout.reopen("/dev/null", "a"); // on Windows, "NUL" should do the trick stdout.setvbuf(buf); writeln("Hello world", 12345); stdout.writeln("Hello again"); // Lastly, fromStringz is used to get a correctly sized char[] from the buffer char[] mystr = fromStringz(cast(char *) buf.ptr); stderr.writeln("Buffer contents:\n", mystr); } [1] https://en.cppreference.com/w/c/io/setvbuf#Notes
Re: How to use GET_X_LPARAM in D ?
On Thursday, 21 May 2020 at 20:12:13 UTC, Harry Gillanders wrote: On Thursday, 21 May 2020 at 18:42:47 UTC, Vinod K Chandran wrote: Hi all, I need to use the macro GET_X_LPARAM. But compiler says that "undefined identifier GET_X_LPARAM". I cant find any modules with GET_X_LPARAM defined. Do i miss something ? GET_X_LPARAM isn't defined in Phobos's Windows bindings, so you'll need to provide the definition yourself. GET_X_LPARAM is defined as a macro in the windowsx.h header of the Windows SDK, as: #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp)) Which can trivially be translated to D as a function, like so: int GET_X_LPARAM (T) (T lp) { import core.sys.windows.windef : LOWORD; return cast(int) cast(short) LOWORD(lp); } Hope this helps :) Thank you for the code and guidance. Let me check it. :)
Re: How to use GET_X_LPARAM in D ?
On Thursday, 21 May 2020 at 18:42:47 UTC, Vinod K Chandran wrote: Hi all, I need to use the macro GET_X_LPARAM. But compiler says that "undefined identifier GET_X_LPARAM". I cant find any modules with GET_X_LPARAM defined. Do i miss something ? GET_X_LPARAM isn't defined in Phobos's Windows bindings, so you'll need to provide the definition yourself. GET_X_LPARAM is defined as a macro in the windowsx.h header of the Windows SDK, as: #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp)) Which can trivially be translated to D as a function, like so: int GET_X_LPARAM (T) (T lp) { import core.sys.windows.windef : LOWORD; return cast(int) cast(short) LOWORD(lp); } Hope this helps :)
Re: How to use GET_X_LPARAM in D ?
On Thursday, 21 May 2020 at 18:42:47 UTC, Vinod K Chandran wrote: Hi all, I need to use the macro GET_X_LPARAM. But compiler says that "undefined identifier GET_X_LPARAM". I cant find any modules with GET_X_LPARAM defined. Do i miss something ? I search all modules in " C:\D\dmd2\src\druntime\src\core\sys\windows ". But no luck.
How to use GET_X_LPARAM in D ?
Hi all, I need to use the macro GET_X_LPARAM. But compiler says that "undefined identifier GET_X_LPARAM". I cant find any modules with GET_X_LPARAM defined. Do i miss something ?
Re: String interpolation
On Thursday, 21 May 2020 at 06:57:28 UTC, mw wrote: On Thursday, 21 May 2020 at 01:13:27 UTC, Paul Backus wrote: On Wednesday, 20 May 2020 at 23:41:15 UTC, mw wrote: Can we do string interpolation in D now? There's an implementation in the dub package "scriptlike": https://code.dlang.org/packages/scriptlike#string-interpolation Thank you! very nice: // Output: The number 21 doubled is 42! int num = 21; writeln( mixin(interp!"The number ${num} doubled is ${num * 2}!") ); Is there any way to make it shorter? e.g. writeln( s!"The number ${num} doubled is ${num * 2}!" ); i.e how to write this 's'? And for debug print, I like the output be: The number num=21 doubled is num * 2=42! i.e print out the string of the original expression, like the stringy operator in C’s macro #var
Re: String interpolation
On Thursday, 21 May 2020 at 17:17:49 UTC, Adam D. Ruppe wrote: On Thursday, 21 May 2020 at 17:10:31 UTC, mw wrote: BTW, is the .idup must be there? It is discussed more in the github document but basically the proposed built-in syntax returns a generic builder thing which can make more than just strings. The idup specifically asks it to make a copy into a string as opposed to the other things it can provide too. I love the extensibility of this, but perhaps there should be something like `ii"foo".idup` that's syntactic sugar for `i"foo".idup`. New users might get confused by the need for appending idup, and then they'll think about how other languages don't necessitate this perceived superfluity when using their interpolated string.
Re: String interpolation
On Thursday, 21 May 2020 at 18:12:01 UTC, ZK wrote: I love the extensibility of this, but perhaps there should be something like `ii"foo".idup` that's syntactic sugar for `i"foo".idup`. New users might get confused by the need for appending idup, and then they'll think about how other languages don't necessitate this perceived superfluity when using their interpolated string. Whoops! I meant to say `ii"foo"`, not `ii"foo".idup`.
Re: How to allocate/free memory under @nogc
On Thursday, 21 May 2020 at 15:09:57 UTC, Steven Schveighoffer wrote: On 5/20/20 10:50 PM, data pulverizer wrote: how do you allocate/free memory without using the garbage collector? Use C malloc and free. Does allocating and freeing memory using `GC.malloc` and `GC.free` avoid D's garbage collector? No, an allocation can trigger a collection. D does not have a scheduled GC, it basically runs the GC when it can't allocate any more memory from it's pools before it tries to get more from the OS. I *think* that @nogc is supposed to mean "Be able to run this without a GC implemented", not that no collections will run. -Steve Hi all! I will try to ask again(previous two posts still have no answers) : are there any site/page/docs somewhere to track actual info about @nogc support in language itself and in phobos library? Or, at least plans to extend such support?
Re: String interpolation
On Thursday, 21 May 2020 at 17:10:31 UTC, mw wrote: BTW, is the .idup must be there? It is discussed more in the github document but basically the proposed built-in syntax returns a generic builder thing which can make more than just strings. The idup specifically asks it to make a copy into a string as opposed to the other things it can provide too.
Re: String interpolation
On Thursday, 21 May 2020 at 12:53:50 UTC, Adam D. Ruppe wrote: On Thursday, 21 May 2020 at 06:57:28 UTC, mw wrote: i.e how to write this 's'? gimme a like on the proposal to add to the language! https://github.com/dlang/DIPs/pull/186 If accepted, that would let you write i"stuff here".idup to get an interpolated string. Liked. BTW, is the .idup must be there?
Re: redirect std out to a string?
On Thursday, 21 May 2020 at 04:29:30 UTC, Kaitlyn Emmons wrote: is there a way to redirect std out to a string or a buffer without using a temp file? yes: --- #!dmd -betterC module runnable; extern(C) int main() { import core.sys.posix.stdio : fclose, stdout, fmemopen, printf, fflush; import core.stdc.stdlib : malloc; char* buff; enum s = "this will use a buffer from the heap that has, " ~ "just like a file, a FD thanks to fmemopen()"; fclose(stdout); buff = cast(char*) malloc(4096); buff[0..4096] = '\0'; stdout = fmemopen(buff, 4096, "wr+"); printf(s); fflush(stdout); assert(buff[0..s.length] == s); return 0; } --- something similar should be possible using mmap().
Re: redirect std out to a string?
On Thursday, 21 May 2020 at 04:29:30 UTC, Kaitlyn Emmons wrote: is there a way to redirect std out to a string or a buffer without using a temp file? If you want to do the redirection at startup, it's possible. Have an another program to start your program by std.process functions and redirect stdout to a pipe. The outer program can then handle the output of the inner program however it wishes. Clumsy but possible. But I don't know whether a process can redirect it's own standard input or output.
Re: How to use this forum ?
On Wednesday, 20 May 2020 at 21:15:25 UTC, Dukc wrote: On Wednesday, 20 May 2020 at 20:49:52 UTC, Vinod K Chandran wrote: [...] No can do :(. Well, moderators can delete posts so you could try to ask them nicely in some cases but the primary way tends to be the same as with email: send a correction message. [...] Thanks. I got it.
Re: How to use this forum ?
On Wednesday, 20 May 2020 at 21:13:25 UTC, Paul Backus wrote: On Wednesday, 20 May 2020 at 20:49:52 UTC, Vinod K Chandran wrote: [...] You can't. If you need to make a correction, the best you can do is to make a follow-up post. [...] Copy & paste it. [...] You can't embed images directly. I'd recommend uploading your image to a hosting site like imgur and pasting the link into your post. [...] No. If you're wondering why these limitations exist, it's because this forum is actually a web interface for the D mailing lists [1]. You can't edit email after it's been sent, so you can't edit your posts here either. [1] https://forum.dlang.org/help#about Thanks, I got the point.
Re: redirect std out to a string?
On 5/21/20 12:29 AM, Kaitlyn Emmons wrote: is there a way to redirect std out to a string or a buffer without using a temp file? D's I/O is dependent on C's FILE * API, so if you can make that write to a string, then you could do it in D. I don't think there's a way to do it in C. So likely the answer is no. -Steve
Re: How to allocate/free memory under @nogc
On 5/20/20 10:50 PM, data pulverizer wrote: how do you allocate/free memory without using the garbage collector? Use C malloc and free. Does allocating and freeing memory using `GC.malloc` and `GC.free` avoid D's garbage collector? No, an allocation can trigger a collection. D does not have a scheduled GC, it basically runs the GC when it can't allocate any more memory from it's pools before it tries to get more from the OS. I *think* that @nogc is supposed to mean "Be able to run this without a GC implemented", not that no collections will run. -Steve
Re: String interpolation
On Thursday, 21 May 2020 at 06:57:28 UTC, mw wrote: i.e how to write this 's'? gimme a like on the proposal to add to the language! https://github.com/dlang/DIPs/pull/186 If accepted, that would let you write i"stuff here".idup to get an interpolated string.
Re: String interpolation
On Thursday, 21 May 2020 at 06:57:28 UTC, mw wrote: On Thursday, 21 May 2020 at 01:13:27 UTC, Paul Backus wrote: On Wednesday, 20 May 2020 at 23:41:15 UTC, mw wrote: Can we do string interpolation in D now? There's an implementation in the dub package "scriptlike": https://code.dlang.org/packages/scriptlike#string-interpolation Thank you! very nice: // Output: The number 21 doubled is 42! int num = 21; writeln( mixin(interp!"The number ${num} doubled is ${num * 2}!") ); Is there any way to make it shorter? e.g. writeln( s!"The number ${num} doubled is ${num * 2}!" ); i.e how to write this 's'? Unfortunately, it's not possible. Without `mixin`, there's no way to give the template access to local variables like `num`.
String interpolation
https://forum.dlang.org/post/prlulfqvxrgrdzxot...@forum.dlang.org On Tuesday, 10 November 2015 at 11:22:56 UTC, wobbles wrote: int a = 1; int b = 4; writefln("The number %s is less than %s", a, b); writeln("The number ",a, " is less than ",b);
Re: Template type deduction question
On Thursday, 21 May 2020 at 07:16:11 UTC, Basile B. wrote: The problem is that "K" is a template type parameter [1]. When the compiler deduces the parameter that ends up with a symbol, i.e not a type. To permit a symbol to be deduced you can use a template alias parameter[2] instead: --- struct Matrix(T) {} struct Kernel(T) {} void calculateKernelMatrix(alias K, T)(K!T kernel, Matrix!T data) { } void main() { Matrix!float m; Kernel!float k; calculateKernelMatrix(k,m); // OK } --- Thanks!
Re: Error running concurrent process and storing results in array
On Wednesday, 6 May 2020 at 17:31:39 UTC, Jacob Carlborg wrote: On 2020-05-06 12:23, data pulverizer wrote: Yes, I'll do a blog or something on GitHub and link it. It would be nice if you could get it published on the Dlang blog [1]. One usually get paid for that. Contact Mike Parker. [1] https://blog.dlang.org Started uploading the code and writing the article for this. The code for each language can be run, see the script.x files in each folder for details and timings. https://github.com/dataPulverizer/KernelMatrixBenchmark Thanks
Re: Template type deduction question
On Thursday, 21 May 2020 at 07:16:11 UTC, Basile B. wrote: On Thursday, 21 May 2020 at 04:46:02 UTC, data pulverizer wrote: I'd like to pass kernel functions using: ``` auto calculateKernelMatrix(K, T)(K!(T) Kernel, Matrix!(T) data) { ... } ``` and call it using `calculateKernelMatrix(myKernel, myData);` but I get a type deduction error and have to call it using `calculateKernelMatrix!(typeof(myKernel), float)(myKernel, myData);` How do I resolve this? The problem is that "K" is a template type parameter [1]. When the compiler deduces the parameter that ends up with a symbol, i.e not a type. To permit a symbol to be deduced you can use a template alias parameter[2] instead: --- struct Matrix(T) {} struct Kernel(T) {} void calculateKernelMatrix(alias K, T)(K!T kernel, Matrix!T data) { } void main() { Matrix!float m; Kernel!float k; calculateKernelMatrix(k,m); // OK } --- However I think that there could be an useful error message, as the current one is of no usefulness. Note that maybe that under the hood there's one but the compiler uses a system of gagging when trying uncertain operations, so that other things can be tried, in case of failure. [1] https://dlang.org/spec/template.html#template_type_parameters [2] https://dlang.org/spec/template.html#aliasparameters I've found that even with a template constraint the diagnostic is sub-optimal, see issue 20851 [1]. [1] https://issues.dlang.org/show_bug.cgi?id=20851
Re: Template type deduction question
On Thursday, 21 May 2020 at 04:46:02 UTC, data pulverizer wrote: I'd like to pass kernel functions using: ``` auto calculateKernelMatrix(K, T)(K!(T) Kernel, Matrix!(T) data) { ... } ``` and call it using `calculateKernelMatrix(myKernel, myData);` but I get a type deduction error and have to call it using `calculateKernelMatrix!(typeof(myKernel), float)(myKernel, myData);` How do I resolve this? The problem is that "K" is a template type parameter [1]. When the compiler deduces the parameter that ends up with a symbol, i.e not a type. To permit a symbol to be deduced you can use a template alias parameter[2] instead: --- struct Matrix(T) {} struct Kernel(T) {} void calculateKernelMatrix(alias K, T)(K!T kernel, Matrix!T data) { } void main() { Matrix!float m; Kernel!float k; calculateKernelMatrix(k,m); // OK } --- However I think that there could be an useful error message, as the current one is of no usefulness. Note that maybe that under the hood there's one but the compiler uses a system of gagging when trying uncertain operations, so that other things can be tried, in case of failure. [1] https://dlang.org/spec/template.html#template_type_parameters [2] https://dlang.org/spec/template.html#aliasparameters
Re: String interpolation
On Thursday, 21 May 2020 at 01:13:27 UTC, Paul Backus wrote: On Wednesday, 20 May 2020 at 23:41:15 UTC, mw wrote: Can we do string interpolation in D now? There's an implementation in the dub package "scriptlike": https://code.dlang.org/packages/scriptlike#string-interpolation Thank you! very nice: // Output: The number 21 doubled is 42! int num = 21; writeln( mixin(interp!"The number ${num} doubled is ${num * 2}!") ); Is there any way to make it shorter? e.g. writeln( s!"The number ${num} doubled is ${num * 2}!" ); i.e how to write this 's'?
Re: Compile and run programs off USB drive
On Thursday, 21 May 2020 at 06:23:10 UTC, Joel wrote: With Windows OS. How would I use my USB drive to compile and run (with 64-bit too)? So far I made a bat file that adds D to %PATH%. There's no zip file of DMD to download, and I didn't get the 7z to work (even with the 7z program?!) - last time I tried. With 64-bit, I don't see what to do there .. edp.bat set PATH=\jpro\dmd2\windows\bin;\jpro\dpro2\Windows\dlls;%PATH% cd jpro\dpro2 Nevermind, I got it working just edited the bat file putting bin64 instead of bin. :)
Re: link error on Windows
On Wednesday, 20 May 2020 at 09:31:38 UTC, Nathan S. wrote: On Tuesday, 19 May 2020 at 04:54:38 UTC, Joel wrote: I tried with DMD32 D Compiler v2.088.1-dirty, and it compiled and created an exe file, but not run (msvcr100.dll not found - and tried to find it on the net without success). DMD 2.089 changed the default linking options. I bet an up-to-date DMD will also work if you invoke it as "dmd -m32mscoff". It should also work if you build it in 64-bit mode. Thanks Nathan. Got it to work using 64-bit. :)
Compile and run programs off USB drive
With Windows OS. How would I use my USB drive to compile and run (with 64-bit too)? So far I made a bat file that adds D to %PATH%. There's no zip file of DMD to download, and I didn't get the 7z to work (even with the 7z program?!) - last time I tried. With 64-bit, I don't see what to do there .. edp.bat set PATH=\jpro\dmd2\windows\bin;\jpro\dpro2\Windows\dlls;%PATH% cd jpro\dpro2