Re: Struct initialization has no effect or error?

2019-10-02 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 3 October 2019 at 04:57:44 UTC, mipri wrote: On Thursday, 3 October 2019 at 04:33:26 UTC, Brett wrote: I was trying to avoid such things since X is quite long in name. Not a huge deal... and I do not like the syntax because it looks like a constructor call. It is a constructor ca

Re: Using algorithms with ranges

2019-10-02 Thread mipri via Digitalmars-d-learn
On Thursday, 3 October 2019 at 05:20:47 UTC, mipri wrote: It'd be nicer to do compose a range over iota, as in iota(1, 10).newThingWithHistory but I don't know how to do that yet. I guess c.f. std.range.retro This is a bit better: #! /usr/bin/env rdmd import std.stdio; auto withHistory(R

Re: Why is it difficult to reference arrays in structs?

2019-10-02 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 3 October 2019 at 04:32:52 UTC, Brett wrote: Ok, fine! auto r = &x.a; Now r is a reference, great! No, r is a pointer, not a reference. D does not have reference variables. But now the semantics of using the array completely change and errors abound! Probably because yo

Re: Using algorithms with ranges

2019-10-02 Thread mipri via Digitalmars-d-learn
On Thursday, 3 October 2019 at 04:33:10 UTC, Brett wrote: I routinely have to generate data using points sequentially and refer to previous points in the data set, maybe even search them. I also may have to break up the algorithm in to parts. I'd like to get more in to ranges but I simply do n

Re: Struct initialization has no effect or error?

2019-10-02 Thread mipri via Digitalmars-d-learn
On Thursday, 3 October 2019 at 04:33:26 UTC, Brett wrote: I was trying to avoid such things since X is quite long in name. Not a huge deal... and I do not like the syntax because it looks like a constructor call. It is a constructor call, though. You can define your own as well: #! /usr/bin

Re: Why is it difficult to reference arrays in structs?

2019-10-02 Thread mipri via Digitalmars-d-learn
On Thursday, 3 October 2019 at 04:32:52 UTC, Brett wrote: struct Y { double q; } struct X { Y[] a; } X x; auto r = x.a; r is not a reference?!?! Arrays are (ptr,length) pairs. r is a copy of them: #! /usr/bin/env rdmd import std.stdio; struct X { int[] a; } void main() { aut

Using algorithms with ranges

2019-10-02 Thread Brett via Digitalmars-d-learn
I routinely have to generate data using points sequentially and refer to previous points in the data set, maybe even search them. I also may have to break up the algorithm in to parts. I'd like to get more in to ranges but I simply do not use them much because I don't know all the fancy stuff

Re: Struct initialization has no effect or error?

2019-10-02 Thread Brett via Digitalmars-d-learn
On Wednesday, 2 October 2019 at 17:54:20 UTC, H. S. Teoh wrote: On Wed, Oct 02, 2019 at 05:37:57PM +, Brett via Digitalmars-d-learn wrote: struct X { int a; } X[1] x; x[0] = {3}; or x[0] = {a:3}; fails; This works: x[0] = X(123); Should the syntax not extend to the case of

Why is it difficult to reference arrays in structs?

