Re: Can static variables in methods be local for each object?

2021-07-22 Thread cc via Digitalmars-d-learn
On Tuesday, 20 July 2021 at 09:24:07 UTC, Mark Lagodych wrote: Is there a way to make myvar local to each instance of `X` without making it a variable of `X`? Just curious. Sorry if I missed something obvious but is there a specific reason why it isn't just a class member variable? ```d class

Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?

2021-07-22 Thread apz28 via Digitalmars-d-learn
On Thursday, 22 July 2021 at 18:56:43 UTC, Steven Schveighoffer wrote: On 7/22/21 2:38 PM, apz28 wrote: On Wednesday, 21 July 2021 at 20:39:54 UTC, Dukc wrote: On Wednesday, 21 July 2021 at 14:15:51 UTC, Steven Schveighoffer wrote: 2. It's hard for me to see where the null dereference would be

Re: enum true, or 1

2021-07-22 Thread Brian Tiffin via Digitalmars-d-learn
On Thursday, 22 July 2021 at 03:58:38 UTC, Ali Çehreli wrote: On 7/21/21 8:44 PM, Brian Tiffin wrote: > What is the preferred syntax for simple on/off states? I use std.typecons.Flag. It feels very repetitive but that's what we have: import std.typecons; void foo(Flag!"doFilter" doFilter) {

Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?

2021-07-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/22/21 2:38 PM, apz28 wrote: On Wednesday, 21 July 2021 at 20:39:54 UTC, Dukc wrote: On Wednesday, 21 July 2021 at 14:15:51 UTC, Steven Schveighoffer wrote: 2. It's hard for me to see where the null dereference would be in that function (the `bool` implementation is pretty simple). DMD

Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?

2021-07-22 Thread apz28 via Digitalmars-d-learn
On Wednesday, 21 July 2021 at 20:39:54 UTC, Dukc wrote: On Wednesday, 21 July 2021 at 14:15:51 UTC, Steven Schveighoffer wrote: 2. It's hard for me to see where the null dereference would be in that function (the `bool` implementation is pretty simple). -Steve DMD complains about dereference

Re: issue with static foreach

2021-07-22 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 22 July 2021 at 18:16:54 UTC, Tejas wrote: On Thursday, 22 July 2021 at 18:06:07 UTC, Paul Backus wrote: On Thursday, 22 July 2021 at 17:38:09 UTC, Tejas wrote: Why does this work? ```d import std; void main() { mixin("int") a; writeln(a); } ``` You can mix in a type: h

Re: issue with static foreach

2021-07-22 Thread Tejas via Digitalmars-d-learn
On Thursday, 22 July 2021 at 18:06:07 UTC, Paul Backus wrote: On Thursday, 22 July 2021 at 17:38:09 UTC, Tejas wrote: Why does this work? ```d import std; void main() { mixin("int") a; writeln(a); } ``` You can mix in a type: https://dlang.org/spec/type.html#mixin_types Looks like

Re: issue with static foreach

2021-07-22 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 22 July 2021 at 17:38:09 UTC, Tejas wrote: Why does this work? ```d import std; void main() { mixin("int") a; writeln(a); } ``` You can mix in a type: https://dlang.org/spec/type.html#mixin_types

Re: issue with static foreach

2021-07-22 Thread Tejas via Digitalmars-d-learn
On Thursday, 22 July 2021 at 05:57:02 UTC, jfondren wrote: On Thursday, 22 July 2021 at 03:43:44 UTC, someone wrote: ... it compiles no-more: Error: found `End of File` when expecting `}` following compound statement ... what I am doing wrong ? You'll get the same error from this code: ```d

Re: associative array with Parallel

2021-07-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/22/21 1:46 AM, seany wrote: Consider :     int [] ii;     foreach(i,dummy; parallel(somearray)) {   ii ~= somefunc(dummy);     } This is not safe, because all threads are accessing the same array and trying to add values and leading to collision. Correct. You must synchronize o

