why `top` report is not consistent with the memory freed by core.stdc.stdlib : free?

2020-11-05 Thread mw via Digitalmars-d-learn
Hi, I'm trying this: https://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation using core.stdc.stdlib : malloc and free to manually manage memory, I tested two scenarios: -- malloc & free -- malloc only and I use Linux command `top` to check the memory used by the

Re: nested module problem

2020-10-28 Thread mw via Digitalmars-d-learn
IMO, 3rd party libraries should always be in their own package namespace. Leave the top-level for user code! Why should a local module 'util' conflict with any dependency? It should be the library author's job to make sure his code doesn't conflict with the user's! logged:

Re: nested module problem

2020-10-28 Thread mw via Digitalmars-d-learn
On Wednesday, 28 October 2020 at 22:52:33 UTC, Adam D. Ruppe wrote: On Wednesday, 28 October 2020 at 22:43:12 UTC, mw wrote: I wonder what's the best way to resolve this conflict, i.e my local file name with 3rd party library dir name. Don't write any module with a single name unless you are

Re: nested module problem

2020-10-28 Thread mw via Digitalmars-d-learn
I run into a similar issue today: -- I try to use a library `pyd`, and -- my local project has a file called "source/util.d" the dub build error out: /.dub/packages/pyd-0.13.1/pyd/infrastructure/util/typelist.d(1,1): Error: package name 'util' conflicts with usage as a module name in file

Re: Why does sum not work in static arrays?

