Re: D threading and shared variables

2019-04-07 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 7 April 2019 at 14:08:07 UTC, Archie Allison wrote: This generally works OK when tied to a Console but when link options are changed to be SUBSYSTEM:WINDOWS and ENTRY:mainCRTStartup it rarely does. Manually setting the entry point sounds problematic if no other precautions are ta

Re: D threading and shared variables

2019-04-07 Thread Archie Allison via Digitalmars-d-learn
On Sunday, 7 April 2019 at 17:52:40 UTC, Mike Wey wrote: How are you using the GUI, GTK is not thread safe, all gui function calls should be made from the GUI thread. Last time i checked threadsEnter and threadsLeave didn't work properly on windows. All GUI updates are sent from a worker

Re: Iterate/sort associative array by value?

2019-04-07 Thread Ali Çehreli via Digitalmars-d-learn
On 04/07/2019 08:41 AM, Robert M. Münch wrote: > I have an AA int[ulong] and would like to traverse the AA from biggest > to smallest by value. Is there an elegant way to do this? Because associative array is a data structure to use when the order is not important, it comes down to getting the v

Re: Iterate/sort associative array by value?

2019-04-07 Thread Seb via Digitalmars-d-learn
On Sunday, 7 April 2019 at 18:22:00 UTC, Robert M. Münch wrote: On 2019-04-07 17:16:12 +, Seb said: Then you can do: --- ["a": 1].byPair.array.sort!((a, b) => a.value < a.value).release.each!writeln; --- You'll have a sorted array with key and value props. This seems to be really tric

Re: Iterate/sort associative array by value?

2019-04-07 Thread Seb via Digitalmars-d-learn
On Sunday, 7 April 2019 at 20:02:15 UTC, Seb wrote: On Sunday, 7 April 2019 at 18:22:00 UTC, Robert M. Münch wrote: On 2019-04-07 17:16:12 +, Seb said: Then you can do: --- ["a": 1].byPair.array.sort!((a, b) => a.value < a.value).release.each!writeln; --- You'll have a sorted array wit

Re: Iterate/sort associative array by value?

2019-04-07 Thread Dennis via Digitalmars-d-learn
On Sunday, 7 April 2019 at 18:22:00 UTC, Robert M. Münch wrote: Error: no property sort for type Tuple!(uint, "key", int, "value")[] Did you import it? import std.algorithm;

Re: Iterate/sort associative array by value?

2019-04-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-07 17:16:12 +, Seb said: Then you can do: --- ["a": 1].byPair.array.sort!((a, b) => a.value < a.value).release.each!writeln; --- You'll have a sorted array with key and value props. This seems to be really tricky: int[uint] myArray; foreach(key, value; myArray.byPair.array.s

Re: Iterate/sort associative array by value?

2019-04-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-07 17:35:23 +, bauss said: Import std.array :-/ Thanks... -- Robert M. Münch http://www.saphirion.com smarter | better | faster

Re: D threading and shared variables

2019-04-07 Thread Mike Wey via Digitalmars-d-learn
On 07-04-2019 16:49, Archie Allison wrote: The codebase is a reasonable size so too big (and proprietary) to share. It's always run with a GUI (GTKD), it's just the difference in linking so launching (a)GUI + attached console for stdout.writeln vs. (b)just the GUI window. There's nothing I'd e

Re: Overloads not returning appropriate info. [Field reflunkory]

2019-04-07 Thread Alex via Digitalmars-d-learn
On Sunday, 7 April 2019 at 15:35:46 UTC, FeepingCreature wrote: On Sunday, 7 April 2019 at 03:47:25 UTC, Alex wrote: rules are meant to be broken. No they're not! Almost by definition not! More comprehensively, if you break a rule you take responsibility for the outcome. You wanna use string

Re: Overloads not returning appropriate info. [Field reflunkory]

2019-04-07 Thread Alex via Digitalmars-d-learn
On Sunday, 7 April 2019 at 15:26:47 UTC, Adam D. Ruppe wrote: On Sunday, 7 April 2019 at 03:47:25 UTC, Alex wrote: What you need to tell me is why using .stringof is bad. You have simply conjured up a rule and are stating it but not giving any reason why it is not a good idea to follow when, in