Re: Do static variables in class consume memory of instances?

2021-07-22 Thread Mark Lagodych via Digitalmars-d-learn
On Thursday, 22 July 2021 at 16:05:41 UTC, Adam D Ruppe wrote: On Thursday, 22 July 2021 at 15:50:59 UTC, Mark Lagodych wrote: Do static variables consume *any* memory in instances, perhaps just for pointers to the variables? nope Or does compiler automatically convert `someObject.someStatic

Re: Do static variables in class consume memory of instances?

2021-07-22 Thread Mark Lagodych via Digitalmars-d-learn
On Thursday, 22 July 2021 at 15:50:59 UTC, Mark Lagodych wrote: Do static variables consume *any* memory in instances, perhaps just for pointers to the variables? Figured it out. Let's try: ```d import std.stdio; class A { static int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

Re: Do static variables in class consume memory of instances?

2021-07-22 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 22 July 2021 at 15:50:59 UTC, Mark Lagodych wrote: Do static variables consume *any* memory in instances, perhaps just for pointers to the variables? nope Or does compiler automatically convert `someObject.someStaticMember` to `SomeClass.someStaticMember`? right

Do static variables in class consume memory of instances?

2021-07-22 Thread Mark Lagodych via Digitalmars-d-learn
[D documentation](https://dlang.org/spec/attribute.html#static) says: Static data has one instance per thread, not one per object. Do static variables consume *any* memory in instances, perhaps just for pointers to the variables? Or does compiler automatically convert `someObject.someStaticMe

Re: catching segfault using try_ catch

2021-07-22 Thread seany via Digitalmars-d-learn
On Thursday, 22 July 2021 at 15:12:37 UTC, Adam D Ruppe wrote: On Thursday, 22 July 2021 at 14:19:37 UTC, seany wrote: how can I specify this with dub ? Probably easiest to just copy the memoryerror.d file from druntime into your dub source dir. I did copy in subfolder /etc/linux. same as t

Re: catching segfault using try_ catch

2021-07-22 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 22 July 2021 at 14:19:37 UTC, seany wrote: how can I specify this with dub ? Probably easiest to just copy the memoryerror.d file from druntime into your dub source dir.

Re: catching segfault using try_ catch

2021-07-22 Thread seany via Digitalmars-d-learn
On Thursday, 22 July 2021 at 14:19:37 UTC, seany wrote: On Tuesday, 13 July 2021 at 17:49:54 UTC, Adam D Ruppe wrote: On Tuesday, 13 July 2021 at 16:52:43 UTC, seany wrote: What will it return to me? true if it succeeded. I want to catch the segfault and a segfault has occured, I want run a

Re: issue with static foreach

2021-07-22 Thread someone via Digitalmars-d-learn
On Thursday, 22 July 2021 at 08:16:43 UTC, Patrick Schluter wrote: What an unreadable mess. Sorry. Indeed LoL !!! I would have done something like that: ```d mixin(format! `case r"%1$s"d : classTickerCustom%1$s lobjTicker%1$s = new classTickerCustom%1$s (lstrSymbolID);

Re: catching segfault using try_ catch

2021-07-22 Thread seany via Digitalmars-d-learn
On Tuesday, 13 July 2021 at 17:49:54 UTC, Adam D Ruppe wrote: On Tuesday, 13 July 2021 at 16:52:43 UTC, seany wrote: What will it return to me? true if it succeeded. I want to catch the segfault and a segfault has occured, I want run a different code at that point. You mean transparently r

Re: issue with static foreach

2021-07-22 Thread someone via Digitalmars-d-learn
On Thursday, 22 July 2021 at 05:57:02 UTC, jfondren wrote: Each individual string has to compile on its own. You'll have to concatenate strings and then mixin them. I forgot about that !

Re: Associative Array with double[][]

2021-07-22 Thread bauss via Digitalmars-d-learn
On Thursday, 22 July 2021 at 03:13:14 UTC, seany wrote: I have a perimeter of a shape, given by a `double [][]` . I want to keep the lengths of various diagonals in another associative array. So, /// define some associative array to keep track of diagonals here.. auto perimeter = n

Re: associative array with Parallel

2021-07-22 Thread seany via Digitalmars-d-learn
On Thursday, 22 July 2021 at 09:02:56 UTC, jfondren wrote: On Thursday, 22 July 2021 at 07:51:04 UTC, seany wrote: OK. Sorry for the bad question : what if i pregenerate every possible key, and fill the associative array where each such key contains some invalid number, say -1 ? You mean wh

Re: issue with static foreach

2021-07-22 Thread Basile B. via Digitalmars-d-learn
On Thursday, 22 July 2021 at 05:57:02 UTC, jfondren wrote: On Thursday, 22 July 2021 at 03:43:44 UTC, someone wrote: ... it compiles no-more: Error: found `End of File` when expecting `}` following compound statement ... what I am doing wrong ? You'll get the same error from this code: ```d

Re: associative array with Parallel

2021-07-22 Thread jfondren via Digitalmars-d-learn
On Thursday, 22 July 2021 at 07:51:04 UTC, seany wrote: OK. Sorry for the bad question : what if i pregenerate every possible key, and fill the associative array where each such key contains some invalid number, say -1 ? You mean where each value contains some invalid number, and the AA's k

Re: associative array with Parallel

2021-07-22 Thread frame via Digitalmars-d-learn
On Thursday, 22 July 2021 at 06:47:52 UTC, Ali Çehreli wrote: But even if it did, we wouldn't want synchronized blocks in parallelization because a synchronized block would run a single thread at a time and nothing would be running in parallel anymore. But it only affects the block, the othe

Re: issue with static foreach

2021-07-22 Thread Patrick Schluter via Digitalmars-d-learn
On Thursday, 22 July 2021 at 03:43:44 UTC, someone wrote: ``` Now, if uncomment those two innocuous commented lines for the if (true == true) block: ```d labelSwitch: switch (lstrExchangeID) { static foreach (sstrExchangeID; gstrExchangeIDs) { mixin(r"case r"d, `"`, sstrExchangeID, `"`,

Re: Initializing a complex dynamic array (with real part from one array, and imaginary from other array)?

2021-07-22 Thread Ali Çehreli via Digitalmars-d-learn
On 7/21/21 2:17 AM, drug wrote: > auto z = zip(x, y) // concatenate two ranges > .map!(a=>Complex!double(a[0],a[1])) // take the current first > element of the first range as the real part and the current first > element of the second range as the imaginary part

Re: associative array with Parallel

2021-07-22 Thread seany via Digitalmars-d-learn
On Thursday, 22 July 2021 at 07:27:52 UTC, jfondren wrote: On Thursday, 22 July 2021 at 07:23:36 UTC, seany wrote: On Thursday, 22 July 2021 at 05:53:01 UTC, jfondren wrote: No. Consider https://programming.guide/hash-tables-open-vs-closed-addressing.html The page says : A key is always

Re: associative array with Parallel

2021-07-22 Thread jfondren via Digitalmars-d-learn
On Thursday, 22 July 2021 at 07:23:36 UTC, seany wrote: On Thursday, 22 July 2021 at 05:53:01 UTC, jfondren wrote: No. Consider https://programming.guide/hash-tables-open-vs-closed-addressing.html The page says : A key is always stored in the bucket it's hashed to. What if my keys are a

Re: associative array with Parallel

2021-07-22 Thread seany via Digitalmars-d-learn
On Thursday, 22 July 2021 at 05:53:01 UTC, jfondren wrote: No. Consider https://programming.guide/hash-tables-open-vs-closed-addressing.html The page says : A key is always stored in the bucket it's hashed to. What if my keys are always unique?