2020-10-10 Thread mw via Digitalmars-d-learn
On Sunday, 6 December 2015 at 12:27:49 UTC, cym13 wrote: On Sunday, 6 December 2015 at 12:23:05 UTC, Tim K. wrote: Hi! I have the following code: int main(string[] argv) { import std.algorithm: sum; import std.stdio: writeln; uint[3] a1 = [1, 2, 3];

Re: What classification should shared objects in qeued thread pools have?

2020-09-30 Thread mw via Digitalmars-d-learn
On Thursday, 1 October 2020 at 00:13:41 UTC, IGotD- wrote: I think that the shared in shared structs should not be transitive to members of the struct. The compiler should not Once the aggregate struct data is decl-ed `shared` as a whole, it needs to be transitive to play safe. The compiler

Re: What classification should shared objects in qeued thread pools have?

2020-09-30 Thread mw via Digitalmars-d-learn
On Thursday, 1 October 2020 at 00:00:06 UTC, mw wrote: On Wednesday, 30 September 2020 at 20:13:47 UTC, IGotD- wrote: [...] I think declaring the container and item as `shared` is the D's encouraged way of sharing data among different threads. [...] then just cast the `shared` away:

Re: What classification should shared objects in qeued thread pools have?

2020-09-30 Thread mw via Digitalmars-d-learn
On Wednesday, 30 September 2020 at 20:13:47 UTC, IGotD- wrote: This where the memory model of D starts to become confusing for me. By default memory allocations/deallocation are not allowed between threads, however setting the object to shared circumvents this. This seems to work as there is

help: cannot build profdump, dub error (bug): Enforcement failed

2020-09-29 Thread mw via Digitalmars-d-learn
I remember I used to able to build this package: https://github.com/AntonMeep/profdump but now, I cannot. Since that package haven't changed for 2 years, maybe it's a dub bug? System information $ uname -a Linux 4.15.0-117-generic #118-Ubuntu SMP Fri Sep 4 20:02:41 UTC 2020 x86_64

what's the best way to convert a sysTime to local machine's time (zone)?

2020-09-24 Thread mw via Digitalmars-d-learn
Hi, I'm just wondering what's the best way to convert sysTime to local machine's time (zone)? Is there any library function does this already? https://dlang.org/phobos/std_datetime_systime.html#SysTime (The time in SysTime is kept internally in hnsecs from midnight, January 1st, 1 A.D.

Re: Why is "delete" unsafe?

2020-09-22 Thread mw via Digitalmars-d-learn
On Saturday, 27 October 2012 at 01:08:12 UTC, Jonathan M Davis wrote: On Saturday, October 27, 2012 01:09:39 Alex Rønne Petersen wrote: On 27-10-2012 01:03, Minas wrote: > So the delete keyword has been deprecated - so good bye > manual memory management... Um, no. Use destroy() from the

Re: create and initialise array

2020-09-19 Thread mw via Digitalmars-d-learn
On Thursday, 20 June 2019 at 07:57:25 UTC, KnightMare wrote: On Thursday, 20 June 2019 at 01:32:04 UTC, matheus wrote: import std.stdio; import std.array; void main(){ auto s = uninitializedArray!(float[])(100); s[] = 0.0f; writeln(s[0]); } Even with this, user has to write two

Re: vibe.d: How to get the conent of a file upload ?

2020-09-18 Thread mw via Digitalmars-d-learn
On Friday, 18 September 2020 at 00:07:12 UTC, wjoe wrote: Are there other frameworks besides vibe that can do what I want? Just FYI, there is also: https://code.dlang.org/packages/hunt-framework I never used myself, you need to investigate.

Re: Call C variadic function from D variadic function

2020-09-13 Thread mw via Digitalmars-d-learn
Just a observation, from the questions & answers in this thread and mine[1]: I think meta-programming in D is somehow like C++, it starts becoming a baroque language. The language is complex enough that there may be ways to get things done, but it's just quite difficult for ordinary users to

Re: how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-13 Thread mw via Digitalmars-d-learn
On Sunday, 13 September 2020 at 10:16:46 UTC, Paul Backus wrote: On Sunday, 13 September 2020 at 07:00:36 UTC, mw wrote: Here it is: D wrapper for https://ta-lib.org/ https://github.com/mingwugmail/talibd I end up using C macro to generate D functions, the single template is this one:

Re: how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-13 Thread mw via Digitalmars-d-learn
On Sunday, 13 September 2020 at 01:25:43 UTC, mw wrote: On Saturday, 12 September 2020 at 20:29:40 UTC, Paul Backus If you have a "real-life" application in mind for this, I'd be curious to hear what it is. I'm wrapping a C library, trying to write a single D function / template that can

Re: how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-12 Thread mw via Digitalmars-d-learn
On Saturday, 12 September 2020 at 20:29:40 UTC, Paul Backus wrote: On Saturday, 12 September 2020 at 19:31:57 UTC, mw wrote: (I'm asking for a more general solution, e.g. what if we have 3, or N sets of variadic parameters?) Looks like we can only pass 1 variadic parameters, then the

Re: how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-12 Thread mw via Digitalmars-d-learn
On Saturday, 12 September 2020 at 19:06:47 UTC, Paul Backus wrote: On Saturday, 12 September 2020 at 18:16:51 UTC, mw wrote: Now, let me expand this challenge: suppose we need to add a new set of variable length extra parameters in parallel to the arrays, i.e: [...] Now the question is how

Re: how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-12 Thread mw via Digitalmars-d-learn
On Saturday, 12 September 2020 at 14:31:59 UTC, Paul Backus wrote: On Saturday, 12 September 2020 at 03:19:23 UTC, mw wrote: I.e. I want to learn the generic meta-programming way to assemble such parameter list (&(x[i], &(y[j])) at compile time, it is possible? It's possible if you use a

Re: how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-11 Thread mw via Digitalmars-d-learn
On Saturday, 12 September 2020 at 03:11:09 UTC, Ali Çehreli wrote: On 9/11/20 6:44 PM, mw wrote:> e.g. > > int[] a = new int[la]; > int[] b = new int[lb]; > int[] c = new int[lc]; > int[] d = new int[ld]; > > > the func I want to write, e.g. for 2 arrays (instantiation) is like this: > > void

how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-11 Thread mw via Digitalmars-d-learn
e.g. int[] a = new int[la]; int[] b = new int[lb]; int[] c = new int[lc]; int[] d = new int[ld]; the func I want to write, e.g. for 2 arrays (instantiation) is like this: void print_random_elem_addr(int[] x, int[] y) { auto i = random_int_between(0, x.length); auto j =

Re: how to run 'dub upgrade' from within VisualD?

2020-09-08 Thread mw via Digitalmars-d-learn
On Monday, 24 August 2020 at 21:19:14 UTC, mw wrote: Hi, Just wonder how to run 'dub upgrade' from within VisualD? on Windows of course. As a work around, I just delete the proj.sln, and regenerated it: ``` C:\\ dub.exe generate visuald ``` then it have the latest package versions.

Re: Shallow copy object when type is know

2020-08-27 Thread mw via Digitalmars-d-learn
On Thursday, 21 April 2016 at 11:53:13 UTC, rumbu wrote: On Wednesday, 20 April 2016 at 12:32:48 UTC, Tofu Ninja wrote: Is there a way to shallow copy an object when the type is known? I cant seem to figure out if there is a standard way. I can't just implement a copy function for the class, I

Re: what's this Error: corrupt MS Coff object module

2020-08-24 Thread mw via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 01:44:16 UTC, mw wrote: I just tried, using -m32: /mnt/c/project/dlang/dmd-2.093.1/windows/bin/sc.ini [Environment] DFLAGS="-I%@P%\..\..\src\phobos" "-I%@P%\..\..\src\druntime\import" "-d" "-m32" at least that error is gone, and I was able to build:

Re: what's this Error: corrupt MS Coff object module

2020-08-24 Thread mw via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 01:35:00 UTC, mw wrote: On Tuesday, 25 August 2020 at 01:13:11 UTC, Adam D. Ruppe wrote: On Tuesday, 25 August 2020 at 01:08:49 UTC, mw wrote: Is it safe to just delete all the: yup. I have to do this every other week on my work box to keep its hard drive from

Re: what's this Error: corrupt MS Coff object module

2020-08-24 Thread mw via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 01:13:11 UTC, Adam D. Ruppe wrote: On Tuesday, 25 August 2020 at 01:08:49 UTC, mw wrote: Is it safe to just delete all the: yup. I have to do this every other week on my work box to keep its hard drive from filling up lol I just completely deleted that

Re: what's this Error: corrupt MS Coff object module

2020-08-24 Thread mw via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 00:56:51 UTC, Adam D. Ruppe wrote: Might help to just delete the old directories and let it redownload and recompile fresh with all the new settings. Is it safe to just delete all the: C:\Users...\AppData\Local\dub\packages\ and run `dub upgrade` again to

what's this Error: corrupt MS Coff object module

2020-08-24 Thread mw via Digitalmars-d-learn
I got this error, when build with VisualD-v1.0.1-dmd-2.093.1-ldc2-1.23.0.exe dmd: lib\unit-threaded_property.lib: Error: corrupt MS Coff object module

Re: how to run 'dub upgrade' from within VisualD?

2020-08-24 Thread mw via Digitalmars-d-learn
On Monday, 24 August 2020 at 21:19:14 UTC, mw wrote: Hi, Just wonder how to run 'dub upgrade' from within VisualD? on Windows of course. In "Solution Explorer", I right click "asdf" and select "DUB Upgrade", but nothing happened: $ grep asdf ats.sln

how to run 'dub upgrade' from within VisualD?

2020-08-24 Thread mw via Digitalmars-d-learn
Hi, Just wonder how to run 'dub upgrade' from within VisualD? on Windows of course. thanks.

SIGUSR1 in clock_nanosleep()? how to isolate this issue?

2020-08-20 Thread mw via Digitalmars-d-learn
Hi, I run into an issue: it's SIGUSR1 in clock_nanosleep() --- ... [New Thread 0x70ae0700 (LWP 36860)] [New Thread 0x7fffcbfff700 (LWP 36861)] [Detaching after fork from child process 36862] [New Thread 0x7fffd2eff700 (LWP 36863)] [New Thread 0x7fffd26fe700 (LWP

Re: getopt Basic usage

2020-08-14 Thread mw via Digitalmars-d-learn
On Saturday, 15 August 2020 at 04:09:19 UTC, James Gray wrote: I am trying to use getopt and would not like the program to throw an unhandled exception when parsing command line options. Is the following, adapted from the first example in the getopt documentation, a reasonable approach? life

Re: vibe.d and my first web service

2020-08-12 Thread mw via Digitalmars-d-learn
On Wednesday, 12 August 2020 at 13:46:06 UTC, James Blachly wrote: ... The ctrl-C non-termination bug has existed since at least 2015 from what I can tell from the forums. It's such a pity that so many dub packages are not in friction-free mode. For this particular problem, maybe before it

Re: how to assign to shared obj.systime?

2020-07-10 Thread mw via Digitalmars-d-learn
On Friday, 10 July 2020 at 17:35:56 UTC, Steven Schveighoffer wrote: Mark your setTime as shared, then cast away shared (as you don't need atomics once it's locked), and assign: synchronized setTime(ref SysTime t) shared { (cast()this).time = t; } I know I can make it work by casting, my

Re: how to assign to shared obj.systime?

2020-07-10 Thread mw via Digitalmars-d-learn
On Friday, 10 July 2020 at 17:18:25 UTC, mw wrote: On Friday, 10 July 2020 at 08:48:38 UTC, Kagamin wrote: On Friday, 10 July 2020 at 05:12:06 UTC, mw wrote: looks like we still have to cast: as of 2020, sigh. Why not? Because cast is ugly. I've also tried this: ``` class A {

Re: how to assign to shared obj.systime?

2020-07-10 Thread mw via Digitalmars-d-learn
On Friday, 10 July 2020 at 08:48:38 UTC, Kagamin wrote: On Friday, 10 July 2020 at 05:12:06 UTC, mw wrote: looks like we still have to cast: as of 2020, sigh. Why not? Because cast is ugly. I've also tried this: ``` class A { SysTime time; synchronized setTime(ref SysTime

Re: how to assign to shared obj.systime?

2020-07-09 Thread mw via Digitalmars-d-learn
On Friday, 10 July 2020 at 03:01:20 UTC, mw wrote: On Friday, 10 July 2020 at 02:59:56 UTC, mw wrote: Error: template std.datetime.systime.SysTime.opAssign cannot deduce function from argument types !()(SysTime) shared, candidates are: /usr/include/dmd/phobos/std/datetime/systime.d(659,17):

Re: how to assign to shared obj.systime?

2020-07-09 Thread mw via Digitalmars-d-learn
On Friday, 10 July 2020 at 02:59:56 UTC, mw wrote: Error: template std.datetime.systime.SysTime.opAssign cannot deduce function from argument types !()(SysTime) shared, candidates are: /usr/include/dmd/phobos/std/datetime/systime.d(659,17): opAssign()(auto ref const(SysTime) rhs) of

how to assign to shared obj.systime?

2020-07-09 Thread mw via Digitalmars-d-learn
``` import std.datetime; class A { SysTime time; } void main() { shared A a = new A(); SysTime time; a.time = time; } ``` Error: template std.datetime.systime.SysTime.opAssign cannot deduce function from argument types !()(SysTime) shared, candidates are:

Re: How to specify a version from dub build command

2020-07-07 Thread mw via Digitalmars-d-learn
On Tuesday, 7 July 2020 at 06:34:15 UTC, adnan338 wrote: I have a separate version for flatpak builds in my app. Let's say I have a large project that builds with dub that goes like this: import std.stdio; void main() { version (flatpak) { writeln(`Flatpak build`);

Re: Associative array on the heap

2020-07-07 Thread mw via Digitalmars-d-learn
On Tuesday, 19 May 2015 at 12:21:48 UTC, Steven Schveighoffer wrote: On 5/18/15 7:55 PM, Freddy wrote: How do you allocate an associative array on the heap? void main(){ alias A=int[string]; auto b=new A; } $ rdmd test test.d(4): Error: new can only create structs, dynamic

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

2020-06-27 Thread mw via Digitalmars-d-learn
On Sunday, 28 June 2020 at 04:59:12 UTC, Kirill wrote: Hello. I am learning how to translate C headers to D. But how do I compile it? I am stuck with this. You can try just to use dpp: https://code.dlang.org/packages/dpp instead of doing the translation manually.

Re: are std.traits.FieldNameTuple and std.traits.Fields returned value always in sync?

2020-06-23 Thread mw via Digitalmars-d-learn
On Monday, 22 June 2020 at 20:08:37 UTC, Stanislav Blinov wrote: But if you'd like it spelled out in text as well, you can make a PR for the Phobos repository. Just-Did-It: https://github.com/dlang/phobos/pull/7540 The point of doc is that the user don't have to dive into the code to know

Re: how to skip the next (n) item & continue from (n+1) with a range ? e.g. in File(fn).byLine();

2020-06-22 Thread mw via Digitalmars-d-learn
On Monday, 22 June 2020 at 21:27:12 UTC, Steven Schveighoffer wrote:    auto line = range.front;    range.popFront;  // pop immediately This is a bad idea, once you popFront, the original front is possibly invalid (and technically is the case for byLine). In this case, it's caused by

Re: how to skip the next (n) item & continue from (n+1) with a range ? e.g. in File(fn).byLine();

2020-06-22 Thread mw via Digitalmars-d-learn
On Monday, 22 June 2020 at 21:22:10 UTC, H. S. Teoh wrote: On Mon, Jun 22, 2020 at 08:51:49PM +, mw via Digitalmars-d-learn wrote: [...] >auto line = range.front; >range.popFront; // pop immediately [...] This is dangerous, because it assumes .front is not inval

Re: how to skip the next (n) item & continue from (n+1) with a range ? e.g. in File(fn).byLine();

2020-06-22 Thread mw via Digitalmars-d-learn
On Monday, 22 June 2020 at 20:58:58 UTC, Ali Çehreli wrote: Others have other explanations for this but my understanding is about exception safety: If it changed internal state and returned the front object, you would no be able to make a function like popFront() strongly exception safe.

Re: how to skip the next (n) item & continue from (n+1) with a range ? e.g. in File(fn).byLine();

2020-06-22 Thread mw via Digitalmars-d-learn
On Monday, 22 June 2020 at 20:49:55 UTC, mw wrote: On Monday, 22 June 2020 at 20:46:30 UTC, mw wrote: On Monday, 22 June 2020 at 20:00:50 UTC, Steven Schveighoffer wrote: I wouldn't recommend it, instead do a while loop: auto range = File(fn).byLine; while(!range.empty) { auto line =

Re: how to skip the next (n) item & continue from (n+1) with a range ? e.g. in File(fn).byLine();

2020-06-22 Thread mw via Digitalmars-d-learn
On Monday, 22 June 2020 at 20:46:30 UTC, mw wrote: On Monday, 22 June 2020 at 20:00:50 UTC, Steven Schveighoffer wrote: I wouldn't recommend it, instead do a while loop: auto range = File(fn).byLine; while(!range.empty) { auto line = range.front; if(someCond(line)) {

Re: how to skip the next (n) item & continue from (n+1) with a range ? e.g. in File(fn).byLine();

2020-06-22 Thread mw via Digitalmars-d-learn
On Monday, 22 June 2020 at 20:00:50 UTC, Steven Schveighoffer wrote: I wouldn't recommend it, instead do a while loop: auto range = File(fn).byLine; while(!range.empty) { auto line = range.front; if(someCond(line)) { range.popFrontN(n); } else { regularProcess(line);

Re: are std.traits.FieldNameTuple and std.traits.Fields returned value always in sync?

2020-06-22 Thread mw via Digitalmars-d-learn
On Saturday, 20 June 2020 at 20:42:03 UTC, Stanislav Blinov wrote: On Saturday, 20 June 2020 at 20:17:54 UTC, mw wrote: Are their returned value, i.e the field names and their types are always in the same order, and of the same length? If they are not, how to get sync-ed pairs (name, type)?

how to skip the next (n) item & continue from (n+1) with a range ? e.g. in File(fn).byLine();

2020-06-22 Thread mw via Digitalmars-d-learn
Hi, I need this logic: ``` auto range = File(fn).byLine(); foreach (line; range) { if (comeCond(line)) { // skip the next n line // and continue the foreach loop from the (n+1) line } else { regularProcess(line); } } ``` Is it possible to do this in a foreach loop? If

are std.traits.FieldNameTuple and std.traits.Fields returned value always in sync?

2020-06-20 Thread mw via Digitalmars-d-learn
Are their returned value, i.e the field names and their types are always in the same order, and of the same length? If they are not, how to get sync-ed pairs (name, type)? If they are, why we need two separate calls, which cause confusion.

Re: why cannot spawn function defined in unittest block {}?

2020-06-20 Thread mw via Digitalmars-d-learn
On Saturday, 20 June 2020 at 18:08:06 UTC, mw wrote: On Saturday, 20 June 2020 at 18:01:51 UTC, Adam D. Ruppe wrote: On Saturday, 20 June 2020 at 17:43:42 UTC, mw wrote: the function defined in unittest become a delegate? how to work-around this? just add the keyword static to the functions

Re: why cannot spawn function defined in unittest block {}?

2020-06-20 Thread mw via Digitalmars-d-learn
On Saturday, 20 June 2020 at 18:01:51 UTC, Adam D. Ruppe wrote: On Saturday, 20 June 2020 at 17:43:42 UTC, mw wrote: the function defined in unittest become a delegate? how to work-around this? just add the keyword static to the functions

why cannot spawn function defined in unittest block {}?

2020-06-20 Thread mw via Digitalmars-d-learn
put the code from: https://tour.dlang.org/tour/en/multithreading/synchronization-sharing in file, and put unittest block from safePrint() to main() as here: https://github.com/mingwugmail/dlang_tour/blob/master/spawn_in_unittest.d#L33 - $ dmd -unittest spawn_in_unittest.d

Re: why cannot spawn function defined in unittest block {}?

2020-06-20 Thread mw via Digitalmars-d-learn
the function defined in unittest become a delegate? how to work-around this?

Re: Windows + LDC/DMD installation nightmare when changing VS versions

2020-06-12 Thread mw via Digitalmars-d-learn
On Friday, 12 June 2020 at 16:16:18 UTC, mw wrote: On Friday, 12 June 2020 at 15:21:12 UTC, Guillaume Piolat wrote: - With LDC + 32-bit it still fail with: libcmt.lib(chkstk.obj) : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64' Error: C:\Program

Re: Windows + LDC/DMD installation nightmare when changing VS versions

2020-06-12 Thread mw via Digitalmars-d-learn
On Friday, 12 June 2020 at 15:21:12 UTC, Guillaume Piolat wrote: - With LDC + 32-bit it still fail with: libcmt.lib(chkstk.obj) : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64' Error: C:\Program Files (x86)\Microsoft Visual Studio

Re: Error: llroundl cannot be interpreted at compile time, because it has no available source code

2020-06-08 Thread mw via Digitalmars-d-learn
On Monday, 8 June 2020 at 19:05:45 UTC, Steven Schveighoffer wrote: On 6/8/20 2:53 PM, mw wrote: And with a symbol-to-c-func table, it should be able to just call that C func. Consider that the libc available to the compiler might not be the same as the libc for the target (e.g. cross

Re: Error: llroundl cannot be interpreted at compile time, because it has no available source code

2020-06-08 Thread mw via Digitalmars-d-learn
On Monday, 8 June 2020 at 18:43:58 UTC, Stanislav Blinov wrote: On Monday, 8 June 2020 at 18:08:57 UTC, mw wrote: 2) even it does so, but why such simple function as lroundl cannot be CTFE-ed? Because, as the error message states, there's no source for it :) std.math calls into C math

Error: llroundl cannot be interpreted at compile time, because it has no available source code

2020-06-08 Thread mw via Digitalmars-d-learn
Hi, I'm trying to build this package: https://code.dlang.org/packages/fixed however, the compiler error out: ldc2-1.21.0-linux-x86_64/bin/../import/std/math.d(5783,39): Error: llroundl cannot be interpreted at compile time, because it has no available source code Looks like it does some

Re: how to append (ref) int[] to int[][]?

2020-06-08 Thread mw via Digitalmars-d-learn
On Monday, 8 June 2020 at 06:42:44 UTC, Simen Kjærås wrote: Arrays (technically, slices) in D are essentially this struct: struct Array(T) { T* ptr; size_t length; // operator overloads } So when you have int[][], each element of the outer array is an Array!int. These, as simple

how to append (ref) int[] to int[][]?

2020-06-08 Thread mw via Digitalmars-d-learn
Hi, I have this program: import std.stdio; void f(ref int[] arr) { arr ~= 3; } void main() { int[][] arrs; int[] arr; foreach (i; 0 .. 3) { arr = new int[0]; arrs ~= arr; //(a)

Re: Metaprogramming with D

2020-06-06 Thread mw via Digitalmars-d-learn
On Saturday, 6 June 2020 at 09:57:36 UTC, Jan Hönig wrote: We have two (little) student projects, which should use D for meta-programming/code generation. More specifically string mixins and templates. I found this doc:

Re: how to achieve C's Token Pasting (##) Operator to generate variable name in D?

2020-06-04 Thread mw via Digitalmars-d-learn
On Thursday, 4 June 2020 at 19:42:57 UTC, mw wrote: On Thursday, 4 June 2020 at 18:42:05 UTC, H. S. Teoh wrote: TBH, whenever I run into a diamond inheritance problem or similar, my first reaction is, I'm using the wrong tool for ^^ Haha, it's also because most of

Re: how to achieve C's Token Pasting (##) Operator to generate variable name in D?

2020-06-04 Thread mw via Digitalmars-d-learn
On Thursday, 4 June 2020 at 18:42:05 UTC, H. S. Teoh wrote: TBH, whenever I run into a diamond inheritance problem or similar, my first reaction is, I'm using the wrong tool for modelling my data; I should be using some kind of component-based system instead of OO inheritance. I have no

Re: how to achieve C's Token Pasting (##) Operator to generate variable name in D?

2020-06-04 Thread mw via Digitalmars-d-learn
On Sunday, 31 May 2020 at 06:28:11 UTC, mw wrote: This is better, ... but it breaks std.traits: void main() { auto fields = FieldNameTuple!(Point); writeln(fields); } $ ./b varvarvar And normally, we cannot define 2 fields with different types: class P { int x; double x; // b.d(45):

Re: Logging best practices

2020-05-31 Thread mw via Digitalmars-d-learn
On Sunday, 31 May 2020 at 07:49:01 UTC, Luis wrote: On Saturday, 30 May 2020 at 18:17:21 UTC, mw wrote: A related question: how to log to multiple destinations? e.g. both console & log file? any examples? Thanks. ```D auto multiLogger = new MultiLogger();

Re: how to achieve C's Token Pasting (##) Operator to generate variable name in D?

2020-05-31 Thread mw via Digitalmars-d-learn
On Sunday, 31 May 2020 at 09:37:24 UTC, Ali Çehreli wrote: On 5/31/20 2:26 AM, Ali Çehreli wrote: Ok, I solved that too with a very convoluted "eponymous mixin template opDispatch." :) struct RW(T) { template opDispatch(string name) { static codeImpl() { import std.format;

Re: how to achieve C's Token Pasting (##) Operator to generate variable name in D?

2020-05-31 Thread mw via Digitalmars-d-learn
On Sunday, 31 May 2020 at 00:46:09 UTC, Paul Backus wrote: You can simplify this considerably using a mixin template [1]: --- mixin template RW(T, string name) { private T var; public T get() { return var; } public typeof(this) set(T val) { var = val; return this; }

Re: how to achieve C's Token Pasting (##) Operator to generate variable name in D?

2020-05-30 Thread mw via Digitalmars-d-learn
On Saturday, 30 May 2020 at 22:21:14 UTC, Paul Backus wrote: enum f(string x) = "_" ~ x; int main() { mixin("int ", f!"x", " = 3;"); return _x; } This uses a templated [1] manifest constant [2] to generate the variable name at compile time, and a mixin statement [3] to insert the

how to achieve C's Token Pasting (##) Operator to generate variable name in D?

2020-05-30 Thread mw via Digitalmars-d-learn
I want to generate a new symbol (new variable name) from existing one: e.g. in C: $ cat t.c #define f(x) _##x int main() { int f(x) = 3; return _x; } $ make t cc t.c -o t $ ./t $ echo $? 3 I

Re: Logging best practices

2020-05-30 Thread mw via Digitalmars-d-learn
On Monday, 29 April 2019 at 16:02:25 UTC, Arun Chandrasekaran wrote: std.experimental.logger is perfectly thread safe. However printing the logging thread ID is still pending with this PR https://github.com/dlang/phobos/pull/6978 Also is any file logger thread safe?

Re: Logging best practices

2020-05-30 Thread mw via Digitalmars-d-learn
On Thursday, 25 April 2019 at 10:33:00 UTC, Vladimirs Nordholm wrote: Hello. Is there a current "Best Practices" for logging in D? For the actual logging, I know of `std.experimental.logger`. However, the `experimental` has kept me away from it. Is it good, or are there any better

Re: How to target ldc compiler only in dub

2020-05-26 Thread mw via Digitalmars-d-learn
On Wednesday, 27 May 2020 at 00:54:45 UTC, data pulverizer wrote: On Wednesday, 27 May 2020 at 00:52:55 UTC, mw wrote: On Tuesday, 26 May 2020 at 22:28:14 UTC, data pulverizer wrote: I am trying to build a package to target LDC compiler only. I set env: LDC= DUB = $(LDC)/bin/dub then, run

Re: How to target ldc compiler only in dub

2020-05-26 Thread mw via Digitalmars-d-learn
On Tuesday, 26 May 2020 at 22:28:14 UTC, data pulverizer wrote: I am trying to build a package to target LDC compiler only. I set env: LDC= DUB = $(LDC)/bin/dub then, run this new dub: $(DUB) build

Re: String interpolation

2020-05-21 Thread mw via Digitalmars-d-learn
On Thursday, 21 May 2020 at 06:57:28 UTC, mw wrote: On Thursday, 21 May 2020 at 01:13:27 UTC, Paul Backus wrote: On Wednesday, 20 May 2020 at 23:41:15 UTC, mw wrote: Can we do string interpolation in D now? There's an implementation in the dub package "scriptlike":

Re: String interpolation

2020-05-21 Thread mw via Digitalmars-d-learn
On Thursday, 21 May 2020 at 12:53:50 UTC, Adam D. Ruppe wrote: On Thursday, 21 May 2020 at 06:57:28 UTC, mw wrote: i.e how to write this 's'? gimme a like on the proposal to add to the language! https://github.com/dlang/DIPs/pull/186 If accepted, that would let you write i"stuff here".idup

Re: String interpolation

2020-05-21 Thread mw via Digitalmars-d-learn
On Thursday, 21 May 2020 at 01:13:27 UTC, Paul Backus wrote: On Wednesday, 20 May 2020 at 23:41:15 UTC, mw wrote: Can we do string interpolation in D now? There's an implementation in the dub package "scriptlike": https://code.dlang.org/packages/scriptlike#string-interpolation Thank you!

Re: String interpolation

2020-05-20 Thread mw via Digitalmars-d-learn
On Tuesday, 10 November 2015 at 13:36:44 UTC, Andrea Fontana wrote: On Tuesday, 10 November 2015 at 12:40:07 UTC, Márcio Martins wrote: writeln(interp!"The number #{a} is less than #{b}"); Quite pleasant syntax this way :) Not sure if it's feasible to do this on the language side. Yes. Here