Re: Member variables in method are null when called as delegate from thread

2021-01-12 Thread tsbockman via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 02:15:49 UTC, Tim wrote: Basically, the program calls a function which modifies a document in the database. If it is called form it's own class' constructor, it works fine. If it is called by a thread, it never returns. ... class Caller : Thread{ void deleg

Re: Anything in D to avoid check for null everywhere?

2021-01-12 Thread Jack via Digitalmars-d-learn
Currently I'm with this: auto ref ifNotNull(T, T2)(T lhs, lazy T2 rhs) { if(lhs) { rhs(); } return lhs; } far from good. I wish there was a way to create a new operator so I would make .? similar to C#'s but would evaluate the left-handed side only if it's null and do noth

Re: Member variables in method are null when called as delegate from thread

2021-01-12 Thread Tim via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 01:49:11 UTC, tsbockman wrote: The compiler and the physical CPU are both allowed to change the order in which instructions are executed to something different from what your code specifies, as long as the visible, "official" results and effects of the chosen orde

Re: Developing and running D GUI app on Android

2021-01-12 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jan 10, 2021 at 06:58:13PM +, aberba via Digitalmars-d-learn wrote: > I'm looking to explore running a D application on Android based on > Adams previous foundation work. However, I'm not familiar with the > Android + D integration so I need some help. > > Has any of you successfully d

Re: Problem with templated alias as delegate parameter type

2021-01-12 Thread cc via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 21:32:14 UTC, Ali Çehreli wrote: On 1/12/21 12:58 PM, cc wrote: > void send(T query, void delegate(T.RESPONSE) callback) { That wants a delegate that takes a T.RESPONSE (PingResponse in this case). However, the following lambda is in fact a template: >

Re: I want to create my own Tuple type

2021-01-12 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 21:38:59 UTC, sighoya wrote: What about this? No magic, but I don't know the performance impact. ``` import std.meta; import std.conv; template same(Types...) { static if (Types.length >= 2) { static if (is(Types[0] == Types[$ - 1])) {

Re: Member variables in method are null when called as delegate from thread

2021-01-12 Thread tsbockman via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 14:00:11 UTC, Steven Schveighoffer wrote: On 1/11/21 8:49 PM, tsbockman wrote: However, this re-ordering IS permitted to freely alter the behavior of your code from the perspective of OTHER threads. A likely cause of your bug is that the write to db by the constr

Re: I want to create my own Tuple type

2021-01-12 Thread sighoya via Digitalmars-d-learn
What about this? No magic, but I don't know the performance impact. ``` import std.meta; import std.conv; template same(Types...) { static if (Types.length >= 2) { static if (is(Types[0] == Types[$ - 1])) { const same = same!(Types[1 .. $]); }

Anything in D to avoid check for null everywhere?

2021-01-12 Thread Jack via Digitalmars-d-learn
I was looking for a way to avoid null checks everywhere. I was checking the Null object pattern, or use something like enforce pattern, or even if I could make a new operator and implement something like C#'s .? operator, that Java was going to have one but they refused[1] (doesn't behave exact

Re: Problem with templated alias as delegate parameter type

2021-01-12 Thread Ali Çehreli via Digitalmars-d-learn
On 1/12/21 12:58 PM, cc wrote: > void send(T query, void delegate(T.RESPONSE) callback) { That wants a delegate that takes a T.RESPONSE (PingResponse in this case). However, the following lambda is in fact a template: > send(PingQuery("helo"), (resp) { You specify the type there an

Re: properly passing strings to functions? (C++ vs D)

2021-01-12 Thread IGotD- via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 18:12:14 UTC, Q. Schroll wrote: Did you consider `in`? It will do that in some time and do it now with -preview=in. If you're using `const`, in almost all cases, `in` will work, too, and be better (and shorter). Has the redesignation of "in" like in the preview

Problem with templated alias as delegate parameter type

2021-01-12 Thread cc via Digitalmars-d-learn
Given the following program: struct PingQuery { string msg; } struct PingResponse { string msg; } template send(T) { void send(T query, void delegate(PingResponse) callback) { writefln("Sending: %s", query); if (callback) {

Re: Variadic Struct Parameter

2021-01-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/12/21 2:49 PM, ryuukk_ wrote: On Tuesday, 12 January 2021 at 18:44:53 UTC, Jonathan Levi wrote: On Tuesday, 12 January 2021 at 17:46:14 UTC, Q. Schroll wrote: It's obvious why arrays work, it's the primary use case. I have no idea why classes are allowed. That classes are allowed, but stru

Re: Renamed but non-selective import?

2021-01-12 Thread cc via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 20:19:20 UTC, ag0aep6g wrote: On 12.01.21 21:09, cc wrote: import core.sys.windows.windows; import mymodule; // contains a struct named MSG Error: `core.sys.windows.winuser.MSG` ... conflicts with `mymodule.MSG` vs import core.sys.windows.windows : winMSG = MSG

Re: Variadic Struct Parameter

2021-01-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/12/21 12:46 PM, Q. Schroll wrote: On Tuesday, 12 January 2021 at 17:26:15 UTC, Jonathan Levi wrote: Why is this not working? ``` struct S {     int x;     string y; } void fun(S s ...) { This is intended for arrays and classes, not structs. Using ... for something other than arrays and

Re: Variadic Struct Parameter

2021-01-12 Thread Q. Schroll via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 18:44:53 UTC, Jonathan Levi wrote: On Tuesday, 12 January 2021 at 17:46:14 UTC, Q. Schroll wrote: It's obvious why arrays work, it's the primary use case. I have no idea why classes are allowed. That classes are allowed, but structs are not, makes no sense to me.

Re: Renamed but non-selective import?

2021-01-12 Thread ag0aep6g via Digitalmars-d-learn
On 12.01.21 21:09, cc wrote: import core.sys.windows.windows; import mymodule; // contains a struct named MSG Error: `core.sys.windows.winuser.MSG` ... conflicts with `mymodule.MSG` vs import core.sys.windows.windows : winMSG = MSG; // this leaves out other symbols Error: undefined identifier

Renamed but non-selective import?

2021-01-12 Thread cc via Digitalmars-d-learn
Is it possible to import all symbols of a module, while renaming just one of them? It seems like doing an import with renaming automatically makes it selective. In the example below, I'd prefer not to have to use the fully qualified name for mymodule.MSG every time e.g.: import core.sys.windo

Re: Variadic Struct Parameter

2021-01-12 Thread ryuukk_ via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 18:44:53 UTC, Jonathan Levi wrote: On Tuesday, 12 January 2021 at 17:46:14 UTC, Q. Schroll wrote: It's obvious why arrays work, it's the primary use case. I have no idea why classes are allowed. That classes are allowed, but structs are not, makes no sense to me.

Re: Variadic Struct Parameter

2021-01-12 Thread Ali Çehreli via Digitalmars-d-learn
On 1/12/21 10:44 AM, Jonathan Levi wrote: > why does `fun` still compile? I'm not familiar with that particular syntax, I don't know why it compiles, and I don't know why structs are different. :) However, it looks very much like the following *slice* syntax: void fun(S[] s...) { writeln

Re: Variadic Struct Parameter

2021-01-12 Thread Jonathan Levi via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 17:46:14 UTC, Q. Schroll wrote: It's obvious why arrays work, it's the primary use case. I have no idea why classes are allowed. That classes are allowed, but structs are not, makes no sense to me. I like the variadic feature for classes, but I wish it worked for

Re: properly passing strings to functions? (C++ vs D)

2021-01-12 Thread Q. Schroll via Digitalmars-d-learn
On Monday, 11 January 2021 at 16:53:50 UTC, IGotD- wrote: I usually use "const string text" because D has no implicit declaration of variables. So using "ref" will not create a variable. This is contrary to C++ where passing as "const std::string &text" has a performance benefit and also C++ c

Re: properly passing strings to functions? (C++ vs D)

2021-01-12 Thread Q. Schroll via Digitalmars-d-learn
On Monday, 11 January 2021 at 14:12:57 UTC, zack wrote: A beginner question: How to pass strings properly to functions in D? Is there any allocation going on if just use a function as "myPrint"? In C++ I have often seen calls where one just passes a reference/const reference to a string to avoi

Re: Variadic Struct Parameter

2021-01-12 Thread Q. Schroll via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 17:26:15 UTC, Jonathan Levi wrote: Why is this not working? ``` struct S { int x; string y; } void fun(S s ...) { This is intended for arrays and classes, not structs. Using ... for something other than arrays and c fun(S(5,"hi")); That one sho

Variadic Struct Parameter

2021-01-12 Thread Jonathan Levi via Digitalmars-d-learn
Why is this not working? ``` struct S { int x; string y; } void fun(S s ...) { writeln(s); } void main() { fun(S(5,"hi")); fun(5,"hi"); } ``` Why does `fun` compile if calling it does not?

Re: any chance to get it working on windows xp?

2021-01-12 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 13:51:16 UTC, Imperatorn wrote: On Tuesday, 12 January 2021 at 12:40:28 UTC, Mike Parker wrote: Are you asking if anyone patched the binaries and made them available as a third-party download? Yes, or if there are any plans for those changes to go upstream.

Re: Member variables in method are null when called as delegate from thread

2021-01-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/11/21 8:49 PM, tsbockman wrote: On Monday, 11 January 2021 at 00:43:00 UTC, Tim wrote: When MessageService calls the delegate for start, db is null. If I call start() in the Foo constructor it works just fine. Am I missing something here? Do delegates get called outside of their class con

Re: Member variables in method are null when called as delegate from thread

2021-01-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/11/21 12:26 PM, Arafel wrote: Thanks for the detailed explanation! I think this mixing of types and storage classes makes a very unfortunate combination: ``` import std; int i = 0; shared int j = 0; struct S {     int i = 0;     shared int j = 0; } S s; void main() {     i = 1;    

Re: any chance to get it working on windows xp?

2021-01-12 Thread Imperatorn via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 12:40:28 UTC, Mike Parker wrote: On Tuesday, 12 January 2021 at 10:25:42 UTC, Imperatorn wrote: https://forum.dlang.org/post/qsgtohsykwldipgng...@forum.dlang.org On Saturday, 3 October 2020 at 23:14:57 UTC, Drone1h wrote: On Monday, 18 May 2020 at 05:36:01 UTC, M

Re: Member variables in method are null when called as delegate from thread

2021-01-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/11/21 6:52 PM, Paul Backus wrote: On Monday, 11 January 2021 at 16:10:49 UTC, Steven Schveighoffer wrote: There are some... odd rules. struct S { [...]    immutable int e = 5; // stored in data segment, not per instance! Are you sure? struct S {     immutable int n = 123;     this(i

Re: any chance to get it working on windows xp?

2021-01-12 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 10:25:42 UTC, Imperatorn wrote: https://forum.dlang.org/post/qsgtohsykwldipgng...@forum.dlang.org On Saturday, 3 October 2020 at 23:14:57 UTC, Drone1h wrote: On Monday, 18 May 2020 at 05:36:01 UTC, Mike Parker wrote: [...] This is not exactly a reply to the ori

Re: I want to create my own Tuple type

2021-01-12 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
Ok, so I now have this, but I think maybe the switch could be turned into a static array by an reinterpret cast of "&expand[0]"? I would assume the layout would typically be "expand_field_0, expand_field_1 etc... template Tuple(Types...){ template same(){ static foreach (i, dummy;

Re: Static constructor

2021-01-12 Thread ludo via Digitalmars-d-learn
NOTE : the entire code we are talking about is in the tiny url in my previous post. On Thursday, 7 January 2021 at 01:55:07 UTC, SealabJaster wrote: On Wednesday, 6 January 2021 at 17:05:02 UTC, ludo wrote: ... Using a static class like this seems to mostly be a design decision. So in ot

any chance to get it working on windows xp?

2021-01-12 Thread Imperatorn via Digitalmars-d-learn
https://forum.dlang.org/post/qsgtohsykwldipgng...@forum.dlang.org On Saturday, 3 October 2020 at 23:14:57 UTC, Drone1h wrote: On Monday, 18 May 2020 at 05:36:01 UTC, Mike Parker wrote: [...] This is not exactly a reply to the original thread, but maybe it helps someone who has searched for "

Re: Linux shared library loading/linking from C does not invoke (shared) static this

2021-01-12 Thread ichneumwn via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 09:49:46 UTC, Mike Parker wrote: On Tuesday, 12 January 2021 at 09:31:08 UTC, ichneumwn wrote: Follow on to my own question: on Linux, with gcc, I have created the following file "starter.c" that I inject into my D shared library: int rt_init(void); int r

Re: Linux shared library loading/linking from C does not invoke (shared) static this

2021-01-12 Thread ichneumwn via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 09:02:38 UTC, Imperatorn wrote: On Tuesday, 12 January 2021 at 08:19:45 UTC, ichneumwn wrote: Where could one file a suggestion for an update to the documentation? In the top right section of the page you can click the "Improve this page"-link. Thanks, I will

Re: Linux shared library loading/linking from C does not invoke (shared) static this

2021-01-12 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 09:31:08 UTC, ichneumwn wrote: Follow on to my own question: on Linux, with gcc, I have created the following file "starter.c" that I inject into my D shared library: int rt_init(void); int rt_term(void); // should really check for errors! static void

Re: Linux shared library loading/linking from C does not invoke (shared) static this

2021-01-12 Thread ichneumwn via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 08:19:45 UTC, ichneumwn wrote: Dear all, I was trying to invoke some D code from Python and ran into issues which I eventually traced back to a simple example on the D website itself : https://dlang.org/articles/dll-linux.html Particularly the section "Dynamic

Re: Member variables in method are null when called as delegate from thread

2021-01-12 Thread Imperatorn via Digitalmars-d-learn
On Monday, 11 January 2021 at 17:26:00 UTC, Arafel wrote: void f() { assert(i == 0); // Expected assert(j == 1); // Expected assert(s.i == 0); // Expected assert(s.j == 0); // Wait, what? } At first sight this looks unexpected. But I think if you have a shared variable inside

Re: How build DCD on Windows?

2021-01-12 Thread Imperatorn via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 06:25:09 UTC, evilrat wrote: On Tuesday, 12 January 2021 at 00:35:41 UTC, Marcone wrote: Hi, Someone can Help me build exe dcd server and client on WIndows? Step by step? Becouse the informations disponible is very hard to undestand. Are you serious? It's on the

Re: Linux shared library loading/linking from C does not invoke (shared) static this

2021-01-12 Thread Imperatorn via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 08:19:45 UTC, ichneumwn wrote: Where could one file a suggestion for an update to the documentation? In the top right section of the page you can click the "Improve this page"-link.

Linux shared library loading/linking from C does not invoke (shared) static this

2021-01-12 Thread ichneumwn via Digitalmars-d-learn
Dear all, I was trying to invoke some D code from Python and ran into issues which I eventually traced back to a simple example on the D website itself : https://dlang.org/articles/dll-linux.html Particularly the section "Dynamically Loading a D DLL From a C Program" In my case, and indee