Re: Top level associative arrays

2017-05-02 Thread ANtlord via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 16:34:15 UTC, H. S. Teoh wrote: On Tue, May 02, 2017 at 02:37:20PM +, ANtlord via Digitalmars-d-learn wrote: On Tuesday, 2 May 2017 at 12:41:01 UTC, Jacob Carlborg wrote: > > Note that when declared as "enum", all places it's > referenced, a new associative array

Re: Porting Java code to D that uses << and >>> operators

2017-05-02 Thread Faux Amis via Digitalmars-d-learn
On 2017-05-02 18:55, TheGag96 wrote: On Tuesday, 2 May 2017 at 07:42:45 UTC, Jacob Carlborg wrote: From that link: "Note that dmd currently does not comply with left to right evaluation of function arguments and AssignExpression". This is something I've never understood. Why doesn't DMD

Re: Porting Java code to D that uses << and >>> operators

2017-05-02 Thread Faux Amis via Digitalmars-d-learn
On 2017-05-02 09:42, Jacob Carlborg wrote: On 2017-05-02 01:27, Faux Amis wrote: To me, this [2] suggests otherwise ;) Or am I missing something? [2] https://dlang.org/spec/expression.html#order-of-evaluation From that link: "Note that dmd currently does not comply with left to right

Re: problem with std.variant rounding

2017-05-02 Thread Nick Sabalausky (Abscissa) via Digitalmars-d-learn
On 05/02/2017 04:02 AM, Suliman wrote: I need co concatenate string with variant type (I am doing SQL query). What is the best way to put it? It's seems that if I am doing simple `replace` string sql = "..." sql.replace(`37.72308`, to!string(cargpspoint.lon)).replace(`55.47957`,

Re: Member delegate/fp to another member in same object?

2017-05-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 17:08:11 UTC, Juanjo Alvarez wrote: struct S { int someState; void some_foo() { return this. someState;} void delegate() foo; void enable() { foo = _foo; } } That's actually illegal in D. It will compile, but has undefined behavior because the

Re: Member delegate/fp to another member in same object?

2017-05-02 Thread Juanjo Alvarez via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 17:08:11 UTC, Juanjo Alvarez wrote: Example: struct S { int someState; void some_foo() { return this. someState;} void delegate() foo; void enable() { foo = _foo; } } unittest { S s; s.someState = 1; enable(); s.someState = 2; assert(foo ==

Member delegate/fp to another member in same object?

2017-05-02 Thread Juanjo Alvarez via Digitalmars-d-learn
Hi! I would like to have a "proxy" delegate, let's call it "foo" that could point to a method or another, let's call them "fast_foo" or "slow_foo" on the same object. This way depending on some conditions I could switch at runtime from one set of methods to others with a "switchFoo(" fast")

Re: Porting Java code to D that uses << and >>> operators

2017-05-02 Thread TheGag96 via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 07:42:45 UTC, Jacob Carlborg wrote: From that link: "Note that dmd currently does not comply with left to right evaluation of function arguments and AssignExpression". This is something I've never understood. Why doesn't DMD implement the behavior their own

Re: Top level associative arrays

2017-05-02 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 02, 2017 at 02:37:20PM +, ANtlord via Digitalmars-d-learn wrote: > On Tuesday, 2 May 2017 at 12:41:01 UTC, Jacob Carlborg wrote: > > > > Note that when declared as "enum", all places it's referenced, a new > > associative array will be allocated. > > If it is allocated at all

Re: Top level associative arrays

2017-05-02 Thread ANtlord via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 14:37:20 UTC, ANtlord wrote: On Tuesday, 2 May 2017 at 12:41:01 UTC, Jacob Carlborg wrote: Note that when declared as "enum", all places it's referenced, a new associative array will be allocated. If it is allocated at all places I can move initialization to

Re: Top level associative arrays

2017-05-02 Thread ANtlord via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 12:41:01 UTC, Jacob Carlborg wrote: Note that when declared as "enum", all places it's referenced, a new associative array will be allocated. If it is allocated at all places I can move initialization to module ctor as says evilrat but how can I make an immutable

Re: Top level associative arrays

2017-05-02 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-05-02 09:48, ANtlord wrote: Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss": "qq" ]; void main() {

Re: Top level associative arrays

2017-05-02 Thread evilrat via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 09:50:50 UTC, ANtlord wrote: On Tuesday, 2 May 2017 at 08:24:09 UTC, evilrat wrote: Making enum means that value should be available at compile time and AA's are fully dynamic. But if my memory serves me well, you can declare empty AA and delay initialization. So

Re: Top level associative arrays

2017-05-02 Thread ANtlord via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 08:24:09 UTC, evilrat wrote: Making enum means that value should be available at compile time and AA's are fully dynamic. But if my memory serves me well, you can declare empty AA and delay initialization. So the closest solution is to move initialization of AA to

Re: problem with std.variant rounding

2017-05-02 Thread Suliman via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 08:02:23 UTC, Suliman wrote: On Saturday, 29 April 2017 at 08:57:09 UTC, Petar Kirov [ZombineDev] wrote: On Friday, 28 April 2017 at 18:08:38 UTC, H. S. Teoh wrote: On Fri, Apr 28, 2017 at 04:42:28PM +, via Digitalmars-d-learn wrote: [...]

Re: Top level associative arrays

2017-05-02 Thread evilrat via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 07:48:35 UTC, ANtlord wrote: Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss":

Re: problem with std.variant rounding

2017-05-02 Thread Suliman via Digitalmars-d-learn
On Saturday, 29 April 2017 at 08:57:09 UTC, Petar Kirov [ZombineDev] wrote: On Friday, 28 April 2017 at 18:08:38 UTC, H. S. Teoh wrote: On Fri, Apr 28, 2017 at 04:42:28PM +, via Digitalmars-d-learn wrote: [...] writefln(text("%.", i, "f"), x); [...] There's no need to use text()

Re: Top level associative arrays

2017-05-02 Thread ANtlord via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 07:48:35 UTC, ANtlord wrote: Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss":

Re: Top level associative arrays

2017-05-02 Thread ANtlord via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 07:48:35 UTC, ANtlord wrote: Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss":

Top level associative arrays

2017-05-02 Thread ANtlord via Digitalmars-d-learn
Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss": "qq" ]; void main() { writeln(val); } I solved

Re: Porting Java code to D that uses << and >>> operators

2017-05-02 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-05-02 01:27, Faux Amis wrote: To me, this [2] suggests otherwise ;) Or am I missing something? [2] https://dlang.org/spec/expression.html#order-of-evaluation From that link: "Note that dmd currently does not comply with left to right evaluation of function arguments and