Re: Checking if a port is listening

2016-03-19 Thread Marc Schütz via Digitalmars-d-learn
Looking at an strace of nmap, it seems it opens a bunch of sockets, puts them into non-blocking mode, calls connect on them (which will return EINPROGRESS), and then uses select(2) to wait for them (in a loop, until all have either been accepted or rejected). select(2) accepts a timeout value,

Re: how to parse a string into a phobos datatype with additional logic

2016-04-07 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 7 April 2016 at 08:06:03 UTC, Puming wrote: On Thursday, 7 April 2016 at 07:45:06 UTC, yawniek wrote: what is the way one is supposed to parse e.g. a double of unixtime (as delived by nginx logs) into a SysTime? currently i'm creating a wrapper struct around SysTime with alias

Re: Checking if a port is listening

2016-03-24 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 23 March 2016 at 21:37:09 UTC, Lucien wrote: When I remove the Thread.sleep, it doesn't find all adresses. Why ? Socket.select() will wait _at most_ 100 msecs. If a socket gets ready before that timeout, it will return immediately. Therefore, you might not get the full

Re: getOverloads, but also include all the imported members

2016-03-24 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 23 March 2016 at 20:54:20 UTC, Yuxuan Shui wrote: Say: module one; void func(int a){} / module two; import one; void func(float a){} Is there a way to get both func() in module two? Add in module two: alias func = one.func;

Re: parsing fastq files with D

2016-03-24 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 24 March 2016 at 08:24:15 UTC, eastanon wrote: On Thursday, 24 March 2016 at 06:34:51 UTC, rikki cattermole wrote: As a little fun thing to do I implemented it for you. It won't allocate. Making this perfect for you. With a bit of work you could make Result have buffers for

Re: Checking if a port is listening

