Re: system's "kill " signal
On Saturday, 5 November 2016 at 02:24:00 UTC, Konstantin Kutsevalov wrote: Hi, is there a way to catch system signal of "kill" command or "shutdown"? During the Run-time: You can register a signal callback, like in this sample (hit CTRL+C once running in a terminal): import std.stdio; import core.sys.posix.signal; bool doQuit; extern(C) void handler(int num) nothrow @nogc @system { printf("Caught signal %d\n",num); doQuit = true; } void main(string[] args) { signal(SIGINT, &handler); while(true) { import core.thread; Thread.sleep(dur!"msecs"(50)); if (doQuit) break; } } After termination: == if (tryWait(PID)[0] == true) then the value carried by tryWait(PID)[1] will tell you if the process has exited because of a signal whatever it's, e.g SIGKILL, SIGTERM, SIGINT, ...
Re: system's "kill " signal
On Saturday, 5 November 2016 at 02:24:00 UTC, Konstantin Kutsevalov wrote: Hi, is there a way to catch system signal of "kill" command or "shutdown"? PS: are there some other ways also to send signals to running a D application? have a look in std.process I don't think you can catch kill.
Re: Calling std.variant.visit from a pure function
On Friday, 4 November 2016 at 23:38:47 UTC, sarn wrote: I suggest trying it with the latest dmd and filing a bug report. Taking a quick look at the library code (https://github.com/dlang/phobos/blob/master/std/variant.d), it *seems* like everything uses templates and functions returning auto, so the pureness of visit should be inferred if possible. Just tried it with 2.072, and I get the same error, so I've submitted a bug report: https://issues.dlang.org/show_bug.cgi?id=16662
Re: is there "this"?
On Thursday, 3 November 2016 at 13:40:11 UTC, Steven Schveighoffer wrote: On 11/2/16 4:43 AM, Jonathan M Davis via Digitalmars-d-learn In the case of the original post, however, you *need* to use this.value, as the parameter masks the member of the same name. Using 'this' removes ambiguity. This is a typical pattern seen in many languages. Often the intuitive name of a member is the same name as you want for the parameter of the constructor. -Steve I'd like to use "this" because when I see something like "this.pumpurum = 10;" then I understand that "pumpurum" is property of class and not some local variable :)
system's "kill " signal
Hi, is there a way to catch system signal of "kill" command or "shutdown"? PS: are there some other ways also to send signals to running a D application?
Re: Calling std.variant.visit from a pure function
On Friday, 4 November 2016 at 02:56:07 UTC, Paul Backus wrote: When I compile this (using DMD 2.069 on Debian Linux), I get an error saying that I can't call visit from a pure function. This is surprising, since all visit does (in theory) is call the provided functions, and all of _them_ are pure. My question is, is this an unavoidable limitation of visit's implementation, or is there a way to work around this? I get the same error with 2.071. (I haven't installed the new dmd yet.) I suggest trying it with the latest dmd and filing a bug report. Taking a quick look at the library code (https://github.com/dlang/phobos/blob/master/std/variant.d), it *seems* like everything uses templates and functions returning auto, so the pureness of visit should be inferred if possible.
Re: not callable error
On Friday, 4 November 2016 at 14:37:04 UTC, bluphantom91 wrote: On Friday, 4 November 2016 at 02:59:49 UTC, Paul Backus wrote: On Friday, 4 November 2016 at 02:28:17 UTC, bluphantom91 wrote: Hello, I am trying to finish up a group project but I am running into a small problem. I keep getting an error about fgetc not being callable. The purpose of my program is to count the number of characters in a file. Any bit of help is appreciated! Here's my code: import std.stdio; import std.file; import std.string; Since you're using the C library stdio functions, you should import core.stdc.stdio ok I added that in, but now its giving me this: function core.stdc.stdio.getc (shared(_IO_FILE)* stream) is not callable using argument types (File) Am I just using getc the wrong way? Try something like this: ... ch = getc(file.getFP); ... https://dlang.org/phobos/std_stdio.html#.File.getFP bye, lobo
Re: not callable error
On Friday, 4 November 2016 at 14:37:04 UTC, bluphantom91 wrote: On Friday, 4 November 2016 at 02:59:49 UTC, Paul Backus wrote: On Friday, 4 November 2016 at 02:28:17 UTC, bluphantom91 wrote: Hello, I am trying to finish up a group project but I am running into a small problem. I keep getting an error about fgetc not being callable. The purpose of my program is to count the number of characters in a file. Any bit of help is appreciated! Here's my code: import std.stdio; import std.file; import std.string; Since you're using the C library stdio functions, you should import core.stdc.stdio ok I added that in, but now its giving me this: function core.stdc.stdio.getc (shared(_IO_FILE)* stream) is not callable using argument types (File) Am I just using getc the wrong way? You're mixing Phobos' `File` object and C's FILE stream. You're passing the `File` to getc which expects FILE. Also, if there's no specific reason, you should prefer the Phobos' file (which doesn't work with getc from C, as it would require obtaining the C stream from Phobos object, which would not be the best idea).
Re: check instance of nested variadic template
On Friday, 4 November 2016 at 15:50:36 UTC, Gianni Pisetta wrote: Hi all, I am having issues finding a solution for this, i want to check if an alias is an istance of a variadic template nested in another variadic template. [...] there is some sort of workaround? Thanks, Gianni Hello, I'm not sure that's exactly what you want but check this: template A(As...) { template B(Bs...) { } } alias BI = A!(1,2).B!(3,4,5); import std.traits; template NestedTemplateArgsOf(alias T) { alias NestedTemplateArgsOf = TemplateArgsOf!(__traits(parent, T)); } alias Bs = TemplateArgsOf!BI; alias As = NestedTemplateArgsOf!BI; static if (is(typeof(BI) == typeof(A!As.B!Bs))) { pragma(msg, "for the win"); } The missing key was NestedTemplateArgsOf. With it you can solve the problem.
check instance of nested variadic template
Hi all, I am having issues finding a solution for this, i want to check if an alias is an istance of a variadic template nested in another variadic template. Here is an example: template A(As...) { template B(Bs...) { } } alias BI = A!(1,2).B!(3,4,5); Now i want to test if BI is an istance of A.B, but i can't do something like this: static if ( is( BI == A!As.B!Bs, As..., Bs... ) ) { // Do Something } there is some sort of workaround? Thanks, Gianni
Re: Combining "chunkBy" and "until" algorithms
On Friday, 4 November 2016 at 08:04:12 UTC, Jacob Carlborg wrote: Currently I'm using a standard for loop iterating over the lines. I'm always looking at the current line and the next line. When the current line is the standard pattern and the next line is is not, I do a separate loop until I see a standard pattern again, collecting the lines with the non-standard pattern in an array. Could you filter [1] for the non standard pattern? Filter is lazy, so will only start looking for the next when the current one has been "handled". [1] https://dlang.org/phobos/std_algorithm_iteration.html#.filter
Re: What is the simplest way of doing @nogc string concatenation?
On Friday, 4 November 2016 at 14:56:46 UTC, Guillaume Piolat wrote: On Friday, 4 November 2016 at 14:55:27 UTC, Guillaume Piolat wrote: On Thursday, 3 November 2016 at 18:54:14 UTC, Gary Willoughby wrote: What is the simplest way of doing @nogc string concatenation? I use sprintf + zero-terminated strings (or a RAII struct to convert slices to ZT strings). Example with the the useful "%.s" format: https://github.com/AuburnSounds/dplug/blob/1037d8a99a6ac730f4d6cc56806dddc83bce07ed/client/dplug/client/client.d#L442 That way you don't have to add the terminal '\0' but be cautious: this will still stop on zero byte. most of the time it doesn't matter, but...
Re: What is the simplest way of doing @nogc string concatenation?
On Friday, 4 November 2016 at 14:55:27 UTC, Guillaume Piolat wrote: On Thursday, 3 November 2016 at 18:54:14 UTC, Gary Willoughby wrote: What is the simplest way of doing @nogc string concatenation? I use sprintf + zero-terminated strings (or a RAII struct to convert slices to ZT strings). Example with the the useful "%.s" format: https://github.com/AuburnSounds/dplug/blob/1037d8a99a6ac730f4d6cc56806dddc83bce07ed/client/dplug/client/client.d#L442 That way you don't have to add the terminal '\0'
Re: What is the simplest way of doing @nogc string concatenation?
On Thursday, 3 November 2016 at 18:54:14 UTC, Gary Willoughby wrote: What is the simplest way of doing @nogc string concatenation? I use sprintf + zero-terminated strings (or a RAII struct to convert slices to ZT strings).
Re: not callable error
On Friday, 4 November 2016 at 02:59:49 UTC, Paul Backus wrote: On Friday, 4 November 2016 at 02:28:17 UTC, bluphantom91 wrote: Hello, I am trying to finish up a group project but I am running into a small problem. I keep getting an error about fgetc not being callable. The purpose of my program is to count the number of characters in a file. Any bit of help is appreciated! Here's my code: import std.stdio; import std.file; import std.string; Since you're using the C library stdio functions, you should import core.stdc.stdio ok I added that in, but now its giving me this: function core.stdc.stdio.getc (shared(_IO_FILE)* stream) is not callable using argument types (File) Am I just using getc the wrong way?
(Solved) Re: Compilation phobos errors with DMD 2.071,2.072 or dub
On Thursday, 3 November 2016 at 14:52:26 UTC, Ozan (ONS) wrote: Hi, with a fresh Ubuntu 16.10 installation using "Hello, World" I got a list of following errors like: /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libphobos2.a(thread_256_713.o): relocation R_X86_64_32 against symbol `_D6object9Throwable7__ClassZ' can not be used when making a shared object; recompile with -fPIC Example: Using dmd 2.071 and dub; dub init appName; compile appName with dub. Or direct with dmd What I'm missing? Any hints? Thanks & Regards, Ozan Solved through changing content of /etc/dmd.conf to [Environment32] DFLAGS=-I/usr/include/dmd/phobos -I/usr/include/dmd/druntime/import -L-L/usr/lib/i386-linux-gnu -L--export-dynamic -fPIC -defaultlib=libphobos2.so [Environment64] DFLAGS=-I/usr/include/dmd/phobos -I/usr/include/dmd/druntime/import -L-L/usr/lib/x86_64-linux-gnu -L--export-dynamic -fPIC -defaultlib=libphobos2.so Thanks for the hints, Ozan
Combining "chunkBy" and "until" algorithms
I have a file with a bunch of lines I want to process. I want to process these lines line by line. Most of these lines have the same pattern. Some of the lines have a different pattern. I want to bundle those lines, which have a non-standard pattern, together with the last line that had the standard pattern. The number of lines with a non-standard pattern is unknown. Are there some algorithms in Phobos that can help with this? Maybe an algorithm combining "chunkBy" and "until" could do it? Currently I'm using a standard for loop iterating over the lines. I'm always looking at the current line and the next line. When the current line is the standard pattern and the next line is is not, I do a separate loop until I see a standard pattern again, collecting the lines with the non-standard pattern in an array. -- /Jacob Carlborg
Re: Error: function std.stdio.setmode is not accessible from module a
On Wednesday, 2 November 2016 at 11:17:49 UTC, Jonathan M Davis wrote: version(DIGITAL_MARS_STDIO) extern(C) int setmode(int, int) nothrow @nogc; else version(MICROSOFT_STDIO) { extern(C) int _setmode(int, int) nothrow @nogc; alias setmode = _setmode; } It really should be put in druntime though. - Jonathan M Davis In case someone else needs this, here is a possible binding: version(CRuntime_DigitalMars) { extern(C) int setmode(int, int) nothrow @nogc; } else version(CRuntime_Microsoft) { extern(C) int _setmode(int, int) nothrow @nogc; alias setmode = _setmode; } (DIGITAL_MARS_STDIO and MICROSOFT_STDIO seem to be internal to std.stdio)