Vibe.D - log requests and responses
Hi, Is there an easy way to log all incoming requests and outgoing responses (and perhaps processing time, wait time, etc) in Vibe.D? Thanks, Saurabh
Re: How to declare function with the same call signature as another?
On Thursday, 24 November 2016 at 02:52:05 UTC, Tofu Ninja wrote: On Thursday, 24 November 2016 at 02:11:21 UTC, ketmar wrote: On Thursday, 24 November 2016 at 00:51:01 UTC, Tofu Ninja wrote: Even with std.traits, you can't know which arguments are variadic. sure, you can. see http://dpldocs.info/experimental-docs/std.traits.variadicFunctionStyle.html that will return variadic style. and the only argument that can be variadic is last. it is enough to reconstruct the signature. Oh well that is my bad, for some reason I was under the impression that there could be more than one typesafe variadic. Still I think the way all of this currently works is very misleading, certainly there is lots of code out there trying to replicate call signatures but are doing it wrong. Having Parameters!(fun) capture things like ref is only going to mislead people(like me!) into thinking it is enough. here i agree. ;-) still, i can't think out a better way to do that. if you have any solid (or at least semi-solid ;-) ideas, feel free to start a new thread, we love bikeshedding! ;-)
Re: How to declare function with the same call signature as another?
On Thursday, 24 November 2016 at 02:11:21 UTC, ketmar wrote: On Thursday, 24 November 2016 at 00:51:01 UTC, Tofu Ninja wrote: Even with std.traits, you can't know which arguments are variadic. sure, you can. see http://dpldocs.info/experimental-docs/std.traits.variadicFunctionStyle.html that will return variadic style. and the only argument that can be variadic is last. it is enough to reconstruct the signature. Oh well that is my bad, for some reason I was under the impression that there could be more than one typesafe variadic. Still I think the way all of this currently works is very misleading, certainly there is lots of code out there trying to replicate call signatures but are doing it wrong. Having Parameters!(fun) capture things like ref is only going to mislead people(like me!) into thinking it is enough.
Re: the best language I have ever met(?)
On Friday, 18 November 2016 at 17:54:52 UTC, Igor Shirkalin wrote: The simpler - the better. After reading "D p.l." by A.Alexandrescu two years ago I have found my past dream. It's theory to start with. That book should be read at least two times especially if you have asm/c/c++/python3/math/physics background, and dealt with Watcom/Symantec C/C++ compilers (best to Walter Bright) with very high optimization goal. No stupid questions, just doing things. That was preface. Now I have server written in D for C++ pretty ancient client. Most things are three times shorter in size and clear (@clear? suffix). All programming paradigms were used. I have the same text in russian, but who has bothered russian(s)? The meaning of all of that is: powerfull attractive language with sufficient infrastructure with future. Just use it. [...] My English is Bad than yours. I am mot russian(s)、、、I am Chinese.
Re: How to declare function with the same call signature as another?
On Thursday, 24 November 2016 at 00:51:01 UTC, Tofu Ninja wrote: Even with std.traits, you can't know which arguments are variadic. sure, you can. see http://dpldocs.info/experimental-docs/std.traits.variadicFunctionStyle.html that will return variadic style. and the only argument that can be variadic is last. it is enough to reconstruct the signature.
Re: How to declare function with the same call signature as another?
On Thursday, 24 November 2016 at 00:36:54 UTC, ketmar wrote: On Thursday, 24 November 2016 at 00:19:04 UTC, Tofu Ninja wrote: You still can't replicate a function with this. you can, by using std.traits and string mixins. Even with std.traits, you can't know which arguments are variadic. The only way to actually replicate a function is with string mixins and parsing the stringof of the function you want to replicate. This (ref int) thing does not help one bit and will only trick people into thinking they are properly replicating the call signature when they are not.
Re: A simplification of the RvalueRef idiom
On Thursday, 24 November 2016 at 00:35:39 UTC, TheGag96 wrote: The thing that gets me more is "return" as a function attribute. I see it under "MemberFunctionAttribute" in the grammar but I can't find an explanation for its use anywhere... YOU ARE NOT SUPPOSED TO KNOW THIS. DON'T LIVE YOUR PLACE, WE SENT A VAN FOR YOU.
Re: A simplification of the RvalueRef idiom
On Tuesday, 22 November 2016 at 13:06:27 UTC, Nordlöw wrote: On Monday, 21 November 2016 at 20:04:51 UTC, Ali Çehreli wrote: mixin template RvalueRef()// <-- DOES NOT TAKE A PARAMETER ANY MORE { alias T = typeof(this); static assert (is(T == struct)); @nogc @safe ref const(T) byRef() const pure nothrow return Why do you need to qualify `byRef` as pure nothrow when it's a template? The thing that gets me more is "return" as a function attribute. I see it under "MemberFunctionAttribute" in the grammar but I can't find an explanation for its use anywhere...
Re: How to declare function with the same call signature as another?
On Thursday, 24 November 2016 at 00:19:04 UTC, Tofu Ninja wrote: You still can't replicate a function with this. you can, by using std.traits and string mixins.
Re: How to declare function with the same call signature as another?
On Thursday, 24 November 2016 at 00:15:07 UTC, ketmar wrote: On Thursday, 24 November 2016 at 00:04:51 UTC, Tofu Ninja wrote: On Wednesday, 23 November 2016 at 23:21:53 UTC, ketmar wrote: On Wednesday, 23 November 2016 at 23:02:30 UTC, Tofu Ninja wrote: Being able to get an alias to (ref int) seems like a bug. you are unable to alias it, `ref` will be erased on aliasing. the only way to retain it is to have a tuple with it. that trick aliases *function* *argument* *tuple*, not a single type. yeah, `ref` is very special beast. but it is still type modifier. ;-) Unless I can write "alias refint = ref int;", this should not be a feature at all... how did anyone think this is a good idea. Seriously I used to love D but now it's just a mess of hacks... either this, or you won't be able to replicate function with it's exact args; you won't be able to even check if some arg is ref. but not having `ref int` as a valid type declaration has it's reasons. You still can't replicate a function with this. No way to replicate or even know if a parameter is variadic. No way to replicate the ref on the return. No way to replicate the linkage or attributes of the function. This is a hack that solves nothing.
Re: How to declare function with the same call signature as another?
On Thursday, 24 November 2016 at 00:04:51 UTC, Tofu Ninja wrote: On Wednesday, 23 November 2016 at 23:21:53 UTC, ketmar wrote: On Wednesday, 23 November 2016 at 23:02:30 UTC, Tofu Ninja wrote: Being able to get an alias to (ref int) seems like a bug. you are unable to alias it, `ref` will be erased on aliasing. the only way to retain it is to have a tuple with it. that trick aliases *function* *argument* *tuple*, not a single type. yeah, `ref` is very special beast. but it is still type modifier. ;-) Unless I can write "alias refint = ref int;", this should not be a feature at all... how did anyone think this is a good idea. Seriously I used to love D but now it's just a mess of hacks... either this, or you won't be able to replicate function with it's exact args; you won't be able to even check if some arg is ref. but not having `ref int` as a valid type declaration has it's reasons.
Re: How to declare function with the same call signature as another?
On Wednesday, 23 November 2016 at 23:21:53 UTC, ketmar wrote: On Wednesday, 23 November 2016 at 23:02:30 UTC, Tofu Ninja wrote: Being able to get an alias to (ref int) seems like a bug. you are unable to alias it, `ref` will be erased on aliasing. the only way to retain it is to have a tuple with it. that trick aliases *function* *argument* *tuple*, not a single type. yeah, `ref` is very special beast. but it is still type modifier. ;-) Unless I can write "alias refint = ref int;", this should not be a feature at all... how did anyone think this is a good idea. Seriously I used to love D but now it's just a mess of hacks...
Re: How to declare function with the same call signature as another?
On Wednesday, 23 November 2016 at 23:02:30 UTC, Tofu Ninja wrote: Being able to get an alias to (ref int) seems like a bug. you are unable to alias it, `ref` will be erased on aliasing. the only way to retain it is to have a tuple with it. that trick aliases *function* *argument* *tuple*, not a single type. yeah, `ref` is very special beast. but it is still type modifier. ;-)
Re: How to declare function with the same call signature as another?
On Wednesday, 23 November 2016 at 22:48:17 UTC, ketmar wrote: On Wednesday, 23 November 2016 at 22:28:57 UTC, Tofu Ninja wrote: On Wednesday, 23 November 2016 at 22:19:28 UTC, ketmar wrote: On Wednesday, 23 November 2016 at 22:14:25 UTC, Tofu Ninja wrote: What is a (ref int)? A tuple with "ref int" as its only member? Since when is ref int a type? it is "type with modifier", like "const int" or "immutable int". Since when has ref been a type qualifier? It has always been a parameter/function attribute. which is technically type qualifier. it just forbidden (in grammar) to use it anywhere except arg declaration. Maybe the compiler sees it as a type qualifier, but it is not listed as a type qualifier and does not behave like a type qualifier in any sense. For example typeof will never return "ref int" but will return "const int", auto will never infer ref but can infer const, you can pass const(int) into a template but can never pass ref(int) into a template(even with that hack I posted before, the ref gets striped). Being able to get an alias to (ref int) seems like a bug.
Re: How to declare function with the same call signature as another?
On Wednesday, 23 November 2016 at 22:28:57 UTC, Tofu Ninja wrote: On Wednesday, 23 November 2016 at 22:19:28 UTC, ketmar wrote: On Wednesday, 23 November 2016 at 22:14:25 UTC, Tofu Ninja wrote: What is a (ref int)? A tuple with "ref int" as its only member? Since when is ref int a type? it is "type with modifier", like "const int" or "immutable int". Since when has ref been a type qualifier? It has always been a parameter/function attribute. which is technically type qualifier. it just forbidden (in grammar) to use it anywhere except arg declaration.
Re: How to declare function with the same call signature as another?
On Wednesday, 23 November 2016 at 22:19:28 UTC, ketmar wrote: On Wednesday, 23 November 2016 at 22:14:25 UTC, Tofu Ninja wrote: What is a (ref int)? A tuple with "ref int" as its only member? Since when is ref int a type? it is "type with modifier", like "const int" or "immutable int". Since when has ref been a type qualifier? It has always been a parameter/function attribute.
Re: spam in bugzilla
I've been marking the accounts as spam and moving the bugs to a specific spam product/category. The last few days have been unusual. If it keeps up, I'll investigate ways of potentially dealing with it better, but I really don't want to add friction to the signup process. It's hard enough to get people to report bugs in general, I don't want to make it harder. On 11/23/2016 11:09 AM, Jonathan M Davis via Digitalmars-d-learn wrote: On Wednesday, November 23, 2016 13:31:45 Steven Schveighoffer via Digitalmars-d-learn wrote: See here: https://issues.dlang.org/show_bug.cgi?id=16737 I don't want to close/change anything, because the guy's email is the reporter, and he'll get any updates. Is there a way to mark something as spam so it gets deleted, and so there are no emails sent to the reporter? If there is, it probably requires Brad to do it. - Jonathan M Davis
Re: How to declare function with the same call signature as another?
On Wednesday, 23 November 2016 at 22:14:25 UTC, Tofu Ninja wrote: What is a (ref int)? A tuple with "ref int" as its only member? Since when is ref int a type? it is "type with modifier", like "const int" or "immutable int".
Re: How to declare function with the same call signature as another?
On Sunday, 20 November 2016 at 12:06:15 UTC, Tofu Ninja wrote: On Sunday, 20 November 2016 at 11:52:01 UTC, Tofu Ninja wrote: ... Also does not include function linkage :/ Because of the lack of response, I am going to guess there is no way to do this cleanly. Guess I am going to have to break out the trusty old mixin to get this working. Also wtf is this... how does this even make sense? template make_ref(T){ static if(is(void delegate(ref T) ftype == delegate) && is(ftype P == function)) alias make_ref = P; else static assert(false); } void main(){ import std.stdio; writeln(make_ref!int.stringof); // (ref int) } What is a (ref int)? A tuple with "ref int" as its only member? Since when is ref int a type?
Re: Switch ignores case (?)
On Wednesday, 23 November 2016 at 22:00:58 UTC, Steven Schveighoffer wrote: I can't see why you need to deal with the glue layer at all -- just tell the glue layer that it's a list of strings and not dstrings ;) 'cause that is how s2ir.d is done in dmd. ;-) it actually sorts *objects*, and objects knows how to order 'emselves. at this stage it is not trivial to treat objects as byte arrays (easy, but not a one-liner). sure, other compilers may do that differently, and it doesn't really matter how exactly the code for switch is generated until it works correctly. ;-)
Re: Switch ignores case (?)
On 11/23/16 4:44 PM, ketmar wrote: On Wednesday, 23 November 2016 at 21:40:52 UTC, Steven Schveighoffer wrote: So the better way is to sort based on byte array, and just use memcmp for everything. i am not completely sure that this is really better. sorting and generating tables is done in glue layer, which can be different for different codegens. and `.compare` method, that is used for sorting strings may be used in other places too. by introducing something like `switchCompare()` we will add unnecessary complexity to the compiler, will make sort order less obvious, and won't really get significant speedup, as binary search doesn't really do alot of comparisons anyway. I'm not certain of how difficult this will be, or how much risk there is. What I am certain of is that the user doesn't care that the compiler really isn't sorting the strings alphabetically, and that he wants the fastest code possible for a switch statement. I can't see why you need to deal with the glue layer at all -- just tell the glue layer that it's a list of strings and not dstrings ;) I also don't actually know that memcmp is faster than wmemcmp, so maybe there is even an advantage to changing behavior for dstring searching. i thing it is better to be fixed in druntime. This can be a solution, for sure. And in reality, it's not *that* much slower -- you are still doing a binary search. I wonder if there is a "binary search among arrays" algorithm that can be optimized for this. -Steve
Re: Switch ignores case (?)
On Wednesday, 23 November 2016 at 21:40:52 UTC, Steven Schveighoffer wrote: So the better way is to sort based on byte array, and just use memcmp for everything. i am not completely sure that this is really better. sorting and generating tables is done in glue layer, which can be different for different codegens. and `.compare` method, that is used for sorting strings may be used in other places too. by introducing something like `switchCompare()` we will add unnecessary complexity to the compiler, will make sort order less obvious, and won't really get significant speedup, as binary search doesn't really do alot of comparisons anyway. i thing it is better to be fixed in druntime.
Re: Switch ignores case (?)
On Wednesday, 23 November 2016 at 21:31:08 UTC, Steven Schveighoffer wrote: I think it makes the most sense to remove the memcmp, and do binary search based on actual char values. yeah. there is wmemcmp, which can be used to speed up one of the cases ('cause wchar_t has different size on windows and GNU/Linux), as i did in my hackfix. yet i am not sure that wmemcmp is really there on windows in all C runtimes (hence HACKfix ;-).
Re: Switch ignores case (?)
On 11/23/16 2:30 PM, ketmar wrote: On Wednesday, 23 November 2016 at 19:07:49 UTC, Chris wrote: It has something to do with the smart quote, e.g.: it is wrong binary search in `_d_switch_string()`. strings for switch are lexically sorted, and compiler calls `_d_switch_string()` to select one. the thing is that comparison in `_d_switch_string()` is done with `memcmp()`. still not clear? ok, let's see how cases are encoded: body _d_switch_dstring() 'U0027' (ca) table[0] = 1, 'U0027' table[1] = 1, 'U2019' or, in memory: table[0] = 1, 0x27, 0x00 table[1] = 1, 0x19, 0x20 so, memcmp for `table[1]` returns... 1! 'cause 0x27 is greater than 0x19. and binsearch is broken from here on. the same is true for `_d_switch_ustring()`, of course. this can be fixed either by using slow char-by-char comparisons in druntime, or by fixing codegen, so it would sort strings as byte arrays. Oh wow, so this is really an endian issue. On a big endian machine, the code would work. Interesting! I think it makes the most sense to remove the memcmp, and do binary search based on actual char values. Thanks for finding this. -Steve
Re: Switch ignores case (?)
quickfix: diff --git a/src/rt/switch_.d b/src/rt/switch_.d index ec124e3..83572fe 100644 --- a/src/rt/switch_.d +++ b/src/rt/switch_.d @@ -27,6 +27,32 @@ private import core.stdc.string; extern (C): +import core.stdc.wchar_ : wchar_t, wmemcmp; + + +static if (wchar_t.sizeof == wchar.sizeof) { + alias memcmpw = wmemcmp; + int memcmpd (const(void)* s0, const(void)* s1, size_t len) { +while (len--) { + if (int r = *cast(const(int)*)s0-*cast(const(int)*)s1) return (r < 0 ? -1 : 1); + s0 += dchar.sizeof; + s1 += dchar.sizeof; +} +return 0; + } +} else static if (wchar_t.sizeof == dchar.sizeof) { + int memcmpw (const(void)* s0, const(void)* s1, size_t len) { +while (len--) { + if (int r = *cast(const(ushort)*)s0-*cast(const(ushort)*)s1) return (r < 0 ? -1 : 1); + s0 += wchar.sizeof; + s1 += wchar.sizeof; +} +return 0; + } + alias memcmpd = wmemcmp; +} else static assert(0, "wut?!"); + + int _d_switch_string(char[][] table, char[] ca) in { @@ -189,7 +215,7 @@ in { int c; -c = memcmp(table[j - 1].ptr, table[j].ptr, len1 * wchar.sizeof); +c = memcmpw(table[j - 1].ptr, table[j].ptr, len1); assert(c < 0); // c==0 means a duplicate } } @@ -205,7 +231,7 @@ out (result) for (auto i = 0u; i < table.length; i++) { if (table[i].length == ca.length) -{ c = memcmp(table[i].ptr, ca.ptr, ca.length * wchar.sizeof); +{ c = memcmpw(table[i].ptr, ca.ptr, ca.length); assert(c != 0); } } @@ -218,7 +244,7 @@ out (result) assert(i < table.length); if (table[i].length == ca.length) { -c = memcmp(table[i].ptr, ca.ptr, ca.length * wchar.sizeof); +c = memcmpw(table[i].ptr, ca.ptr, ca.length); if (c == 0) { assert(i == result); @@ -253,7 +279,7 @@ body auto c = cast(sizediff_t)(ca.length - pca.length); if (c == 0) { -c = memcmp(ca.ptr, pca.ptr, ca.length * wchar.sizeof); +c = memcmpw(ca.ptr, pca.ptr, ca.length); if (c == 0) { //printf("found %d\n", mid); return cast(int)mid; @@ -317,7 +343,7 @@ in assert(len1 <= len2); if (len1 == len2) { -auto c = memcmp(table[j - 1].ptr, table[j].ptr, len1 * dchar.sizeof); +auto c = memcmpd(table[j - 1].ptr, table[j].ptr, len1); assert(c < 0); // c==0 means a duplicate } } @@ -331,7 +357,7 @@ out (result) for (auto i = 0u; i < table.length; i++) { if (table[i].length == ca.length) -{ auto c = memcmp(table[i].ptr, ca.ptr, ca.length * dchar.sizeof); +{ auto c = memcmpd(table[i].ptr, ca.ptr, ca.length); assert(c != 0); } } @@ -344,7 +370,7 @@ out (result) assert(i < table.length); if (table[i].length == ca.length) { -auto c = memcmp(table[i].ptr, ca.ptr, ca.length * dchar.sizeof); +auto c = memcmpd(table[i].ptr, ca.ptr, ca.length); if (c == 0) { assert(i == result); @@ -379,7 +405,7 @@ body auto c = cast(sizediff_t)(ca.length - pca.length); if (c == 0) { -c = memcmp(ca.ptr, pca.ptr, ca.length * dchar.sizeof); +c = memcmpd(ca.ptr, pca.ptr, ca.length); if (c == 0) { //printf("found %d\n", mid); return cast(int)mid; -- 2.9.2
Re: Switch ignores case (?)
On Wednesday, 23 November 2016 at 20:49:01 UTC, Chris wrote: Actually, I came across a compiler message that gave me something like \x19\x20 which I found odd. This sure needs fixing. After all, it's quite a basic feature. So it's back to the old `if` again (for now). yeah, until this is fixed, `switch` over wstring/dstring can be considered completely broken, and better be avoided. `switch` over normal string is unaffected, of course.
How to get the name for a Tid
std.concurrency contains the register function to associate a name with a Tid. This is stored internally in an associative array namesByTid. I see no accessors for this. Is there a way to get to the associated names of a Tid? Thanks, Christian
Re: Switch ignores case (?)
On Wednesday, 23 November 2016 at 19:30:01 UTC, ketmar wrote: On Wednesday, 23 November 2016 at 19:07:49 UTC, Chris wrote: It has something to do with the smart quote, e.g.: it is wrong binary search in `_d_switch_string()`. strings for switch are lexically sorted, and compiler calls `_d_switch_string()` to select one. the thing is that comparison in `_d_switch_string()` is done with `memcmp()`. still not clear? ok, let's see how cases are encoded: body _d_switch_dstring() 'U0027' (ca) table[0] = 1, 'U0027' table[1] = 1, 'U2019' or, in memory: table[0] = 1, 0x27, 0x00 table[1] = 1, 0x19, 0x20 so, memcmp for `table[1]` returns... 1! 'cause 0x27 is greater than 0x19. and binsearch is broken from here on. the same is true for `_d_switch_ustring()`, of course. this can be fixed either by using slow char-by-char comparisons in druntime, or by fixing codegen, so it would sort strings as byte arrays. Actually, I came across a compiler message that gave me something like \x19\x20 which I found odd. This sure needs fixing. After all, it's quite a basic feature. So it's back to the old `if` again (for now).
Re: the best language I have ever met(?)
On Wednesday, 23 November 2016 at 19:15:52 UTC, Jonathan M Davis wrote: It's nice, but it's non-standard. So, it seems to me that using it is just going to lead to problems like you ran into in this thread where you posted an example that wasn't valid D, and it'll make you that much more annoyed when you have to write code that _is_ standard D and can't use your enhancements. So, I really think that it would be better if you just used standard D, but obviously, that's up to you. for me, it is easier to "vanilize" the code later (if i need to, at all). yeah, sometimes non-vanilla code sneaks to where it doesn't belong, but it is rare, and doesn't invalidate the things that makes my life easier while i developing my projects. ;-) as i am unemployed now, i don't care if somebody is able to compile my code anymore.
Linking g++ compiled object files
For example, i have test.cpp: #include void test() { printf("test\n"); } And test.d: import std.stdio; extern (C++) void test(); void main() { test(); readln(); } How i should compile test.cpp using g++ to link it normally?
Re: Switch ignores case (?)
On Wednesday, 23 November 2016 at 19:07:49 UTC, Chris wrote: It has something to do with the smart quote, e.g.: it is wrong binary search in `_d_switch_string()`. strings for switch are lexically sorted, and compiler calls `_d_switch_string()` to select one. the thing is that comparison in `_d_switch_string()` is done with `memcmp()`. still not clear? ok, let's see how cases are encoded: body _d_switch_dstring() 'U0027' (ca) table[0] = 1, 'U0027' table[1] = 1, 'U2019' or, in memory: table[0] = 1, 0x27, 0x00 table[1] = 1, 0x19, 0x20 so, memcmp for `table[1]` returns... 1! 'cause 0x27 is greater than 0x19. and binsearch is broken from here on. the same is true for `_d_switch_ustring()`, of course. this can be fixed either by using slow char-by-char comparisons in druntime, or by fixing codegen, so it would sort strings as byte arrays.
Re: Switch ignores case (?)
On Wednesday, November 23, 2016 19:07:49 Chris via Digitalmars-d-learn wrote: > (I think I marked it as "P1" (default option), maybe it's "P2", > didn't know what to choose) AFAIK, there are no devs that pay any attention to those. Some attention is paid to regression vs enhancement vs etc. But the priority field really doesn't mean anything for how D bugs get fixed or who fixes what when. - Jonathan M Davis
Re: the best language I have ever met(?)
On Wednesday, November 23, 2016 18:58:55 ketmar via Digitalmars-d-learn wrote: > On Wednesday, 23 November 2016 at 18:54:35 UTC, Igor Shirkalin > > wrote: > > On Tuesday, 22 November 2016 at 00:08:05 UTC, ketmar wrote: > >> On Monday, 21 November 2016 at 23:49:27 UTC, burjui wrote: > >>> Though I would argue that it's better to use '_' instead of > >>> '$' to denote deduced fixed size, it seems more obvious to me: > >>> > >>> int[_] array = [ 1, 2, 3 ]; > >> > >> alas, `_` is valid identifier, so `enum _ = 42; int[_] a;` is > >> perfectly valid. dollar is simply most logical non-identifier > >> character. > > > > We can define static array without counting the elements as > > following: > > > > > > enum array_ = [1u,2,3,4]; > > uint[array_.length] static_array = array_; > > there are workarounds, of course. yet i'll take mine `uint[$] a = > [1u,2,3,4];` over that quoted mess at any time, without second > thought. ;-) It's nice, but it's non-standard. So, it seems to me that using it is just going to lead to problems like you ran into in this thread where you posted an example that wasn't valid D, and it'll make you that much more annoyed when you have to write code that _is_ standard D and can't use your enhancements. So, I really think that it would be better if you just used standard D, but obviously, that's up to you. We really should add a helper for this to std.typecons though. Maybe I'll try and do something for it this holidy weekend... - Jonathan M Davis
Re: spam in bugzilla
On Wednesday, November 23, 2016 13:31:45 Steven Schveighoffer via Digitalmars-d-learn wrote: > See here: https://issues.dlang.org/show_bug.cgi?id=16737 > > I don't want to close/change anything, because the guy's email is the > reporter, and he'll get any updates. Is there a way to mark something as > spam so it gets deleted, and so there are no emails sent to the reporter? If there is, it probably requires Brad to do it. - Jonathan M Davis
Re: Switch ignores case (?)
On Wednesday, 23 November 2016 at 18:34:28 UTC, Steven Schveighoffer wrote: Please file here: https://issues.dlang.org/enter_bug.cgi I think this has been there forever. Happens in 2.040 too (the earliest dmd I have on my system). -Steve Here it is: https://issues.dlang.org/show_bug.cgi?id=16739 (I think I marked it as "P1" (default option), maybe it's "P2", didn't know what to choose) It has something to do with the smart quote, e.g.: import std.array; import std.conv; import std.stdio; void main() { auto tokens = to!(dchar[][])(["D"d, "’"d, "Addario"d, "'"d, "."d]); // Or use this below: //~ dstring[] tokens = ["D"d, "’"d, "Addario"d, "'"d]; while (!tokens.empty) { switch (tokens[0]) { case "\u2019"d: writeln("Apostrophe smart " ~ tokens[0]); break; case "\u0027"d: writeln("Apostrophe straight " ~ tokens[0]); break; case "D"d: writeln("Letter 'D'"); break; case "."d: writeln("fullstop " ~ tokens[0]); break; default: writeln("Other " ~ tokens[0]); break; } tokens = tokens[1..$]; } } prints: Letter 'D' Other ’ // <== not expected Other Addario Apostrophe straight ' fullstop . Both LDC and DMD produce the same error. I discovered this while writing a tokenizer. It is a bit upsetting, because it is really an essential thing. The workaround for now would be if (token[0] == "\u2019"d) goto Wherever; which works, by the way.
Re: the best language I have ever met(?)
On Wednesday, 23 November 2016 at 18:54:35 UTC, Igor Shirkalin wrote: On Tuesday, 22 November 2016 at 00:08:05 UTC, ketmar wrote: On Monday, 21 November 2016 at 23:49:27 UTC, burjui wrote: Though I would argue that it's better to use '_' instead of '$' to denote deduced fixed size, it seems more obvious to me: int[_] array = [ 1, 2, 3 ]; alas, `_` is valid identifier, so `enum _ = 42; int[_] a;` is perfectly valid. dollar is simply most logical non-identifier character. We can define static array without counting the elements as following: enum array_ = [1u,2,3,4]; uint[array_.length] static_array = array_; there are workarounds, of course. yet i'll take mine `uint[$] a = [1u,2,3,4];` over that quoted mess at any time, without second thought. ;-)
Re: the best language I have ever met(?)
On Tuesday, 22 November 2016 at 00:08:05 UTC, ketmar wrote: On Monday, 21 November 2016 at 23:49:27 UTC, burjui wrote: Though I would argue that it's better to use '_' instead of '$' to denote deduced fixed size, it seems more obvious to me: int[_] array = [ 1, 2, 3 ]; alas, `_` is valid identifier, so `enum _ = 42; int[_] a;` is perfectly valid. dollar is simply most logical non-identifier character. We can define static array without counting the elements as following: enum array_ = [1u,2,3,4]; uint[array_.length] static_array = array_;
Re: Switch ignores case (?)
On 11/23/16 1:03 PM, Chris wrote: On Wednesday, 23 November 2016 at 17:33:04 UTC, Steven Schveighoffer wrote: I tested this locally with different ideas. This definitely looks like a codegen bug. I was able to reduce it to: void main() { switch("'"d) { case "'"d: writeln("a"); break; case "’"d: writeln("b"); break; default: writeln("default"); } } prints "default" What seems to fix it is removing the case statement for the "smart apostrophe". So I'd look there for where the bug is triggering. Yep, removing one of the two cases works. I tried it with different versions of dmd back to 2.070.0, and it always gives me the same (wrong) result. I haven't tried ldc yet. Please file here: https://issues.dlang.org/enter_bug.cgi I think this has been there forever. Happens in 2.040 too (the earliest dmd I have on my system). -Steve
spam in bugzilla
See here: https://issues.dlang.org/show_bug.cgi?id=16737 I don't want to close/change anything, because the guy's email is the reporter, and he'll get any updates. Is there a way to mark something as spam so it gets deleted, and so there are no emails sent to the reporter? -Steve
Re: Switch ignores case (?)
On Wednesday, 23 November 2016 at 17:33:04 UTC, Steven Schveighoffer wrote: I tested this locally with different ideas. This definitely looks like a codegen bug. I was able to reduce it to: void main() { switch("'"d) { case "'"d: writeln("a"); break; case "’"d: writeln("b"); break; default: writeln("default"); } } prints "default" What seems to fix it is removing the case statement for the "smart apostrophe". So I'd look there for where the bug is triggering. -Steve Yep, removing one of the two cases works. I tried it with different versions of dmd back to 2.070.0, and it always gives me the same (wrong) result. I haven't tried ldc yet.
Re: Switch ignores case (?)
On 11/23/16 11:28 AM, Chris wrote: Only one of the two cases is considered. What am I doing wrong? ` import std.array; import std.conv; import std.stdio; void main() { auto tokens = to!(dchar[][])(["D"d, "’"d, "Addario"d, "'"d]); // Or use this below: //~ dstring[] tokens = ["D"d, "’"d, "Addario"d, "'"d]; while (!tokens.empty) { switch (tokens[0]) { case "\u2019"d: writeln("Apostrophe smart " ~ tokens[0]); break; case "\u0027"d: writeln("Apostrophe straight " ~ tokens[0]); break; default: writeln("Other " ~ tokens[0]); break; } tokens = tokens[1..$]; } } ` Prints: Other D Apostrophe smart ’ Other Addario Other ' I would have expected: Other D Apostrophe smart ’ Other Addario Apostrophe straight ' <== expected I tested this locally with different ideas. This definitely looks like a codegen bug. I was able to reduce it to: void main() { switch("'"d) { case "'"d: writeln("a"); break; case "’"d: writeln("b"); break; default: writeln("default"); } } prints "default" What seems to fix it is removing the case statement for the "smart apostrophe". So I'd look there for where the bug is triggering. -Steve
Re: Curl namelookup_time
On Wednesday, 23 November 2016 at 13:59:29 UTC, Adam D. Ruppe wrote: On Wednesday, 23 November 2016 at 08:24:46 UTC, Andre Pany wrote: [...] curl_easy_getinfo expects the C handle, CURL*, but you are passing it the D struct, Curl. [...] Thank you Adam. I will create a bug report and also an enhancement request. Getting the the time values is quite cumbersome:) Kind regards André
Switch ignores case (?)
Only one of the two cases is considered. What am I doing wrong? ` import std.array; import std.conv; import std.stdio; void main() { auto tokens = to!(dchar[][])(["D"d, "’"d, "Addario"d, "'"d]); // Or use this below: //~ dstring[] tokens = ["D"d, "’"d, "Addario"d, "'"d]; while (!tokens.empty) { switch (tokens[0]) { case "\u2019"d: writeln("Apostrophe smart " ~ tokens[0]); break; case "\u0027"d: writeln("Apostrophe straight " ~ tokens[0]); break; default: writeln("Other " ~ tokens[0]); break; } tokens = tokens[1..$]; } } ` Prints: Other D Apostrophe smart ’ Other Addario Other ' I would have expected: Other D Apostrophe smart ’ Other Addario Apostrophe straight ' <== expected
Re: Is there a way to identfy Windows version?
On Tuesday, 22 November 2016 at 15:48:36 UTC, rumbu wrote: On Tuesday, 22 November 2016 at 11:00:52 UTC, Bauss wrote: [...] Obtaining the true Windows version is tricky starting with Windows 8. Be careful when using GetVersionEx, it's deprecated. VerifyVersionInfo is more reliable, but it will not return a version greater than Windows 8 if your application does not embed a specific manifest. The dirty way to obtain the true Windows version without embedding a manifest, it's to check for the availability of specific functions. Another way is to parse HLKM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Product Name. And finally NetServerGetInfo is your best bet, but it's not guaranteed to work in the future version of Windows. What I really care about is if it works in current versions. Thanks though, I'll see which solution fits the best to my project.
Re: Curl namelookup_time
On Wednesday, 23 November 2016 at 08:24:46 UTC, Andre Pany wrote: Curl curl; curl_easy_getinfo(, CurlInfo.namelookup_time, ); curl_easy_getinfo expects the C handle, CURL*, but you are passing it the D struct, Curl. I don't understand why this even compiles, it should give an invalid argument type error let me guess, it has `alias void CURL`... hey look, there it is: http://dpldocs.info/experimental-docs/source/etc.c.curl.d.html#L110 thanks, zero typechecks. It really should be an opaque struct. Lemme guess too, it was a typedef in C. https://github.com/curl/curl/blob/master/include/curl/curl.h#L102 gee, typedef and alias aren't the same! This is a bug. A REALLY common bug. Anyway, as to your specific instance, the D Curl struct has no public function to return the underlying C handle. To use the C functions, you'll have to create them using C functions too.
Re: Sending Tid in a struct
On 03/03/2012 18:35, Timon Gehr wrote: > On 03/03/2012 12:09 PM, Nicolas Silva wrote: >> Hi, >> >> I'm trying to send structs using std.concurrency. the struct contains >> a Tid (the id of the sender) so that the receiver can send an answer. >> >> say: >> >> struct Foo >> { >>Tid tid; >>string str; >> } >> >> // ... >> >> Foo f = { >>tid: thisTid, >>str: "hello!" >> }; >> std.concurrency.send(someThread, f); >> // /usr/include/d/dmd/phobos/std/concurrency.d(465): Error: static >> assert "Aliases to mutable thread-local data not allowed." >> // hello.d(15):instantiated from here: send!(Foo) >> >> However, I can send a Tid if I pass it directly as a parameter of the >> send function instead of passing it within a struct. >> >> Is this a bug ? It looks like so to me but I guess I could have missed >> something. >> >> thanks in advance, >> >> Nicolas > > Yes, this seems to be a bug. > > Workaround: > > struct Foo{ > string s; > Tid id; > } > > void foo(){ > Foo foo; > receive((Tuple!(string,"s",Tid,"id") bar){foo=Foo(bar.s,bar.id);}); > } > > void main(){ > auto id = spawn(); > id.send("string",id); > ... > } I had a similar problem with this an it seems this is still a bug with dmd 2.072. best regards, christian
Curl namelookup_time
Hi, I try to get some cUrl measurements like name lookup time. pragma(lib, "curl"); import std.stdio, std.net.curl, etc.c.curl; void main() { Curl curl; curl.initialize(); curl.set(CurlOption.url, "https://www.google.com;); curl.perform(); double d; curl_easy_getinfo(, CurlInfo.namelookup_time, ); writeln(d); } While the cUrl console application return values like "0,015", this coding returns values like "9.71874e-311". Where is the bug? Kind regards André
Re: Memory allocation failed. Why?
On Tuesday, 22 November 2016 at 15:53:39 UTC, Steven Schveighoffer wrote: On 11/21/16 11:53 AM, ag0aep6g wrote: Thank you very much for explaining such a difficult and slippery situation.