Re: Recommendation on plotting library
20.07.2023 05:37, Chris Piker пишет: Hi D One of my jobs is to release and maintain public data archives from long-running scientific instruments. In order to help people understand how to process the data, sample code is often included with the archive. Recently this has been in the form of short programs that generate a plot of a representative time period. Python works well for this task as matplotlib support is pretty much universal. Matlab is also a reasonable choice for many. Were I to also provide sample code in D, what library would you recommend for scientific plotting, especially for dynamic power spectral densities generated from time-series data (basically heatmaps)? Since dub can pull down dependencies easily enough and since it supports single file projects it seems that D would be well suited to this task, but I've never plotted any data directly from a D program. Many GUI libraries I see for D are wrappers around external C or C++ based libraries that would need to be installed separately. I'd like to avoid such complications if that's possible. Thanks for any advice, https://code.dlang.org/packages/ggplotd
Re: How to free memory ater use of "new" to allocate it.
17.07.2023 15:45, Alain De Vos пишет: This works also: [snipped] Despite this time you use new you still allocate your class on stack using scope and its scope still is `dofun`. But I just want to inform you. Your solutions work. Don't get me wrong. N.B. I would say if you do not have THE reason to manually free memory - do not do this. At all. Just let GC does its work.
Re: How to free memory ater use of "new" to allocate it.
17.07.2023 13:17, Alain De Vos пишет: The following code works: ``` import std.stdio:writefln; import object: destroy; import core.memory: GC; import core.stdc.stdlib: malloc,free; import std.typecons; class C { int * pa; int [] a; // Constructor this() {writefln("Called constructor"); pa=cast(int *)malloc(1000*int.sizeof); a=pa[0..1000]; } ~this(){ writefln("Called Destructor"); free(a.ptr);} } void dofun() { auto x=scoped!(C); x.a[3]=5; writefln("%12x",); } int main(){ dofun(); dofun(); return 0; } ``` Note that you do not use new anymore. You allocate your class instances on stack and their scope is `dofun()` only
Re: How get struct value by member name string ?
30.05.2023 11:46, John Xu пишет: How to put above enum as a function parameter? Following code wouldn't work: string getTMember(T t, enum string memberName) { return __traits(getMember, t, memberName); } My database table is very wide, with many columns. Above ddbc allows a struct to map db returned data. Then if I want a member's value to show in vibe.d template, how do I use a function to get it? This works for me: ```D import std; void main() { struct T {int a; string name;} auto t = T(12, "got by member name"); enum s = "name"; writeln(__traits(getMember, t, s)); } ```
Re: Coding Challenges - Dlang or Generic
10.01.2023 14:23, drug007 пишет: 10.01.2023 13:57, matheus пишет: On Tuesday, 10 January 2023 at 05:21:15 UTC, H. S. Teoh wrote: Printing it in this format is trivial, and not very interesting. The interest in the challenge is to lay it out like I posted, side-by-side,... Like I said I did it over D online compiler which unfortunately I couldn't validate the output because it "wraps" the text, and the font wasn't monospace. But It just a case of changing the loop in a way to print 3 groups of months. ... and to do so in a way that the code is clean, maintainable, and consists of reusable components. ... Talking about modularity and reusable components, I really think it depends, because if that's was really the case, then I would think of using the OS functions to move the cursor around (If console/terminal) to print a given month in some location or side by side until reach some horizontal limit (Terminal), then it could be 1 column only (Like I did), 2, 3 and maybe 4 columns if the terminal/resolution permit, and for that I would use ARSD. :] But I think this would be too much for this kind of thing writing on online compiler. ... That's where the challenge lies. To be honest when I saw your proposal, I really thought that the real challenge would be to write my own algo to handle the date, and I was pretty sure after posting above, you would say that, but not about the layout or printing in groups. =] Matheus. [To clarify the situation](https://wiki.dlang.org/Component_programming_with_ranges) (H S Teoh is the author of this article) Also I'd like to add that this article inspired Eric Niebler to write ranges for C++. Now C++ has already 3rd version of ranges and they are still not used in general.
Re: Coding Challenges - Dlang or Generic
10.01.2023 13:57, matheus пишет: On Tuesday, 10 January 2023 at 05:21:15 UTC, H. S. Teoh wrote: Printing it in this format is trivial, and not very interesting. The interest in the challenge is to lay it out like I posted, side-by-side,... Like I said I did it over D online compiler which unfortunately I couldn't validate the output because it "wraps" the text, and the font wasn't monospace. But It just a case of changing the loop in a way to print 3 groups of months. ... and to do so in a way that the code is clean, maintainable, and consists of reusable components. ... Talking about modularity and reusable components, I really think it depends, because if that's was really the case, then I would think of using the OS functions to move the cursor around (If console/terminal) to print a given month in some location or side by side until reach some horizontal limit (Terminal), then it could be 1 column only (Like I did), 2, 3 and maybe 4 columns if the terminal/resolution permit, and for that I would use ARSD. :] But I think this would be too much for this kind of thing writing on online compiler. ... That's where the challenge lies. To be honest when I saw your proposal, I really thought that the real challenge would be to write my own algo to handle the date, and I was pretty sure after posting above, you would say that, but not about the layout or printing in groups. =] Matheus. [To clarify the situation](https://wiki.dlang.org/Component_programming_with_ranges) (H S Teoh is the author of this article)
Re: Is `void` the correct way to say "do not initialize this variable"?
On 10/3/22 09:35, tsbockman wrote: On Sunday, 2 October 2022 at 23:45:45 UTC, drug007 wrote: It works but not as someone could expect. In case of ```D Foo[2] arr = void; ``` `arr` value is not defined, it is not an initialized array of uninitialized elements like you want, it is just uninitialized array. This is incorrect. It is not possible to declare an uninitialized static array variable in D; only the elements are affected by `= void`. The meta data of a static array like `Foo[2] arr` (`.ptr` and `.length`) is determined statically at compile time and inserted where needed into the generated code. It is not stored in mutable memory the way a dynamic array/slice's meta data is, and does not need to be initialized at run time. You are right. I used to complex structure (with indirections) for testing and made wrong statement. By contrast, it **is** possible to declare a completely uninitialized dynamic array, or to just leave its elements uninitialized: ```D // Meta data is not initialized, and no elements are allocated. // This has no static array equivalent: int[] arrA = void; // Meta data is initialized, and elements are allocated but not initialized. // This is the dynamic equivalent of the static: // int[2] arr = void; int[] arrB = uninitializedArray!(int[])(2); ```
Re: Is `void` the correct way to say "do not initialize this variable"?
On 10/3/22 02:30, ryuukk_ wrote: I have tried to look at the documentation and various places on the DMD source, but i couldn't find the answer https://dlang.org/spec/declaration.html#void_init ```D MyStruct test = void; ``` Does this guarantee that the compiler will not initialize it? Yes Does it work with static arrays of struct too? It works but not as someone could expect. In case of ``` Foo[2] arr = void; ``` `arr` value is not defined, it is not an initialized array of uninitialized elements like you want, it is just uninitialized array. The generated code is different than ``MyStruct test;`` What exactly (by exactly i mean is the behavior documented somewhere?) ``void`` does?
Re: std.container.array.Array is not @nogc?
On 15.01.2017 15:49, Jack Stouffer wrote: No you're not. Array was designed before the @nogc attribute was created, so it wasn't coded with it's requirements in mind. Looking at the code, Array allocates GC memory for exception throwing in some cases. These can and should be changed to asserts. I am writing a PR now to fix this. There doesn't seem to be too many cases to fix. Thanks for answer. Looking forward for your PR.
std.container.array.Array is not @nogc?
Is there a way to use Array in @nogc code: ``` import std.container.array : Array; @nogc: void main(string[ ] args) { Array!int ai; ai ~= 1; assert(ai[0] == 1); } ``` fails: ``` main.d(8): Error: @nogc function 'D main' cannot call non-@nogc function 'std.container.array.Array!int.Array.opOpAssign!("~", int).opOpAssign' main.d(9): Error: @nogc function 'D main' cannot call non-@nogc function 'std.container.array.Array!int.Array.opIndex' ``` am I doing something wrong?
Re: Accessing members through pointers to structs (also, CTFE associative arrays)
On 13.12.2016 23:30, Ali wrote: Hi, Long time watcher and recently started playing with D a bit more. Ran in to a couple of snags that I'll combine in one post. It involves a data set that contains a list of strings. Each string represents a Room name. What I'm trying to do is pluck out the room names and also calculate the frequency each letter occurs in a name, per room. First problem is to do with pointers to structs. Here's the code: static immutable rooms = import("data.txt").split("\n").map!parse.array; static Tuple!(const(Room*), "room", int[char], "frequencies")[rooms.length] data; static this() { foreach (i, room; rooms) { data[i].room = // Also calculate frequencies, but that's not important yet. } } void main() { foreach (d; data) { d.room.name.writeln; // <-- How do I access name here?? } } I've tried d.(*room).name but that didn't work. There's no arrow I'm sleepy, sorry for quick and probable wrong answer - try (*d.room).name
Re: Using the result of a comma expression is deprecated
On 27.11.2016 14:07, Suliman wrote: I am getting deprecation message: "Using the result of a comma expression is deprecated" on this code: string sqlinsert = (`INSERT INTO usersshapes (userlogin, uploading_date, geometry_type, data) VALUES ('%s', '%s', '%s', '%s') `, login, uploading_date, geometry_type, data); What's wrong with it? Didn't you miss something like class/structure/function before "(`INSERT..."? What result do you expect?
Re: How do i convert this Makefile to dub
On 08.08.2016 21:48, Adil wrote: On Monday, 8 August 2016 at 18:45:35 UTC, drug007 wrote: On 08.08.2016 21:35, Adil wrote: On Monday, 8 August 2016 at 18:29:54 UTC, Adil wrote: [...] One minor addition. I use the Makefile in our CI tool, that inserts auto-increment numbers in place of git hashes. Numbers are a familiar. Ex: make VERSION_STRING=v%build.number%; make screener-d-debug VERSION_STRING=v%build.number%; Can i insert a version number when i run dub? You can do it by using `preBuildCommands` in dub.sdl, see http://code.dlang.org/package-format?lang=sdl How can i pass a VERSION_STRING from the cmd line? I don't know about passing from cli, but you can redirect output to some .d file and import it, for example.
Re: How do i convert this Makefile to dub
On 08.08.2016 21:35, Adil wrote: On Monday, 8 August 2016 at 18:29:54 UTC, Adil wrote: I have a Makefile setup that I use to return the latest git tag/commit from within my program. The setup is as below: VERSIONED_LIB = myversion.d && rm -f myversion.d VERSION_STRING ?= $(shell git rev-parse --short HEAD) makeVersion: echo "module compileConfig; public string versionString = \"$(VERSION_STRING)\";" > myversion.d; mysoftware: makeVersion dmd -de -O /* compiler flags */ source/myprogrma.d myversion.d rm -f myversion.d When i run `make mysoftware` my binary now contains the latest git commit HASH, which i use for debugging. How can i mimic the same setup i dub? Is there an alternative to achieve the same goal? One minor addition. I use the Makefile in our CI tool, that inserts auto-increment numbers in place of git hashes. Numbers are a familiar. Ex: make VERSION_STRING=v%build.number%; make screener-d-debug VERSION_STRING=v%build.number%; Can i insert a version number when i run dub? You can do it by using `preBuildCommands` in dub.sdl, see http://code.dlang.org/package-format?lang=sdl
Re: Array of const objects with indirections and std.algorithm.copy
On 28.07.2016 21:45, Ali Çehreli wrote: On 07/27/2016 04:51 AM, drug wrote: > cfoo.copy(foo); // fails to compile because phobos in case of array uses > // array specialization and this specialization fails > // see > https://github.com/dlang/phobos/blob/v2.071.1/std/algorithm/mutation.d#L333 Thanks for explaining further. Yes, this is a bug. Although areCopyCompatibleArrays!(const(Foo)[], Foo[]) is true, std.algorithm.copy of that specialization fails. Please create a bug report at https://issues.dlang.org/ Thank you, Ali Thank you too. done https://issues.dlang.org/show_bug.cgi?id=16332