Re: D do not know which function to use apparently

2018-12-11 Thread Narxa via Digitalmars-d-learn
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'

Re: D do not know which function to use apparently

2018-12-11 Thread Narxa via Digitalmars-d-learn
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

Re: imports in a Separate File?

2018-12-11 Thread Steven Schveighoffer via Digitalmars-d-learn
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

Re: imports in a Separate File?

2018-12-11 Thread Ron Tarrant via Digitalmars-d-learn
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

Re: D do not know which function to use apparently

2018-12-11 Thread Steven Schveighoffer via Digitalmars-d-learn
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

Re: D do not know which function to use apparently

2018-12-11 Thread Andrea Fontana via Digitalmars-d-learn
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 =

imports in a Separate File?

2018-12-11 Thread Ron Tarrant via Digitalmars-d-learn
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

Re: How do I install a library?

2018-12-11 Thread Murilo via Digitalmars-d-learn
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.

Re: OT (Was: Re: is(ElementType!(char[2]) == dchar - why?)

2018-12-11 Thread Jonathan M Davis via Digitalmars-d-learn
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. :-/

Re: is(ElementType!(char[2]) == dchar - why?

2018-12-11 Thread Paul Backus via Digitalmars-d-learn
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

Re: is(ElementType!(char[2]) == dchar - why?

2018-12-11 Thread H. S. Teoh via Digitalmars-d-learn
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])) > >     ); > >

Re: How to split strings into AA using phobos

2018-12-11 Thread Andre Pany via Digitalmars-d-learn
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

Re: Why do ints defined in template mixins have garbage values?

2018-12-11 Thread H. S. Teoh via Digitalmars-d-learn
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: >

Re: is(ElementType!(char[2]) == dchar - why?

2018-12-11 Thread rikki cattermole via Digitalmars-d-learn
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:

Re: is(ElementType!(char[2]) == dchar - why?

2018-12-11 Thread bauss via Digitalmars-d-learn
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( >    

Why do ints defined in template mixins have garbage values?

2018-12-11 Thread Johannes Riecken via Digitalmars-d-learn
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

Re: How to split strings into AA using phobos

2018-12-11 Thread Adam D. Ruppe via Digitalmars-d-learn
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: Why do ints defined in template mixins have garbage values?

2018-12-11 Thread Steven Schveighoffer via Digitalmars-d-learn
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); }

Re: Why do ints defined in template mixins have garbage values?

2018-12-11 Thread H. S. Teoh via Digitalmars-d-learn
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

Re: How to split strings into AA using phobos

2018-12-11 Thread Steven Schveighoffer via Digitalmars-d-learn
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

OT (Was: Re: is(ElementType!(char[2]) == dchar - why?)

2018-12-11 Thread H. S. Teoh via Digitalmars-d-learn
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

Re: How to split strings into AA using phobos

2018-12-11 Thread John Chapman via Digitalmars-d-learn
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

How to split strings into AA using phobos

2018-12-11 Thread Arun Chandrasekaran via Digitalmars-d-learn
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

is(ElementType!(char[2]) == dchar - why?

2018-12-11 Thread Denis Feklushkin via Digitalmars-d-learn
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

D do not know which function to use apparently

2018-12-11 Thread Narxa via Digitalmars-d-learn
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):

Re: D do not know which function to use apparently

2018-12-11 Thread Adam D. Ruppe via Digitalmars-d-learn
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.