Re: How do I install a library?
On Tuesday, 11 December 2018 at 07:25:49 UTC, Seb wrote: On Monday, 10 December 2018 at 00:18:52 UTC, Murilo wrote: Hi guys, thank you for helping me out here, there is this facebook group for the D language, here we can help and teach each other. It is called Programming in D. Please join. https://www.facebook.com/groups/662119670846705/?ref=bookmarks Please stop this spam. It is not spam, I really created this group, it has 80 members now, I would like more members so we could help each other there rather than here, facebook is a better communication tool than this mailing list. But since you asked me to stop then I will stop.
Re: OT (Was: Re: is(ElementType!(char[2]) == dchar - why?)
On Tuesday, December 11, 2018 2:11:49 PM MST H. S. Teoh via Digitalmars-d- learn wrote: > On Tue, Dec 11, 2018 at 09:02:41PM +, bauss via Digitalmars-d-learn wrote: > > On Tuesday, 11 December 2018 at 18:10:48 UTC, H. S. Teoh wrote: > [...] > > > > Autodecoding raises its ugly head again. :-/ > > [...] > > > Has it ever had anything else? > > LOL... well, we (or some of us) were deceived by its pretty tail for a > while, until we realized that it was just a façade, and Unicode really > didn't work the way we thought it did. Yeah. Auto-decoding came about, because Andrei misunderstood Unicode and thought that code points were complete characters (likely because the Unicode standard weirdly likes to refer to them as characters), and he didn't know about graphemes. At the time, many of us were just as clueless as he was (in many cases, more so), and auto-decoding made sense. You supposedly got full correctness by default and could work around it for increased performance when you needed to (and the standard library did that for you where it mattered, reducing how much you had to care). Walter knew better, but he wasn't involved enough with Phobos development to catch on until it was too late. It's only later when more folks involved came to a fuller understanding of Unicode that auto-decoding started to be panned. For instance, I very much doubt that you would find much from the D community talking about how horrible auto-decoding is back in 2010, whereas you probably could find plenty by 2015, and every time it comes up now, folks complain about it. Previously, folks would get annoyed about the restrictions, but the restrictions made sense with the understanding that code points were the actual characters, and you didn't want code to be chopping them up. But once it became more widely understood that code points were also potentially pieces of characters, you no longer had the same defense against the annoyances caused by how narrow strings are treated, and so it just became annoying. We went from newcomers getting annoyed, but those who understood the reasons behind auto-decoding being fine with it (because it supposedly made their code correct and prevented bugs) to almost everyone involved being annoyed about it. The newcomers who don't understand it still get annoyed by it, but instead of the ones who do understand it telling them about how it's helping keep Unicode handling correct, the folks who understand what's going now tell everyone how terrible auto-decoding is. So, the narrative that auto-decoding is terrible has now become the status quo, whereas before, it was actually considered to be a good thing by the D community at large, because it supposedly ensured Unicode correctness. It was still annoying, but that was because Unicode is annoying. Now, Unicode is still annoying, but auto-decoding is understood to make it even more so without actually helping. The one bright side out of all of this that makes it so that I don't think that auto-decoding is entirely bad is that it shoves the issue in everyone's faces so that everyone is forced to learn at least the basics about Unicode, whereas if we didn't have it, many folks would likely just treat char as a complete character and merrily write code that can't handle Unicode, since that's what usually happens in most programs in most languages (some languages do use the equivalent of wchar for their char, but most code still treats their char type as if it were a complete character). The fact that we have char, wchar, and dchar _does_ help raise the issue on its own, but auto-decoding makes it very hard to ignore. Now, that doesn't mean that I think that we should have auto-decoding (ideally, we'd figure out how to remove it), but the issues that it's caused have resulted in a lot of developers becoming much more knowledgeable about Unicode and therefore more likely to write code that handles Unicode correctly. - Jonathan M Davis
Re: Why do ints defined in template mixins have garbage values?
P.S. Just looked at the disassembly. Seems to be a codegen bug -- the code appears to be trying to lookup local variables (presumably i0 and i1), but somehow the initialization code is missing. --T On Tue, Dec 11, 2018 at 09:09:55PM +, Johannes Riecken via Digitalmars-d-learn wrote: > Code: > > import std.conv; > import std.stdio; > > mixin template genInts() > { > enum arr = [0,1]; > static foreach (t; arr) { > mixin("int i" ~ to!string(t) ~ " = 5;"); > } > } > > void main() { > mixin genInts!(); > writeln(i0); > writeln(i1); > } > > > Expected output: > 5 > 5 > > Actual output is two garbage integer values. -- "If you're arguing, you're losing." -- Mike Thomas
Re: Why do ints defined in template mixins have garbage values?
On 12/11/18 4:09 PM, Johannes Riecken wrote: Code: import std.conv; import std.stdio; mixin template genInts() { enum arr = [0,1]; static foreach (t; arr) { mixin("int i" ~ to!string(t) ~ " = 5;"); } } void main() { mixin genInts!(); writeln(i0); writeln(i1); } Expected output: 5 5 Actual output is two garbage integer values. Looks like a bug to me in static foreach. Using -vcg-ast, it appears that the int definitions do not show up in main. If I add an int using a regular declaration or a straight mixin("int i0 = 5;"); then the variable shows up. -Steve
Re: Why do ints defined in template mixins have garbage values?
On Tue, Dec 11, 2018 at 09:09:55PM +, Johannes Riecken via Digitalmars-d-learn wrote: > Code: > > import std.conv; > import std.stdio; > > mixin template genInts() > { > enum arr = [0,1]; > static foreach (t; arr) { > mixin("int i" ~ to!string(t) ~ " = 5;"); > } > } > > void main() { > mixin genInts!(); > writeln(i0); > writeln(i1); > } > > > Expected output: > 5 > 5 > > Actual output is two garbage integer values. Whoa. That looks like a compiler bug. File a bug here: https://issues.dlang.org/enter_bug.cgi T -- There are two ways to write error-free programs; only the third one works.
OT (Was: Re: is(ElementType!(char[2]) == dchar - why?)
On Tue, Dec 11, 2018 at 09:02:41PM +, bauss via Digitalmars-d-learn wrote: > On Tuesday, 11 December 2018 at 18:10:48 UTC, H. S. Teoh wrote: [...] > > Autodecoding raises its ugly head again. :-/ [...] > Has it ever had anything else? LOL... well, we (or some of us) were deceived by its pretty tail for a while, until we realized that it was just a façade, and Unicode really didn't work the way we thought it did. T -- Notwithstanding the eloquent discontent that you have just respectfully expressed at length against my verbal capabilities, I am afraid that I must unfortunately bring it to your attention that I am, in fact, NOT verbose.
Why do ints defined in template mixins have garbage values?
Code: import std.conv; import std.stdio; mixin template genInts() { enum arr = [0,1]; static foreach (t; arr) { mixin("int i" ~ to!string(t) ~ " = 5;"); } } void main() { mixin genInts!(); writeln(i0); writeln(i1); } Expected output: 5 5 Actual output is two garbage integer values.
Re: is(ElementType!(char[2]) == dchar - why?
On Tuesday, 11 December 2018 at 18:10:48 UTC, H. S. Teoh wrote: On Wed, Dec 12, 2018 at 06:56:46AM +1300, rikki cattermole via Digitalmars-d-learn wrote: On 12/12/2018 6:51 AM, Denis Feklushkin wrote: > import std.stdio; > import std.range.primitives; > > void main() > { > writeln( > typeid(ElementType!(char[2])) > ); > > static assert(is(ElementType!(char[2]) == dchar)); // > why? > } > > ? > > https://run.dlang.io/is/Q74yHm Because docs: https://dlang.org/phobos/std_range_primitives.html#ElementType What you probably want is: https://dlang.org/phobos/std_traits.html#ForeachType Autodecoding raises its ugly head again. :-/ T Has it ever had anything else?
Re: How to split strings into AA using phobos
On 12/11/18 3:20 AM, Arun Chandrasekaran wrote: A typical example would be to split the HTTP query string into an AA. vibe.d has req.queryString, but no convenient wrapper to access it as an AA. Yeah it does: http://vibed.org/api/vibe.http.server/HTTPServerRequest.query -Steve
Re: How to split strings into AA using phobos
On Tuesday, 11 December 2018 at 18:46:27 UTC, Andre Pany wrote: I am not 100% sure but I think query parameters names can occur multiple times in query string. Yes, that's right.
Re: How to split strings into AA using phobos
On Tuesday, 11 December 2018 at 08:20:32 UTC, Arun Chandrasekaran wrote: A typical example would be to split the HTTP query string into an AA. vibe.d has req.queryString, but no convenient wrapper to access it as an AA. http://localhost/hello?name=abc=123 I've got this far. auto arr = req.queryString.splitter('&').map!(a => a.splitter('=')); Thanks I am not 100% sure but I think query parameters names can occur multiple times in query string. Therefore you need an associative array with string as key and string[] array as value. By using associative array you loose the order of the parameters. Whether this is important for query parameters I do not know. Kind regards Andre
Re: is(ElementType!(char[2]) == dchar - why?
On Tuesday, 11 December 2018 at 17:51:56 UTC, Denis Feklushkin wrote: import std.stdio; import std.range.primitives; void main() { writeln( typeid(ElementType!(char[2])) ); static assert(is(ElementType!(char[2]) == dchar)); // why? } ? https://run.dlang.io/is/Q74yHm This is a "feature" called auto decoding. It's explained here: https://tour.dlang.org/tour/en/gems/unicode You can get around it by using .byChar or .byCodeUnit.
Re: is(ElementType!(char[2]) == dchar - why?
On Wed, Dec 12, 2018 at 06:56:46AM +1300, rikki cattermole via Digitalmars-d-learn wrote: > On 12/12/2018 6:51 AM, Denis Feklushkin wrote: > > import std.stdio; > > import std.range.primitives; > > > > void main() > > { > > writeln( > > typeid(ElementType!(char[2])) > > ); > > > > static assert(is(ElementType!(char[2]) == dchar)); // why? > > } > > > > ? > > > > https://run.dlang.io/is/Q74yHm > > Because docs: https://dlang.org/phobos/std_range_primitives.html#ElementType > > What you probably want is: > https://dlang.org/phobos/std_traits.html#ForeachType Autodecoding raises its ugly head again. :-/ T -- It is the quality rather than the quantity that matters. -- Lucius Annaeus Seneca
Re: is(ElementType!(char[2]) == dchar - why?
On 12/12/2018 6:51 AM, Denis Feklushkin wrote: import std.stdio; import std.range.primitives; void main() { writeln( typeid(ElementType!(char[2])) ); static assert(is(ElementType!(char[2]) == dchar)); // why? } ? https://run.dlang.io/is/Q74yHm Because docs: https://dlang.org/phobos/std_range_primitives.html#ElementType What you probably want is: https://dlang.org/phobos/std_traits.html#ForeachType
is(ElementType!(char[2]) == dchar - why?
import std.stdio; import std.range.primitives; void main() { writeln( typeid(ElementType!(char[2])) ); static assert(is(ElementType!(char[2]) == dchar)); // why? } ? https://run.dlang.io/is/Q74yHm
Re: imports in a Separate File?
On Tuesday, 11 December 2018 at 15:39:18 UTC, Steven Schveighoffer wrote: Use public imports in your header file. This will pretend that the symbols imported reside in the module itself. i.e. inside importedStuff.d: public { // 120 import statements } -Steve Thanks, Steve. Works like a charm... but you knew that.
Re: D do not know which function to use apparently
On Tuesday, 11 December 2018 at 15:17:10 UTC, Narxa wrote: Yes, it worked: --- int var = cast(int) floor(sqrt( cast(float) n )); I thought floor already returned an 'int' but I was mistaken. Thank you very much. I think you don't need floor. int var = cast(int)(sqrt(cast(float)n)); or: int var = cast(int)(float(i).sqrt); or: int var = float(i).sqrt.to!int; Andrea
Re: imports in a Separate File?
On 12/11/18 10:27 AM, Ron Tarrant wrote: I ran across a code example (https://github.com/gtkd-developers/GtkD/blob/master/demos/gtkD/TestWindow/TestWindow.d) in which the first ~120 lines are mostly import statements. And it got me wondering... I tried to off-load a bunch of imports into a pseudo-header file — importedStuff.d — and then in the actual code file I just did: import importedStuff; but found myself swimming in undefined identifier errors. Is there a way to do this so I wouldn't have to scroll 120 lines into a file before finding code? Or does this mean I still haven't caught onto what I was told the last time I was on this forum? (And here's a grammar question, just for the heck of it: Why isn't forum spelled with an 'n,' like column?) Use public imports in your header file. This will pretend that the symbols imported reside in the module itself. i.e. inside importedStuff.d: public { // 120 import statements } -Steve
imports in a Separate File?
I ran across a code example (https://github.com/gtkd-developers/GtkD/blob/master/demos/gtkD/TestWindow/TestWindow.d) in which the first ~120 lines are mostly import statements. And it got me wondering... I tried to off-load a bunch of imports into a pseudo-header file — importedStuff.d — and then in the actual code file I just did: import importedStuff; but found myself swimming in undefined identifier errors. Is there a way to do this so I wouldn't have to scroll 120 lines into a file before finding code? Or does this mean I still haven't caught onto what I was told the last time I was on this forum? (And here's a grammar question, just for the heck of it: Why isn't forum spelled with an 'n,' like column?)
Re: D do not know which function to use apparently
On Tuesday, 11 December 2018 at 14:53:02 UTC, Steven Schveighoffer wrote: On 12/11/18 9:47 AM, Narxa wrote: On Tuesday, 11 December 2018 at 14:22:30 UTC, Adam D. Ruppe wrote: On Tuesday, 11 December 2018 at 14:16:05 UTC, Narxa wrote: int var = floor(sqrt(n)) // where 'n' is a 'const int' You can just cast it to float: floor(sqrt( cast(float) n )); and it will work. It produced the following error: Error: cannot implicitly convert expression floor(sqrt(cast(float)n)) of type float to int I am using 'dmd' compiler if it matters. You need to cast the result back to int. -Steve Yes, it worked: --- int var = cast(int) floor(sqrt( cast(float) n )); I thought floor already returned an 'int' but I was mistaken. Thank you very much.
Re: D do not know which function to use apparently
On 12/11/18 9:47 AM, Narxa wrote: On Tuesday, 11 December 2018 at 14:22:30 UTC, Adam D. Ruppe wrote: On Tuesday, 11 December 2018 at 14:16:05 UTC, Narxa wrote: int var = floor(sqrt(n)) // where 'n' is a 'const int' You can just cast it to float: floor(sqrt( cast(float) n )); and it will work. It produced the following error: Error: cannot implicitly convert expression floor(sqrt(cast(float)n)) of type float to int I am using 'dmd' compiler if it matters. You need to cast the result back to int. -Steve
Re: D do not know which function to use apparently
On Tuesday, 11 December 2018 at 14:22:30 UTC, Adam D. Ruppe wrote: On Tuesday, 11 December 2018 at 14:16:05 UTC, Narxa wrote: int var = floor(sqrt(n)) // where 'n' is a 'const int' You can just cast it to float: floor(sqrt( cast(float) n )); and it will work. It produced the following error: Error: cannot implicitly convert expression floor(sqrt(cast(float)n)) of type float to int I am using 'dmd' compiler if it matters.
Re: D do not know which function to use apparently
On Tuesday, 11 December 2018 at 14:16:05 UTC, Narxa wrote: int var = floor(sqrt(n)) // where 'n' is a 'const int' You can just cast it to float: floor(sqrt( cast(float) n )); and it will work.
D do not know which function to use apparently
Hello, people! The following case: --- int var = floor(sqrt(n)) // where 'n' is a 'const int' Produces the following error: - Error: std.math.sqrt called with argument types (const(int)) matches both: /usr/include/dmd/phobos/std/math.d(2067): std.math.sqrt(float x) and: /usr/include/dmd/phobos/std/math.d(2073): std.math.sqrt(real x) Please, could you tell me how do I solve this?! Thank you!
Re: How to split strings into AA using phobos
On Tuesday, 11 December 2018 at 08:20:32 UTC, Arun Chandrasekaran wrote: A typical example would be to split the HTTP query string into an AA. vibe.d has req.queryString, but no convenient wrapper to access it as an AA. http://localhost/hello?name=abc=123 I've got this far. auto arr = req.queryString.splitter('&').map!(a => a.splitter('=')); Thanks req.queryString[req.queryString.indexOf('?') + 1 .. $] .splitter('&') .map!(a => a.splitter('=')) .map!(a => tuple(a.front, a.back)) .assocArray
How to split strings into AA using phobos
A typical example would be to split the HTTP query string into an AA. vibe.d has req.queryString, but no convenient wrapper to access it as an AA. http://localhost/hello?name=abc=123 I've got this far. auto arr = req.queryString.splitter('&').map!(a => a.splitter('=')); Thanks