Re: Iterate/sort associative array by value?

2019-04-07 Thread bauss via Digitalmars-d-learn
On Sunday, 7 April 2019 at 16:44:01 UTC, Robert M. Münch wrote: On 2019-04-07 16:24:52 +, Cym13 said: You could use sort to gather the indexes in order then traverse from there: aa.byKey.array.sort!((a, b) => aa[a] That doesn't work: Error: no property array for type Result With a

Re: Iterate/sort associative array by value?

2019-04-07 Thread Seb via Digitalmars-d-learn
On Sunday, 7 April 2019 at 16:44:01 UTC, Robert M. Münch wrote: On 2019-04-07 16:24:52 +, Cym13 said: You could use sort to gather the indexes in order then traverse from there: aa.byKey.array.sort!((a, b) => aa[a] That doesn't work: Error: no property array for type Result With a

Re: == comparison of string literals, and their usage

2019-04-07 Thread diniz via Digitalmars-d-learn
Le 07/04/2019 à 14:23, bauss via Digitalmars-d-learn a écrit : On Saturday, 6 April 2019 at 19:47:14 UTC, lithium iodate wrote: On Saturday, 6 April 2019 at 15:35:22 UTC, diniz wrote: So, I still could store and use and compare string pointers myself [1], and get valid results, meaning: pointer

Re: What's the correct way to interface with a intptr_t?

2019-04-07 Thread bauss via Digitalmars-d-learn
On Sunday, 7 April 2019 at 13:45:15 UTC, Paul Backus wrote: On Sunday, 7 April 2019 at 12:19:10 UTC, bauss wrote: On Saturday, 6 April 2019 at 20:16:06 UTC, Paul Backus wrote: On Saturday, 6 April 2019 at 19:31:15 UTC, Robert M. Münch wrote: I have a C interface that uses a parameter of type in

Re: Iterate/sort associative array by value?

2019-04-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-07 16:24:52 +, Cym13 said: You could use sort to gather the indexes in order then traverse from there: aa.byKey.array.sort!((a, b) => aa[a] That doesn't work: Error: no property array for type Result With a wrapper caching that order and making it transparent as well as

Re: Iterate/sort associative array by value?

2019-04-07 Thread Cym13 via Digitalmars-d-learn
On Sunday, 7 April 2019 at 15:41:51 UTC, Robert M. Münch wrote: I have an AA int[ulong] and would like to traverse the AA from biggest to smallest by value. Is there an elegant way to do this? The only way I can imagine is to create an "reverse" AA of the form ulong[int] and than sort by keys

Re: Alias to struct memembers of a function paramater as a shortcut => need this for XYZ of type void*

2019-04-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.04.19 17:36, Robert M. Münch wrote: The docs state that an alias can either be related to the type or the symbol. Hence, in my case I expected it to be the symbol... The symbol is `X.a`. A field of an instance doesn't make a distinct symbol.

Iterate/sort associative array by value?

2019-04-07 Thread Robert M. Münch via Digitalmars-d-learn
I have an AA int[ulong] and would like to traverse the AA from biggest to smallest by value. Is there an elegant way to do this? The only way I can imagine is to create an "reverse" AA of the form ulong[int] and than sort by keys. Traverse this AA and use the value as the lookup key in the org

Re: Overloads not returning appropriate info. [Field reflunkory]

2019-04-07 Thread FeepingCreature via Digitalmars-d-learn
On Sunday, 7 April 2019 at 03:47:25 UTC, Alex wrote: rules are meant to be broken. No they're not! Almost by definition not! More comprehensively, if you break a rule you take responsibility for the outcome. You wanna use stringof? "Don't use stringof for that." "rules are meant to be broken

Re: Alias to struct memembers of a function paramater as a shortcut => need this for XYZ of type void*

2019-04-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-07 14:05:13 +, ag0aep6g said: You can't make an alias to a field of an object. The alias will be made in relation to the type instead. (If that makes sense. I'm not sure how to phrase it best.) The docs state that an alias can either be related to the type or the symbol. Hence

Re: Overloads not returning appropriate info. [Field reflunkory]

2019-04-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 7 April 2019 at 03:47:25 UTC, Alex wrote: What you need to tell me is why using .stringof is bad. You have simply conjured up a rule and are stating it but not giving any reason why it is not a good idea to follow when, in fact, not following can be shown to be beneficial. You can'

Re: Overloads not returning appropriate info. [Field reflunkory]

2019-04-07 Thread Paul Backus via Digitalmars-d-learn
On 4/6/19 11:47 PM, Alex wrote: > What you need to tell me is why using .stringof is bad. You have simply > conjured up a rule and are stating it but not giving any reason why it > is not a good idea to follow when, in fact, not following can be shown > to be beneficial. I'm not Adam, but I've als

Re: Easiest way to use Linux system C files / tiny C libraries

2019-04-07 Thread James Blachly via Digitalmars-d-learn
On 3/29/19 7:52 PM, H. S. Teoh wrote: On Fri, Mar 29, 2019 at 10:48:47PM +, Chris Katko via Digitalmars-d-learn wrote: ...> There are probably other similar gotchas, but these are the ones off the top of my head. Feel free to ask if you're having trouble correctly translating something fr

Re: D threading and shared variables

2019-04-07 Thread Archie Allison via Digitalmars-d-learn
On Sunday, 7 April 2019 at 14:35:24 UTC, Doc Andrew wrote: When you say it "rarely works" when run as a GUI app (vs console), it makes me think that there's probably a race condition going on, and the extra context switching that takes place in GUI mode makes it more likely. I haven't tried it

Re: Error: template instance `Reflect!(type)` cannot use local `type` as parameter to non-global template `Reflect(Ts...)()`

2019-04-07 Thread Paul Backus via Digitalmars-d-learn
On 4/7/19 1:30 AM, Nicholas Wilson wrote: > On Sunday, 7 April 2019 at 05:24:38 UTC, Alex wrote: >> Error: template instance `Reflect!(type)` cannot use local `type` as >> parameter to non-global template `Reflect(Ts...)()` >> >> mixin(`import `~moduleName!(T)~`;`);    >> mixin(`alias X = T.`~name~

Re: D threading and shared variables

2019-04-07 Thread Doc Andrew via Digitalmars-d-learn
On Sunday, 7 April 2019 at 14:08:07 UTC, Archie Allison wrote: I have written an industrial control program which uses serial ports to communicate with hardware but am having problems, perhaps with shared memory, on Windows. The SerialPort class calls C object-file functions. Transmits are on

Re: Alias to struct memembers of a function paramater as a shortcut => need this for XYZ of type void*

2019-04-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.04.19 14:23, Robert M. Münch wrote: struct X { TYPE a; TYPE b; } myFunc(X _struct){ alias a = _struct.a; a = myOtherFunc(); } X myStruct; myFun(myStruct); This gives an error: need this for a of type void* I don't understand why, because all I want is a shortcut

D threading and shared variables

2019-04-07 Thread Archie Allison via Digitalmars-d-learn
I have written an industrial control program which uses serial ports to communicate with hardware but am having problems, perhaps with shared memory, on Windows. The SerialPort class calls C object-file functions. Transmits are on one thread and receives on another (all within a class derived

Re: What's the correct way to interface with a intptr_t?

2019-04-07 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 7 April 2019 at 12:19:10 UTC, bauss wrote: On Saturday, 6 April 2019 at 20:16:06 UTC, Paul Backus wrote: On Saturday, 6 April 2019 at 19:31:15 UTC, Robert M. Münch wrote: I have a C interface that uses a parameter of type intptr_t. Wondering if size_t is the correct D equivalent? T

Re: == comparison of string literals, and their usage

2019-04-07 Thread bauss via Digitalmars-d-learn
On Saturday, 6 April 2019 at 19:47:14 UTC, lithium iodate wrote: On Saturday, 6 April 2019 at 15:35:22 UTC, diniz wrote: So, I still could store and use and compare string pointers myself [1], and get valid results, meaning: pointer equality implies (literal) string equality. Or am I wrong? The

Alias to struct memembers of a function paramater as a shortcut => need this for XYZ of type void*

2019-04-07 Thread Robert M. Münch via Digitalmars-d-learn
struct X { TYPE a; TYPE b; } myFunc(X _struct){ alias a = _struct.a; a = myOtherFunc(); } X myStruct; myFun(myStruct); This gives an error: need this for a of type void* I don't understand why, because all I want is a shortcut the symbol of the parameter.

Re: alias sequences of sequences

2019-04-07 Thread aliak via Digitalmars-d-learn
On Sunday, 7 April 2019 at 04:58:13 UTC, Alex wrote: Is there any way to get sequences of sequences? Using RT, I have to use strings [[`string`, `0`], ...] when it would be much better to use [[string, 0], ...] Ideally it wouldn't add so much overhead that it defeats the purpose. https://

Re: What's the correct way to interface with a intptr_t?

2019-04-07 Thread bauss via Digitalmars-d-learn
On Saturday, 6 April 2019 at 20:16:06 UTC, Paul Backus wrote: On Saturday, 6 April 2019 at 19:31:15 UTC, Robert M. Münch wrote: I have a C interface that uses a parameter of type intptr_t. Wondering if size_t is the correct D equivalent? The correct equivalent is `intptr_t` from `core.stdc.std

Re: § 28.3 Pointers and the Garbage Collector

2019-04-07 Thread kdevel via Digitalmars-d-learn
On Sunday, 7 April 2019 at 10:17:53 UTC, AltFunction1 wrote: On Sunday, 7 April 2019 at 10:05:26 UTC, kdevel wrote: In § 28.3 Pointers and the Garbage Collector [1] we read Do not add or subtract an offset to a pointer such that the result points outside of the bounds of the garbage coll

Re: § 28.3 Pointers and the Garbage Collector

2019-04-07 Thread AltFunction1 via Digitalmars-d-learn
On Sunday, 7 April 2019 at 10:05:26 UTC, kdevel wrote: In § 28.3 Pointers and the Garbage Collector [1] we read Do not add or subtract an offset to a pointer such that the result points outside of the bounds of the garbage collected object originally allocated. [...] No the foo() cod

§ 28.3 Pointers and the Garbage Collector

2019-04-07 Thread kdevel via Digitalmars-d-learn
In § 28.3 Pointers and the Garbage Collector [1] we read Do not add or subtract an offset to a pointer such that the result points outside of the bounds of the garbage collected object originally allocated. char* p = new char[10]; char* q = p + 6; // ok q = p + 11;

Re: alias sequences of sequences

2019-04-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.04.19 06:58, Alex wrote: Is there any way to get sequences of sequences? Using RT, I have to use strings [[`string`, `0`], ...] when it would be much better to use [[string, 0], ...] Ideally it wouldn't add so much overhead that it defeats the purpose. You can make a template that do

Re: CTFE & code generators based on PEG grammars?

2019-04-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.04.19 05:32, Alex wrote: readlin is not a CT function. You misinterpreted what I said. Yeah, bad example from me. This would probably have been better: auto v = "foo"; enum y = f(v); /* Error: variable v cannot be read at compile time */ Also, the `readln` example wasn't meant

Re: CTFE & code generators based on PEG grammars?

2019-04-07 Thread Alex via Digitalmars-d-learn
On Sunday, 7 April 2019 at 06:39:05 UTC, zabruk wrote: On Sunday, 7 April 2019 at 03:32:45 UTC, Alex wrote: just execute them at CT if possible(and the possibility simply is if the inputs are known at CT). imho, Bastiaan Veelo want to say about citate above: not just "if possible", but "only

Re: What's the correct way to interface with a intptr_t?

2019-04-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-06 20:16:06 +, Paul Backus said: On Saturday, 6 April 2019 at 19:31:15 UTC, Robert M. Münch wrote: I have a C interface that uses a parameter of type intptr_t. Wondering if size_t is the correct D equivalent? The correct equivalent is `intptr_t` from `core.stdc.stdint`. Ha, t

Re: CTFE & code generators based on PEG grammars?

2019-04-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-04-06 20:16:14 +, Bastiaan Veelo said: On Saturday, 6 April 2019 at 12:06:22 UTC, Robert M. Münch wrote: The idea is, that I can write a string (or maybe even a scope block?) in my DSL and use a CTFE grammer to transpile the code. Are you aware of Pegged[1]? It’s for exactly that.