Re: How make DMD auto link imported modules?

2020-04-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 21 April 2020 at 21:36:57 UTC, Marcone wrote: When I create a module, for exemple mymodule.d and import im my main program using "import mymodule" I need add mymodule.d in DMD command line manually. How can make it automatic? dmd -i

Re: Function aliasing problem

2020-04-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/21/20 5:24 PM, Jean-Louis Leroy wrote: I would like to combine them all, e.g.:     alias sst(T) = SS!T.f;     int d = sst(42); // <=> SS!int.f(42) But it fails like this:     aliasstaticfunction.d(23): Error: template `aliasstaticfunction.sst` cannot deduce function from argument typ

How make DMD auto link imported modules?

2020-04-21 Thread Marcone via Digitalmars-d-learn
When I create a module, for exemple mymodule.d and import im my main program using "import mymodule" I need add mymodule.d in DMD command line manually. How can make it automatic?

Re: Option and Result [was Integration tests]

2020-04-21 Thread aliak via Digitalmars-d-learn
On Tuesday, 21 April 2020 at 16:30:15 UTC, Russel Winder wrote: On Mon, 2020-04-20 at 20:19 +, aliak via Digitalmars-d-learn wrote: […] [0]: https://github.com/aliak00/optional Rust has Option and Result, and most languages are rapidly introducing at least Option if not Result – and y

Function aliasing problem

2020-04-21 Thread Jean-Louis Leroy via Digitalmars-d-learn
I can alias a function template: T f(T)(T x) { return x; } alias g = f; int a = g(42); I can alias a static function: struct S { static int f(int i) { return i; } } alias sf = S.f; int b = sf(42); I can alias to a static function in a template instance:

Re: float has too much precision

2020-04-21 Thread Faux Amis via Digitalmars-d-learn
On 2020-04-21 22:10, Steven Schveighoffer wrote: On 4/21/20 3:47 PM, Faux Amis wrote: I'm dumbfounded, why does the following code write '35' on DMD32 D Compiler v2.091.0-dirty? module magic; float magic( float f ) { return f + 35f - f; } void main() { import std.stdio; writel

Re: float has too much precision

2020-04-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/21/20 3:47 PM, Faux Amis wrote: I'm dumbfounded, why does the following code write '35' on DMD32 D Compiler v2.091.0-dirty? module magic; float magic( float f ) {     return f + 35f - f; } void main() {     import std.stdio;     writeln( magic(1_000_000_000f) ); } On run.dlang.io, i

Re: Enum conversion

2020-04-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/21/20 2:09 PM, tsbockman wrote: conversely what is the right way of going the other way: cast(ZoneNumber)1 to!ZoneNumber(1) Use `to` except where you can gaurantee that the input value maps to a valid enum member, because `cast` does not check your work:     writeln(cast(ZoneNumber)17

Re: Enum conversion

2020-04-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/21/20 3:00 PM, Russel Winder wrote: On Tue, 2020-04-21 at 12:59 -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: On 4/21/20 12:03 PM, Russel Winder wrote: Hi, Given an enum: enum ZoneNumber { One = 1, Two = 2, } then which of these is the right way of accessing the

float has too much precision

2020-04-21 Thread Faux Amis via Digitalmars-d-learn
I'm dumbfounded, why does the following code write '35' on DMD32 D Compiler v2.091.0-dirty? module magic; float magic( float f ) { return f + 35f - f; } void main() { import std.stdio; writeln( magic(1_000_000_000f) ); }

Re: Enum conversion

2020-04-21 Thread Russel Winder via Digitalmars-d-learn
On Tue, 2020-04-21 at 18:09 +, tsbockman via Digitalmars-d-learn wrote: > On Tuesday, 21 April 2020 at 16:03:20 UTC, Russel Winder wrote: > > then which of these is the right way of accessing the value? > > > > cast(ubyte)ZoneNumber.One > > to!ubyte(ZoneNumber.One) > > Either is acceptable be

Re: Option and Result [was Integration tests]

2020-04-21 Thread Alex via Digitalmars-d-learn
On Tuesday, 21 April 2020 at 16:30:15 UTC, Russel Winder wrote: On Mon, 2020-04-20 at 20:19 +, aliak via Digitalmars-d-learn wrote: […] [0]: https://github.com/aliak00/optional Rust has Option and Result, and most languages are rapidly introducing at least Option if not Result – and y

Re: Enum conversion

2020-04-21 Thread Russel Winder via Digitalmars-d-learn
On Tue, 2020-04-21 at 12:59 -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 4/21/20 12:03 PM, Russel Winder wrote: > > Hi, > > > > Given an enum: > > > > enum ZoneNumber { > > One = 1, > > Two = 2, > > } > > > > then which of these is the right way of accessing the valu

Re: Can I use dub to build multiple app.d files?

2020-04-21 Thread Selim via Digitalmars-d-learn
On Tuesday, 21 April 2020 at 17:50:03 UTC, Andre Pany wrote: On Tuesday, 21 April 2020 at 16:14:54 UTC, Selim wrote: Hi there. I have been using dub for a while now -maybe 12 months- but I haven't been able to figure out if you can build multiple app.d files with it. Is it possible to use dub r

Re: Enum conversion

2020-04-21 Thread tsbockman via Digitalmars-d-learn
On Tuesday, 21 April 2020 at 16:03:20 UTC, Russel Winder wrote: then which of these is the right way of accessing the value? cast(ubyte)ZoneNumber.One to!ubyte(ZoneNumber.One) Either is acceptable because there is no way that this operation can fail. Using a naked `cast` makes less work for t

Re: Can I use dub to build multiple app.d files?

2020-04-21 Thread Andre Pany via Digitalmars-d-learn
On Tuesday, 21 April 2020 at 16:14:54 UTC, Selim wrote: Hi there. I have been using dub for a while now -maybe 12 months- but I haven't been able to figure out if you can build multiple app.d files with it. Is it possible to use dub run command to build multiple executables in one shot? Maybe

Re: Enum conversion

2020-04-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/21/20 12:03 PM, Russel Winder wrote: Hi, Given an enum: enum ZoneNumber { One = 1, Two = 2, } then which of these is the right way of accessing the value? cast(ubyte)ZoneNumber.One to!ubyte(ZoneNumber.One) I generally do this: ubyte(ZoneNumber.One) conversely what is the

Re: Option and Result [was Integration tests]

2020-04-21 Thread Russel Winder via Digitalmars-d-learn
On Mon, 2020-04-20 at 20:19 +, aliak via Digitalmars-d-learn wrote: > > […] > [0]: https://github.com/aliak00/optional Rust has Option and Result, and most languages are rapidly introducing at least Option if not Result – and yes it is almost certain all this comes from Haskell. Is Option i

Can I use dub to build multiple app.d files?

2020-04-21 Thread Selim via Digitalmars-d-learn
Hi there. I have been using dub for a while now -maybe 12 months- but I haven't been able to figure out if you can build multiple app.d files with it. Is it possible to use dub run command to build multiple executables in one shot? Maybe the question is weird, because dub might not be the tool

Enum conversion

2020-04-21 Thread Russel Winder via Digitalmars-d-learn
Hi, Given an enum: enum ZoneNumber { One = 1, Two = 2, } then which of these is the right way of accessing the value? cast(ubyte)ZoneNumber.One to!ubyte(ZoneNumber.One) conversely what is the right way of going the other way: cast(ZoneNumber)1 to!ZoneNumber(1) I tried: enum ZoneNumb