Re: reference variables don't exist, but can simulate them

2020-06-28 Thread NonNull via Digitalmars-d-learn
On Sunday, 28 June 2020 at 20:59:59 UTC, NonNull wrote: Using gdc (Ubuntu 8.4.0-1ubuntu1~18.04) 8.4.0 Please criticize: struct refer(T) { T* ptr; this(ref T x) { ptr = } ref T _() { return *ptr; } alias _ this; string toString() { import std.conv; return to!string(*ptr); } } This

Re: How to implement Canceleable spawn() from parent

2020-06-28 Thread aberba via Digitalmars-d-learn
On Sunday, 28 June 2020 at 23:39:07 UTC, Stanislav Blinov wrote: On Sunday, 28 June 2020 at 23:02:26 UTC, aberba wrote: I believe this: StopWatch sw; sw.start; works becuse D structs are initialized by default, right? I've never actually done it this way. Little details. Yup. You can also

[DIP1000] Something I don't quite understand regarding 'scope'

2020-06-28 Thread Stanislav Blinov via Digitalmars-d-learn
void local(Args...)(Args args) { } void main() @safe { import std.stdio; scope int* p; local(p); // Ok writeln(p); // Error: scope variable p assigned to non-scope parameter _param_0 calling std.stdio.writeln!(int*).writeln } The signatures of `std.stdio.writeln` and `local`

Re: How to implement Canceleable spawn() from parent

2020-06-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 28 June 2020 at 23:02:26 UTC, aberba wrote: I believe this: StopWatch sw; sw.start; works becuse D structs are initialized by default, right? I've never actually done it this way. Little details. Yup. You can also do a auto sw = StopWatch(AutoStart.yes); and not have to call

Re: reference variables don't exist, but can simulate them

2020-06-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 29 June 2020 at 02:11:15 UTC, NonNull wrote: Deprecation: Cannot use alias this to partially initialize variable j of type refer. Use j._() This is for the line j=3 What is this about? Where does this hidden rule come from? That one comes from [1]. But there are quite a few more

reference variables don't exist, but can simulate them

2020-06-28 Thread NonNull via Digitalmars-d-learn
Using gdc (Ubuntu 8.4.0-1ubuntu1~18.04) 8.4.0 Please criticize: struct refer(T) { T* ptr; this(ref T x) { ptr = } ref T _() { return *ptr; } alias _ this; string toString() { import std.conv; return to!string(*ptr); } } This will make a reference variable (simulation). [ toString()

Re: How to implement Canceleable spawn() from parent

2020-06-28 Thread aberba via Digitalmars-d-learn
On Sunday, 28 June 2020 at 14:23:01 UTC, Stanislav Blinov wrote: On Sunday, 28 June 2020 at 13:29:08 UTC, aberba wrote: Thanks. I believe this: StopWatch sw; sw.start; works becuse D structs are initialized by default, right? I've never actually done it this way. Little details.

Re: How to implement Canceleable spawn() from parent

2020-06-28 Thread Ali Çehreli via Digitalmars-d-learn
On 6/28/20 4:08 PM, aberba wrote: So I checked receiveTimeout() when I was looking for what I could use. I wish there was an example in the docs. https://dlang.org/library/std/concurrency/receive_timeout.html I have an example of it:

Re: How to implement Canceleable spawn() from parent

2020-06-28 Thread aberba via Digitalmars-d-learn
On Sunday, 28 June 2020 at 23:02:26 UTC, aberba wrote: On Sunday, 28 June 2020 at 14:23:01 UTC, Stanislav Blinov wrote: On Sunday, 28 June 2020 at 13:29:08 UTC, aberba wrote: Thanks. I believe this: StopWatch sw; sw.start; works becuse D structs are initialized by default, right? I've

Re: reference variables don't exist, but can simulate them

2020-06-28 Thread NonNull via Digitalmars-d-learn
On Sunday, 28 June 2020 at 21:01:36 UTC, NonNull wrote: On Sunday, 28 June 2020 at 20:59:59 UTC, NonNull wrote: Using gdc (Ubuntu 8.4.0-1ubuntu1~18.04) 8.4.0 Please criticize: struct refer(T) { T* ptr; this(ref T x) { ptr = } ref T _() { return *ptr; } alias _ this; string

Re: foreach iterator with closure

2020-06-28 Thread Denis via Digitalmars-d-learn
To keep this reply brief, I'll just summarize: Lots of great takeaways from both of your posts, and a handful of topics you mentioned that I need to dig into further now. This is great (I too like D :) I very much appreciate the extra insight into how things work and why certain design

Light-weight runtime

2020-06-28 Thread Виталий Фадеев via Digitalmars-d-learn
I want light-weight runtime ! How to ?

How to implement Canceleable spawn() from parent

2020-06-28 Thread aberba via Digitalmars-d-learn
Trying to implement a setInterval() that I can cancel using: Tid tid = setInterval(2000, (){ writeln("hello");}) And then I can do: stopInterval(tid); With something like this: stopInterval(Tid tid) { send(tid, "cancel"); } import std.stdio : writeln; import std.concurrency : receive,

Re: How to implement Canceleable spawn() from parent

2020-06-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 28 June 2020 at 13:29:08 UTC, aberba wrote: Getting error: Error: template std.concurrency.spawn cannot deduce function from argument types !()(void delegate(Tid id) @system, Tid), candidates are: /usr/include/dmd/phobos/std/concurrency.d(460,5): spawn(F, T...)(F fn, T

dmd release schedule?

2020-06-28 Thread drathier via Digitalmars-d-learn
Is there a release schedule anywhere for DMD? Any list of tasks to be the next release? I'm only finding 5+ year old things when searching.

Re: Light-weight runtime

2020-06-28 Thread aberba via Digitalmars-d-learn
On Sunday, 28 June 2020 at 07:09:53 UTC, Виталий Фадеев wrote: I want light-weight runtime ! How to ? If you have access to Google translate or any equivalent tool, you may use it to write in Russian language and copy+paste the English here. I think that'll really help. I always give deep

Re: Translating C headers to D: How do I compile it?

2020-06-28 Thread Kirill via Digitalmars-d-learn
On Sunday, 28 June 2020 at 05:13:32 UTC, Mike Parker wrote: On Sunday, 28 June 2020 at 04:59:12 UTC, Kirill wrote: something.d: module something; int add(int a, int b); This should be extern(C) int add(int a, int b). The extern(C) tells the D compiler to use the standard C calling

Re: foreach iterator with closure

2020-06-28 Thread Ali Çehreli via Digitalmars-d-learn
On 6/28/20 9:07 AM, Denis wrote: > * foreach is the actual iterator, Yes. foreach is "lowered" to the following equivalent: for ( ; !range.empty; range.popFront()) { // Use range.front here } A struct can support foreach iteration through its opCall() member function as well.

std.concurrency.receive and shared const(char)[]?

2020-06-28 Thread BakedPineapple via Digitalmars-d-learn
import std.stdio; import std.concurrency; void main() { auto t = spawn((){ receive((shared const(char)[] char_arr) { ownerTid.send(true); }); }); shared const(char)[] char_arr = "cut my code into pieces";

Re: std.concurrency.receive and shared const(char)[]?

2020-06-28 Thread Anonymouse via Digitalmars-d-learn
On Sunday, 28 June 2020 at 16:11:50 UTC, BakedPineapple wrote: import std.stdio; import std.concurrency; void main() { auto t = spawn((){ receive((shared const(char)[] char_arr) { ownerTid.send(true); }); }); shared

Re: Temporary File Creation

2020-06-28 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 22 June 2020 at 23:53:41 UTC, Stanislav Blinov wrote: tempDir just returns a path (i.e. "/tmp" or whatever it is on Windows, etc.), it doesn't create anything. Given the synopsis of std.file, a procedure for *creating* a file doesn't belong there, as it would only be half of an

Re: foreach iterator with closure

2020-06-28 Thread Denis via Digitalmars-d-learn
Many thanks: your post has helped me get past the initial stumbling blocks I was struggling with. I do have a followup question. First, here are my conclusions up to this point, based on your post above, some additional experimentation, and further research (for future reference, and for any

Re: std.concurrency.receive and shared const(char)[]?

2020-06-28 Thread BakedPineapple via Digitalmars-d-learn
On Sunday, 28 June 2020 at 16:39:12 UTC, Anonymouse wrote: On Sunday, 28 June 2020 at 16:11:50 UTC, BakedPineapple wrote: import std.stdio; import std.concurrency; void main() { auto t = spawn((){ receive((shared const(char)[] char_arr) {