2016-03-19 Thread Marc Schütz via Digitalmars-d-learn
On Saturday, 19 March 2016 at 09:55:13 UTC, Lucien wrote: const int MAX = 64; Socket[] sockets = new Socket[MAX]; string ipb = "192.168.0."; for (int i = 1; i < MAX; i++) { Here's the reason for your SEGV: You need to start at 0, because otherwise `sockets[0]` is `null`. When

Re: Whitch can replace std::bind/boost::bind ?

2016-03-19 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 18 March 2016 at 10:50:34 UTC, Dsby wrote: foreach (i ; 0..4) { auto th = new Thread(delegate(){listRun(i);});//this is erro _thread[i]= th; th.start(); } void listRun(int i) { writeln("i = ", i); // the value is not(0,1,2,3), it all is 2. } I want

Re: mutable keyword

2016-05-22 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 22 May 2016 at 09:42:54 UTC, Jack Applegame wrote: I agree. But I think we need something that allows *logical* const and immutable. Strict binding constness to physical memory constancy is not always necessary and sometimes even harmful. http://wiki.dlang.org/DIP89

Re: Immutable objects and constructor ?

2016-05-20 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 20 May 2016 at 15:07:53 UTC, chmike wrote: The error message is gone, but I now have another compilation error message I don't understand. This is what I have in fact interface Info { . . . } class MyInfos { . . . protected: class Obj : Info { . . . } public:

Re: Compiler silently ignores some method overloads

2016-05-11 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 10 May 2016 at 22:17:00 UTC, pineapple wrote: On Tuesday, 10 May 2016 at 09:57:11 UTC, pineapple wrote: On Monday, 9 May 2016 at 18:56:15 UTC, Peter Häggman wrote: No problem here (tested with everything in a single module). I can't help more. Front end version ? Well, this is

Re: Using shorthand *= leads to unexpected result?

2016-05-15 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 15 May 2016 at 13:01:45 UTC, Michael wrote: It may be that I'm doing something wrong here, but after updating DMD to the latest version, my simulations started producing some very odd results and I think I've pinpointed it to a sign inversion that I was making. Here is some code

Re: Setting a list of values

2016-05-01 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 1 May 2016 at 05:42:00 UTC, Ali Çehreli wrote: On 04/30/2016 10:05 PM, Joel wrote: > This has no effect: > _bars.each!(a => { a._plots.fillColor = Color(255, 180, 0); }); This is a common issue especially for people who know lambdas from other languages. :) Your lambda does not do

Re: Setting a list of values

2016-05-02 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 2 May 2016 at 08:46:31 UTC, Ali Çehreli wrote: On 05/01/2016 12:54 PM, Xinok wrote: > On Sunday, 1 May 2016 at 05:42:00 UTC, Ali Çehreli wrote: >> On 04/30/2016 10:05 PM, Joel wrote: >> > This has no effect: >> > _bars.each!(a => { a._plots.fillColor = Color(255, 180, 0); >> }); >> >>

Re: multithreading profiling

2016-04-18 Thread Marc Schütz via Digitalmars-d-learn
Which platform/OS, dmd version, and command line are you using?

Re: Problem with circular imports of modules with static ctors an immutable variables

2016-04-15 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 15 April 2016 at 05:35:24 UTC, Uranuz wrote: In my program I have error with circular imports of modules with static ctors. So I decided to move ctors in separate file and import it only from the 1st file. But problem is that in the first file I have immutables that should be

Re: Shallow copy object when type is know

2016-04-21 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 19:58:15 UTC, Tofu Ninja wrote: How does D not have shallow copy? Seems like a very basic functionality... You could implement a `dup()` method. `dup` is already used for shallow copying of arrays, why not reuse it for classes (as a convention)?

Re: vibe.d is blocking threads

2016-04-28 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 27 April 2016 at 23:30:10 UTC, Nicholas Wilson wrote: On Wednesday, 27 April 2016 at 13:00:29 UTC, RuZzz wrote: Code: import std.concurrency; import core.thread; //import vibe.http.client; // If uncommented this line, the thread "worker" does not start void

Re: local const functions - bug ?

2016-07-12 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 10 July 2016 at 07:20:29 UTC, Meta wrote: On Friday, 8 July 2016 at 09:01:10 UTC, Marc Schütz wrote: `foo()` is effectively a delegate, therefore `const` applies to the context. AFAIK const on a function can only ever refer to the `this` pointer, but there is no `this` pointer.

Re: How to group similar member functions from different classes?

2016-07-18 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 15 July 2016 at 17:25:23 UTC, cy wrote: On Monday, 20 June 2016 at 16:39:54 UTC, Marc Schütz wrote: Untested: Seems to only work if A and B are both defined in the same file as Foos (defeating the purpose). Putting A and B in a.d and b.d respectively gives me these errors:

Re: local const functions - bug ?

2016-07-08 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 7 July 2016 at 15:02:29 UTC, Jonathan M Davis wrote: On Thursday, July 07, 2016 10:33:39 Basile B. via Digitalmars-d-learn wrote: this compiles without error: struct Foo { int i; void bar() { void foo() const { i = 1; }

Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-05 Thread Marc Schütz via Digitalmars-d-learn
auto concat(T : E[n], E, size_t n)(const E[][] args...) @nogc { size_t offset = 0; T result = void; foreach(arr; args) { result[offset .. offset+arr.length] = arr; offset += arr.length; } assert(offset == result.length); return result; } static immutable

Re: Fiber Concurrency Showcase

2016-09-13 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 13 September 2016 at 10:02:28 UTC, Andrea Fontana wrote: On Tuesday, 13 September 2016 at 09:46:46 UTC, Nordlöw wrote: I would like to experiment with Fibers/Coroutines in D/vibe.d. I'm missing a code example in std.concurrency that highlights an example of using Fibers for

Re: Fiber Concurrency Showcase

2016-09-13 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 13 September 2016 at 09:46:46 UTC, Nordlöw wrote: I would like to experiment with Fibers/Coroutines in D/vibe.d. I'm missing a code example in std.concurrency that highlights an example of using Fibers for massive concurrency. Could anybody show me such a code example or link to a

Re: isRvalue trait

2016-10-10 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 10 October 2016 at 11:46:01 UTC, Nordlöw wrote: At https://github.com/nordlow/phobos-next/blob/master/src/moval.d I've implemented a helper function for creating r-value out of l-values defined as E movedToRvalue(E)(ref E e) { import std.algorithm.mutation : move; E

Re: thisExePath purity

2016-09-20 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 20 September 2016 at 04:17:21 UTC, crimaniak wrote: Hi and thanks all! On Tuesday, 20 September 2016 at 00:43:10 UTC, Jonathan M Davis wrote: immutable string executablePath; shared static this() { import std.file : thisExePath(); executablePath = thisExePath(); }

Re: Problem parsing IPv4/IPv6 addresses with std.socket.parseAddress

2016-09-27 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 27 September 2016 at 09:04:53 UTC, Dsciple wrote: As said, this works fine when tested in isolation, and the compiler only complains when using BindAddress as a member of ConfigParams. Any idea what the problem may be? Or is there maybe a ready to use, high-level library for

Re: Problem parsing IPv4/IPv6 addresses with std.socket.parseAddress

2016-09-28 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 27 September 2016 at 14:57:26 UTC, Dsciple wrote: struct ConfigParams { // ... // Define configuration parameters' static default fields static immutable BindAddresses defaultBindAddresses = BindAddresses([ BindAddress("192.168.2.10") ]); // ... } Yepp, that's

Re: Explicit casting of enum -- intentional restriction?

2016-10-02 Thread Marc Schütz via Digitalmars-d-learn
On Saturday, 1 October 2016 at 20:52:48 UTC, rcorre wrote: I just tried to compile an old project and the following failed: --- enum Paths : string { bitmapDir = "content/image", fontDir = "content/font", soundDir = "content/sound", ... if (Paths.preferences.exists)

Re: weighted round robin

2016-10-19 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 18 October 2016 at 16:43:19 UTC, vino wrote: On Wednesday, 12 October 2016 at 13:44:59 UTC, Erikvv wrote: In your first post you mention it should be weighted, but I see no weights anywhere. Hi Marc, I am at the initial stage of implementing the round robin algorithm and still

Re: opIndexDispatch?

2016-10-14 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 13 October 2016 at 01:09:06 UTC, Ali Çehreli wrote: On 10/10/2016 12:01 PM, Yuxuan Shui wrote: Hi, Why is there no opIndexDispatch for overloading a[x].func() ? I could not understand the question fully but would using an element proxy work? I assume a proxy would indeed

Re: Complex numbers are harder to use than in C

2016-11-19 Thread Marc Schütz via Digitalmars-d-learn
On Saturday, 19 November 2016 at 11:11:36 UTC, Nordlöw wrote: On Saturday, 19 November 2016 at 09:38:38 UTC, Marduk wrote: The difference is that D is more verbose. Am I missing something? Can we have C's behaviour in D? Something like auto I(T)(T im) if (isNumeric!T) { return

Re: Complex numbers are harder to use than in C

2016-11-20 Thread Marc Schütz via Digitalmars-d-learn
On Saturday, 19 November 2016 at 20:08:42 UTC, Marduk wrote: On Saturday, 19 November 2016 at 11:11:36 UTC, Nordlöw wrote: On Saturday, 19 November 2016 at 09:38:38 UTC, Marduk wrote: The difference is that D is more verbose. Am I missing something? Can we have C's behaviour in D? Something

Re: Complex numbers are harder to use than in C

2016-11-20 Thread Marc Schütz via Digitalmars-d-learn
On Saturday, 19 November 2016 at 20:24:09 UTC, Marduk wrote: On Saturday, 19 November 2016 at 12:55:57 UTC, Marc Schütz wrote: On Saturday, 19 November 2016 at 11:11:36 UTC, Nordlöw wrote: On Saturday, 19 November 2016 at 09:38:38 UTC, Marduk wrote: The difference is that D is more verbose. Am

Re: Best approach to handle accented letters

2016-10-28 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 28 October 2016 at 11:24:28 UTC, Alfred Newman wrote: Hello, I'm getting some troubles to replace the accented letters in a given string with their unaccented counterparts. Let's say I have the following input string "très élégant" and I need to create a function to return just

Re: weighted round robin

2016-10-10 Thread Marc Schütz via Digitalmars-d-learn
On Saturday, 8 October 2016 at 22:48:53 UTC, vino wrote: Hi, Can some one guide me on how to implement the weighted round robin, below is what i tried or any other better ways to do it Main Requirement : Incoming socket connection has to be sent to 3 servers in the weighted round robin

Re: Determining if a class has a template function

2016-10-14 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 16:57:50 UTC, Meta wrote: There's also a *very* ugly hack you can do: //A template function's .stringof is of the format name>()() //so match on the number of brackets to determine whether it's a template function or not enum isTemplateFunction =

Re: switch to member

2017-01-14 Thread Marc Schütz via Digitalmars-d-learn
You can utilize a little-known `switch` syntax trick in combination with `foreach`. Because a `foreach` over tuples is unrolled at compile time, it works even if your fields don't have exactly the same types: -- struct Foo { int

Re: Split Real / Float into Mantissa, Exponent, and Base

2017-03-06 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 3 March 2017 at 18:09:02 UTC, Jonathan M. Wilbur wrote: I have tried to come up with a good way to get the mantissa, exponent, and base from a real number, and I just can't come up with a good cross-platform way of doing it. I know about std.math.frexp(), but that function only

Re: GC

2017-07-30 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 30 July 2017 at 09:12:53 UTC, piotrekg2 wrote: I would like to learn more about GC in D. For example can anyone explain why do we need memset(0) here: https://github.com/dlang/phobos/blob/master/std/container/array.d#L356 , doesn't it assume a certain type of GC? What if there is a

Re: Static array * scalar is not working for me

2017-07-30 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 30 July 2017 at 08:18:07 UTC, Danni Coy wrote: The following code is not working for me float[3] f; f[] = abs(f)[] * -1.0f; where abs is a function that returns a float[3]; it complains that f should be attached to some memory. Is it a bug or am I missing something? I cannot

Re: How to call function with variable arguments at runtime?

2017-10-10 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 10 October 2017 at 02:58:45 UTC, Mr. Jonse wrote: I need to store a hetrogeneous array of delegates. How can I do this but still call the function with the appropriate number of parameters at run time? I have the parameters as Variant[] params and a function/delegate

<    1   2