2019-10-02 Thread Brett via Digitalmars-d-learn
struct Y { double q; } struct X { Y[] a; } X x; auto r = x.a; r is not a reference?!?! When updating x.a, r is not updated ;/ [I'm not sure if it just creates a slice or what] Ok, fine! auto r = &x.a; Now r is a reference, great!. But now the semantics of using the array completely chan

Re: C++ base constructor call vs. D's

2019-10-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, October 2, 2019 11:22:40 AM MDT Just Dave via Digitalmars-d- learn wrote: > I was reading the C++ to D page, and came across this little bit > about when to call the base class constructor: > > "It's superior to C++ in that the base constructor call can be > flexibly placed anywhere i

Re: How to find what is causing a closure allocation

2019-10-02 Thread Boris Carvajal via Digitalmars-d-learn
On Wednesday, 2 October 2019 at 15:19:43 UTC, John Colvin wrote: I have a function that allocates a closure somewhere in it (as shown by the result of -profile=gc). I can't make the function nogc as it calls a lot of other GC using code. profilegc.log only gives me the line number of the fun

Re: C++ base constructor call vs. D's

2019-10-02 Thread kinke via Digitalmars-d-learn
On Wednesday, 2 October 2019 at 17:22:40 UTC, Just Dave wrote: I was reading the C++ to D page, and came across this little bit about when to call the base class constructor: Isn't there some inherent danger of not calling the base constructor first? The object's fields are pre-initialized

Re: Struct initialization has no effect or error?

2019-10-02 Thread Andre Pany via Digitalmars-d-learn
On Wednesday, 2 October 2019 at 18:35:39 UTC, mipri wrote: On Wednesday, 2 October 2019 at 17:37:57 UTC, Brett wrote: X y = {3}; works fine. So one has to do x[0] = y; You could initialize x all at once. Complete example: import std.stdio; struct Point { int x, y; string

Re: Struct initialization has no effect or error?

2019-10-02 Thread mipri via Digitalmars-d-learn
On Wednesday, 2 October 2019 at 17:37:57 UTC, Brett wrote: X y = {3}; works fine. So one has to do x[0] = y; You could initialize x all at once. Complete example: import std.stdio; struct Point { int x, y; string toString() { import std.format : format;

Re: Struct initialization has no effect or error?

2019-10-02 Thread mipri via Digitalmars-d-learn
On Wednesday, 2 October 2019 at 17:54:20 UTC, H. S. Teoh wrote: On Wed, Oct 02, 2019 at 05:37:57PM +, Brett via Digitalmars-d-learn wrote: struct X { int a; } X[1] x; x[0] = {3}; or x[0] = {a:3}; fails; This works: x[0] = X(123); I'd knew I'd gotten the impression from som

Re: Struct initialization has no effect or error?

2019-10-02 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 02, 2019 at 05:37:57PM +, Brett via Digitalmars-d-learn wrote: > struct X { int a; } > > X[1] x; > > x[0] = {3}; > > or > > x[0] = {a:3}; > > fails; This works: x[0] = X(123); > Should the syntax not extend to the case of array assignment? Arguably it should. But i

Struct initialization has no effect or error?

2019-10-02 Thread Brett via Digitalmars-d-learn
struct X { int a; } X[1] x; x[0] = {3}; or x[0] = {a:3}; fails; Should the syntax not extend to the case of array assignment? This avoids a double copy. X y = {3}; works fine. So one has to do x[0] = y;

C++ base constructor call vs. D's

2019-10-02 Thread Just Dave via Digitalmars-d-learn
I was reading the C++ to D page, and came across this little bit about when to call the base class constructor: "It's superior to C++ in that the base constructor call can be flexibly placed anywhere in the derived constructor." Isn't there some inherent danger of not calling the base constr

Re: Using D for Raspberry Pi expirements

2019-10-02 Thread Dave Chapman via Digitalmars-d-learn
On Sunday, 29 September 2019 at 11:26:41 UTC, aberba wrote: On Thursday, 26 September 2019 at 17:26:25 UTC, Dave Chapman wrote: [...] your code... can you push it to GitHub so I can check it out? I haven't used GitHub or git. Is there some other way?

Re: How to find what is causing a closure allocation

2019-10-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 2 October 2019 at 15:19:43 UTC, John Colvin wrote: profilegc.log only gives me the line number of the function signature, which doesn't give me any hint as to where in the function the closure is allocated. You'll wanna check any nested functions declared in that function. Kinda

How to find what is causing a closure allocation

2019-10-02 Thread John Colvin via Digitalmars-d-learn
I have a function that allocates a closure somewhere in it (as shown by the result of -profile=gc). I can't make the function nogc as it calls a lot of other GC using code. profilegc.log only gives me the line number of the function signature, which doesn't give me any hint as to where in th

A Strong Betting Experience on Free Slots

2019-10-02 Thread panhasky via Digitalmars-d-learn
Do you remember at one-arm-bandits, the casino systems that have becharmed bettors with its unbelievable audios symbols and positively with its payouts? From mechanical slots machines to advanced video slots machines, slots games have developed however have deal to stay its specific smart luck

Re: want to know precise GC benchmarks

2019-10-02 Thread a11e99z via Digitalmars-d-learn
On Wednesday, 2 October 2019 at 06:41:28 UTC, Rainer Schuetze wrote: thanks for the detailed answer