Re: Recommendations on porting Python to D
On Wednesday, 24 April 2024 at 19:50:45 UTC, Chris Piker wrote: I can just call my old C code from D, but the old Python is another story. Thanks for any advice you may have, You could also try some AI solution
Serial communication library
Hi guys! What's the best/preferred library to use for serial communication (RS)? Thanks 🍀
Re: Serial communication library
On Thursday, 22 September 2022 at 12:05:00 UTC, Imperatorn wrote: Hi guys! What's the best/preferred library to use for serial communication (RS)? Thanks 🍀 I will give onyx-serial a try
Re: Interfacing with Rust
On Friday, 30 September 2022 at 00:18:42 UTC, Ruby The Roobster wrote: On Thursday, 29 September 2022 at 16:07:59 UTC, mw wrote: On Thursday, 29 September 2022 at 16:02:43 UTC, Ruby The Roobster wrote: Is there any way one can interface with Rust, such as with a struct, or a function? I know that rust has an extern keyword, but I can't get it to work. https://code.dlang.org/packages/rust_interop_d Read the notes on memory management: Only pass pointers as u64 as value type. This isn't the issue. I can't interface anything, period. Show an example of exactly what you're trying to do. Maybe it's some detail
D installer
I only have Visual Studio 2022. Will the installer be updated to support that or am I missing some components? ![Installer](https://i.ibb.co/sCZRFRf/installer.jpg) Thanks!
Re: D installer
On Sunday, 2 October 2022 at 12:37:37 UTC, Mike Parker wrote: On Sunday, 2 October 2022 at 11:33:47 UTC, Imperatorn wrote: I only have Visual Studio 2022. Will the installer be updated to support that or am I missing some components? ![Installer](https://i.ibb.co/sCZRFRf/installer.jpg) You should be fine. Select the bottom option since you already have it installed. Thanks for a quick reply!
Re: How do I correctly install packages for use with Visual Studio?
On Sunday, 16 October 2022 at 11:42:04 UTC, matheus wrote: On Sunday, 16 October 2022 at 11:09:31 UTC, Decabytes wrote: I'm trying to set up Visual Studio 2022 with Visual D, and I'm running into issues trying to get my project to build correctly. It's a double whammy because I've never used Visual Studio before (Just an Emacs Guy), but I need to debug my D programming and according to the [documentation](https://wiki.dlang.org/Debuggers) this is my only option on Windows. I don't know if anything changed significantly, but I used to debug on Windows with WinDbg without any IDE. Maybe this is useful: https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-download-tools Matheus. I also *highly* recommend WinDbg Preview https://apps.microsoft.com/store/detail/windbg-preview/9PGJGD53TN86
Re: How to pass noncopyable variadic arguments with ref?
On Thursday, 20 October 2022 at 14:03:10 UTC, tchaloupka wrote: Hi, I've found strange behavior where: ```D import std.stdio; struct Foo { @disable this(this); int x; } void test(Foo[] foos...) { foreach (ref f; foos) { writeln(&f, ": ", f.x); f.x = 0; } } void main() { Foo f1 = Foo(1); Foo f2 = Foo(2); writeln("f1: ", &f1); writeln("f2: ", &f2); test(f1, f2); writeln("f1: ", f1.x); writeln("f2: ", f2.x); } ``` Compiles fine (no error on passing noncopyable arguments to the function), but there are other objects passed to the function as they aren't cleared out in the caller scope. Shouldn't it at least protest that objects can't be passed to the function as they aren't copyable? Have you looked at the ast?
Re: is dmd a virus?
On Saturday, 22 October 2022 at 07:40:39 UTC, MGW wrote: is dmd a virus? https://www.virustotal.com report: Cybereason --> Malicious.779f29 VBA32 --> BScope.Trojan.DShell Yes, it's a virus... 😇 No, it's a false positive
Re: Hipreme's #2 Tip of the day - Reducing .di files dependency
On Monday, 24 October 2022 at 12:10:19 UTC, Nick Treleaven wrote: On Sunday, 23 October 2022 at 20:12:46 UTC, Hipreme wrote: For reducing a D Interface file dependency when generating it with the `-H` flag for DMD, you can't import a module on the top level. Take a look at that example: This would make a nice blog post if you have one ;-) Indeed, D needs more blogs
Re: Disabling All Inlining in DMD Debug Builds
On Monday, 24 October 2022 at 19:28:34 UTC, Jack Stouffer wrote: I use ``` pragma(inline, true) function definition ``` all over my code. And by default, DMD inlines these functions even in debug builds, which normally is great. I have a custom dynamic array container and if the indexing operator overload function wasn't inlined the debug build would have a ~10x slowdown and become un-testable in many ways. What sucks about this is that stepping through the code in a debugger is way worse because the the "step-over" operation no longer works properly. Maybe this is a bug in the PDB output, but trying to step over an inlined function call still takes you into the inlined function body as if it were a step-in. So is there a way to tell DMD to ignore these pragmas in certain builds? Search and replace pragma(inline, true) with //pragma(inline, true) ;)
Re: Supporting foreach (k, v; T.init) for a user-defined (container) type
On Monday, 24 October 2022 at 21:52:18 UTC, Ali Çehreli wrote: On 10/24/22 14:26, Per Nordlöw wrote: [...] Another option is to use range functions where front() returns a Tuple. We have an esoteric feature where a tuple expands automatically in foreach loops: import std.typecons : tuple; import std.conv : to; import std.stdio : writeln; import std.range : take; struct S { size_t count; bool empty = false; auto front() { const key = count; const value = key.to!string; return tuple(key, value);// <-- HERE } void popFront() { ++count; } } void main() { foreach (k, v; S.init.take(10)) { writeln(k, ": ", v); } } Ali I didn't know about that esoteric feature. like this approach
Re: how to benchmark pure functions?
On Thursday, 27 October 2022 at 17:17:01 UTC, ab wrote: Hi, when trying to compare different implementations of the optimized builds of a pure function using benchmark from std.datetime.stopwatch, I get times equal to zero, I suppose because the functions are not executed as they do not have side effects. The same happens with the example from the documentation: https://dlang.org/library/std/datetime/stopwatch/benchmark.html How can I prevent the compiler from removing the code I want to measure? Is there some utility in the standard library or pragma that I should use? Thanks AB Sorry, I don't understand what you're saying. The examples work for me. Can you provide an exact code example which does not work as expected for you?
Re: how to benchmark pure functions?
On Friday, 28 October 2022 at 09:48:14 UTC, ab wrote: On Thursday, 27 October 2022 at 17:17:01 UTC, ab wrote: [...] Thanks to H.S. Teoh and Dennis for the suggestions, they both work. I like the empty asm block a bit more because it is less invasive, but it only works with ldc. @Imperatorn see Dennis code for an example. std.datetime.benchmark works, but at high optimization level (-O2, -O3) the loop can be removed and the time brought down to 0hnsec. E.g. try "ldc2 -O3 -run dennis.d". AB Yeah I didn't read carefully enough sorry 🌷
Re: ImportC in a Dub project
On Friday, 28 October 2022 at 17:45:59 UTC, Carsten Schlote wrote: Hi, I created a Dub project containing two files: app.d and zstd_binding.c [...] Are you using DMD?
Re: ImportC in a Dub project
On Friday, 28 October 2022 at 18:43:21 UTC, Carsten Schlote wrote: On Friday, 28 October 2022 at 18:31:25 UTC, Steven Schveighoffer wrote: [...] ``` $ cat dub.json { "authors": [ "Carsten Schlote" ], "copyright": "Copyright © 2022, Carsten Schlote", "description": "A minimal D application.", "license": "proprietary", "name": "importc-app", "lflags": [ "-lzstd", "zstd_binding.o" ], "preBuildCommands": [ "gcc -g -O0 -c -o zstd_binding.o source/zstd_binding.c"] ``` [...] Like schveiguy said, what's your build line? dmd should pick up the file if the import has the same name as the file.
Re: ImportC in a Dub project
On Friday, 28 October 2022 at 19:04:21 UTC, Carsten Schlote wrote: On Friday, 28 October 2022 at 18:56:03 UTC, Imperatorn wrote: Like schveiguy said, what's your build line? dmd should pick up the file if the import has the same name as the file. What do you mean with 'buildline'? The project is build with dub. See previous posts with outputs from commandline. DMD does find and import the C file. But it doesn't create code for ```relatedCode()``` in the C file. The only way to fix this, is to compile it with a C compiler and use the object as additional linker output. IMHO this is a bug. Have you read this? https://dlang.org/spec/importc.html
Re: Applied fix to Dub (Was: ImportC in a Dub project )
On Sunday, 30 October 2022 at 12:46:10 UTC, Carsten Schlote wrote: It turned out, that the required changes to add support for C files in Dub are really small. So I added a PR (https://github.com/dlang/dub/pull/2521). There is also some other PR (https://github.com/dlang/dub/pull/2270) releated to C file support in Dub. [...] Agreed, but don't forget about the .i extension. Imo we could add a switch which enables something like your PR (include .c and .i) until we know what the default should be.
Re: Applied fix to Dub (Was: ImportC in a Dub project )
On Sunday, 30 October 2022 at 14:42:55 UTC, Carsten Schlote wrote: On Sunday, 30 October 2022 at 13:38:23 UTC, Imperatorn wrote: [...] I will merge the two PRs into a new patchset, and also add appropriate code to search für {c|i|h} files at the right places. The patchset should be as minimal as possible, so that the planned better solution is not blocked/messed up. [...] Maybe a switch/flag should be added to the dub.json/sdl files to turn on the new behaviour? This allows to enable the new search logic for C files without breaking something old. It would make it more clear, that also a new 2.101+ D compiler is needed. Yeah maybe something like that. Because I agree we need to update it since we now have ImportC.
Re: overloading main
On Sunday, 30 October 2022 at 16:09:54 UTC, NonNull wrote: I am linking to a C project with some C already automatically translated into D including the C main function `int main(int argc, char** argv){/* ... */}` which I wanted to call from a D main function in a new module. But then I found that the former C main in D will not compile! ldc2 complains that main must only have prototypes as if it is the entry point. So it seems that main cannot be overloaded with a prototype that is not a valid entry point in D. Is this restriction essential? And if not, why make it? You should not have multiple mains. Rename it and call it
Re: overloading main
On Sunday, 30 October 2022 at 17:29:25 UTC, NonNull wrote: On Sunday, 30 October 2022 at 16:31:45 UTC, Imperatorn wrote: You should not have multiple mains. Rename it and call it Doesn't answer my questions. I wasn't asking for practical, moral or esthetic advice. Try to phrase your question more clearly. I'm just stating a fact.
Re: overloading main
On Sunday, 30 October 2022 at 23:43:03 UTC, NonNull wrote: On Sunday, 30 October 2022 at 18:24:22 UTC, Adam D Ruppe wrote: [...] Ah, makes sense to limit the possible low level error messages with separate compilation because of the linker not knowing D signatures. Thanks for the intuition. I thought this was too obvious to say, but apparently not.
Re: A strange DMD error
On Tuesday, 1 November 2022 at 15:40:04 UTC, Keivan Shah wrote: Hello, Today I came across a strange bug while using D with `dmd`. I have still not been able to figure out under what conditions does it happen but it seems to be a DMD related bug to me. Here is a reproducible snippet of the code [...] Could be there's some restriction in DMD on number of arguments. May I ask if this was just an experiment? I hope you're not having code like that in the wild 🙏
Re: A strange DMD error
On Tuesday, 1 November 2022 at 15:49:54 UTC, Keivan Shah wrote: On Tuesday, 1 November 2022 at 15:42:43 UTC, Imperatorn wrote: On Tuesday, 1 November 2022 at 15:40:04 UTC, Keivan Shah wrote: [...] Could be there's some restriction in DMD on number of arguments. May I ask if this was just an experiment? I hope you're not having code like that in the wild 🙏 Possible, but I think I have had code with more arguments than this and it has worked 😅 Unfortunately, not an experiment. Although have replaced the types so seems silly now, this is part of my constructor for a huge co-coordinator class that takes too many configurable start time parameters and so need to pass these many arguments. Keivan Hehe. One simple thing you could do is to create a struct instead for you params and pass that
Re: druntime thread (from foreach parallel?) cleanup bug
On Tuesday, 1 November 2022 at 19:49:47 UTC, mw wrote: On Tuesday, 1 November 2022 at 18:18:45 UTC, Steven Schveighoffer wrote: [...] Maybe the hunt library author doesn't know. (My code does not directly use this library, it got pulled in by some other decencies.) [...] Please, if you see anything in the docs that needs to be updated, make a PR right away <3 Documentation saves lives! The times I have thought "I'll do it later" have been too many.
Re: Unit testing a function returning void
On Thursday, 3 November 2022 at 10:00:27 UTC, Bruno Pagis wrote: Good morning, I have the following class: ``` class A { int[] array; ... void print() { writeln("array = ", this.array); } } ``` I would like to unit test the print function (yes, I know, not very useful on the above example since print is merely a duplicate of writeln...). Is there a way to use assert to test the output of the print function to stdout? Something like: ``` A myClass= new A; myClass.array = [1,2]; assert(myClass.print() == "array = [1,2]"); // I know that print does not return anything so this is wrong, but you get the idea :-) ``` Thanks. Just so we understand, do you want to verify that the output is indeed directed to stdout and not some other stream?
Re: Unit testing a function returning void
On Thursday, 3 November 2022 at 10:26:04 UTC, Imperatorn wrote: On Thursday, 3 November 2022 at 10:00:27 UTC, Bruno Pagis wrote: Good morning, I have the following class: ``` class A { int[] array; ... void print() { writeln("array = ", this.array); } } ``` I would like to unit test the print function (yes, I know, not very useful on the above example since print is merely a duplicate of writeln...). Is there a way to use assert to test the output of the print function to stdout? Something like: ``` A myClass= new A; myClass.array = [1,2]; assert(myClass.print() == "array = [1,2]"); // I know that print does not return anything so this is wrong, but you get the idea :-) ``` Thanks. Just so we understand, do you want to verify that the output is indeed directed to stdout and not some other stream? Just for documentation purposes, if you wished to redirect I believe you could do something like this (untested): ```d auto original = stdout; // save stdout.open(newdest, "wt"); // redirect // do stuff, check newdest stdout = original; // restore ```
Re: Hipreme's #3 Tip of the day - Changing DMD linker on Windows
On Tuesday, 1 November 2022 at 16:17:08 UTC, Hipreme wrote: The linker used on Windows when installing DMD is pretty much decided on how your PC was setup. [...] Do you have a blog?
Re: save() feature for iota
On Friday, 4 November 2022 at 08:48:36 UTC, Salih Dincer wrote: On Thursday, 3 November 2022 at 11:58:20 UTC, Paul Backus wrote: On Thursday, 3 November 2022 at 06:26:22 UTC, Salih Dincer Looking at the source, it seems that only the numeric overloads of `iota` implement `save`. I think this is probably just an oversight, though, since I can't see any reason why `save` wouldn't work just as well for the generic version. The problem I'm having here seems to be chunk related. But using a template like iota!char for some reason does not affect the output result. I showed these situations in the example in the Turkish forum: https://forum.dlang.org/thread/jbklbbozmisahohou...@forum.dlang.org SDB@79 See Pauls response
Re: Makefiles and dub
On Saturday, 5 November 2022 at 11:38:09 UTC, rikki cattermole wrote: We have a few build formats that dub can generate for you automatically: ``` visuald - VisualD project files sublimetext - SublimeText project file cmake - CMake build scripts build - Builds the package directly ``` Unfortunately none of them are make, it would be nice to have that if you are looking to contribute! Wait, dub can generate all those? I only knew about visuald
Re: Linking not working properly Windows 11
On Saturday, 5 November 2022 at 13:30:43 UTC, bauss wrote: Fresh install of DMD and when trying to use ex. std.file from Phobos I get the following linking error: (I can trigger different ones depending on modules imported etc.) [...] Im also on Windows 10 and 11 and don't have any problems with dmd
Re: My new programming book ...
On Sunday, 6 November 2022 at 22:43:33 UTC, ikelaiah wrote: Hi, I got a new programming book yesterday, authored by Adam D. Rupee. [...] Agreed. It's a great book with a "get it done"-attitude <3
Re: dirEntries removes entire branches of empty directories
On Wednesday, 9 November 2022 at 19:05:58 UTC, Ali Çehreli wrote: In case it matters, the file system is ext4. 1) Create a directory: [...] That's not the behaviour I get in Windows. When I create the subdirectory, I see it even if it's empty
Re: dirEntries removes entire branches of empty directories
On Wednesday, 9 November 2022 at 20:06:15 UTC, Ali Çehreli wrote: On 11/9/22 11:05, Ali Çehreli wrote: It was pretty easy to use but there is a quality issue there: They failed to support a 'void*' context for the user! You can walk the tree but can't put the results into your local context! Boo! 👻
Re: dirEntries removes entire branches of empty directories
On Wednesday, 9 November 2022 at 19:59:57 UTC, Ali Çehreli wrote: On 11/9/22 11:48, Imperatorn wrote: > That's not the behaviour I get in Windows. Windows users deserve it! :p (At least it is better in this case. :) ) > When I create the subdirectory, I see it even if it's empty struct DirIteratorImpl has different implementations for Windows, etc. Ali Anyway, it's definitely a bug in that implementation
Re: dirEntries removes entire branches of empty directories
On Thursday, 10 November 2022 at 16:34:53 UTC, Ali Çehreli wrote: On 11/9/22 11:30, Vladimir Panteleev wrote: > On Wednesday, 9 November 2022 at 19:05:58 UTC, Ali Çehreli wrote: >> Running the program shows no output; 'a' is not visited as a directory >> entry. > > That's not what happens for me: Does not happen for me today either. (?) I must have confused myself both with my actual program and with a trivial isolated program that I had written to test it. Unless others have seen the same behavior yesterday there is no bug here today. :p Ali "walks away with a confused look on his face" Oh, did you run the program on Wednesday? Fool!
Re: Making sense out of scope and function calls
On Sunday, 13 November 2022 at 19:06:40 UTC, 0xEAB wrote: ```d struct Foo { /* … */ hstring[] getHeader(LowerCaseToken name) scope return { return _headers[name].values; } [...] There's an old saying "you can't make sense out of scope"
Re: Proper way to exit with specific exit code?
On Sunday, 13 November 2022 at 21:37:47 UTC, mw wrote: On Sunday, 13 November 2022 at 21:16:32 UTC, mw wrote: I even tried core.stdc.stdlib.exit(-1), it does not work. Tried ``` import core.runtime; Runtime.terminate(); core.stdc.stdlib.exit(-1); ``` Still does not work. I have no idea why it would fail. What about assert(0)?
Re: How to work with long paths on Windows?
On Tuesday, 13 September 2022 at 19:54:15 UTC, Preetpal wrote: In Windows 10, Version 1607 (and later), you can [enable long paths](https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry) which bypasses the MAX_PATH limitation for local paths (e.g., C:\Users\you\log.txt). Currently if you iterate over a directory with a file exceeding the MAX_PATH limitation for local paths, an exception is thrown. There is no limitation on Linux (tested using GDC on the Windows Subsystem for Linux) and this issue occurs when using either the LDC2 or DMD compilers on Windows. It's very common to have these sorts of paths if you use [npm](https://www.npmjs.com/). [...] Have you set longPathAware in the applications manifest?
Re: How to work with long paths on Windows?
On Monday, 14 November 2022 at 10:44:11 UTC, Imperatorn wrote: On Tuesday, 13 September 2022 at 19:54:15 UTC, Preetpal wrote: In Windows 10, Version 1607 (and later), you can [enable long paths](https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry) which bypasses the MAX_PATH limitation for local paths (e.g., C:\Users\you\log.txt). Currently if you iterate over a directory with a file exceeding the MAX_PATH limitation for local paths, an exception is thrown. There is no limitation on Linux (tested using GDC on the Windows Subsystem for Linux) and this issue occurs when using either the LDC2 or DMD compilers on Windows. It's very common to have these sorts of paths if you use [npm](https://www.npmjs.com/). [...] Have you set longPathAware in the applications manifest? "If possible, you should embed the application manifest as a resource in your application's .exe file or .dll. If you can't do that, then you can place the application manifest file in the same directory as the .exe or .dll" "By convention an application manifest should have the same name as your app's executable file, with the .manifest extension appended to it" Here's an example ```xml xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings";> true ```
Re: How to work with long paths on Windows?
On Monday, 14 November 2022 at 14:43:50 UTC, Preetpal wrote: On Monday, 14 November 2022 at 10:44:11 UTC, Imperatorn wrote: On Tuesday, 13 September 2022 at 19:54:15 UTC, Preetpal wrote: [...] Have you set longPathAware in the applications manifest? Yeah that's how I dealt with the issue. I just replied to my own question with a working example that people who might find this post can refer to: [gist](https://gist.github.com/preetpalS/2fd6c6bf05a94734f89b70b679716bf3) (see my comment in the gist for how to make it work). 👍
Re: Get the class name without casting the type
On Tuesday, 15 November 2022 at 12:25:22 UTC, Hipreme wrote: On Tuesday, 15 November 2022 at 11:42:59 UTC, Alexander Zhirov wrote: As shown you can use Object for this. Side-note, you don't override interface members, you implement them. ```d interface A { string text(); } class B : A { string text() { return ": To B or not to B!"; } } class C : A { string text() { return ": Oh I C!"; } } void main() { Object[] a = new B[3]; B b = new B(); C c = new C(); fill(a, b); //Just to show a[0] = c; foreach (val; a) { writeln(typeof(val).stringof, val.text()); } } ```
Re: Running GtkD programs on macOS
On Tuesday, 29 November 2022 at 07:17:09 UTC, Joel wrote: On Saturday, 30 November 2019 at 00:17:51 UTC, Mike Wey wrote: On 29-11-2019 04:40, Joel wrote: Oh, I used 'brew install gtk+3', and the test program worked, but (see below) I don't know about all that installing - is that alright? They all look like GTK+ dependencies so that would be alright/ Update: Three years to the day (from when I posted on here about it), since upgrading to macOS Ventura I've found my GTK+ programs work again! Yay. It never stopped working on my Windows computer. The DLangui hasn't been working on Windows though. There is progress on dlangui nowadays though
Re: Terminating the process of a running LDC2 compiler.
On Wednesday, 1 March 2023 at 11:38:11 UTC, realhet wrote: Hello, Is it safe to kill an ongoing LDC2 process on Windows? My situation is this: - I launch 8 LDC2 compilation command lines on 8 DLang source files. - One of them has a compilation error and quits. - At this point I wait the completion of the other threads, but it would be faster to kill all those threads, fix the error, and run the multithreaded compilation again. Is it safe to kill those processes, or would it be unreliable (because of the integrity of environment variables, and/or cached temp files)? Thank You! We don't know what you mean by your definition of safe unfortunately
Re: C to D: please help translate this weird macro
On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote: Here is the macro: ```C #define NK_CONTAINER_OF(ptr,type,member)\ (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member))) ``` I'm trying to translate the Nuklear GUI library to D [here](https://github.com/rillki/nuklear-d/tree/nuklear-d-translation). When you're done, will you put it on dub?
Re: Detect 8-bit alligned type TXY by TX,TY.
On Tuesday, 19 September 2023 at 06:41:49 UTC, Vitaliy Fadeev wrote: On Tuesday, 19 September 2023 at 06:33:25 UTC, Richard (Rikki) Andrew Cattermole wrote: [...] Thank, Richard. ```.offsetof...``` mmm... May be exists some like: ```d // TXYXY = Detect!(TX,TX) // Detect!(uint,uint) == ulong template Detect(TX,TY) { static if ( TX.sizeof + TY.sizeof <= 8 ) alias Detect = ubyte; else static if ( TX.sizeof + TY.sizeof <= 16 ) alias Detect = ushort; else static if ( TX.sizeof + TY.sizeof <= 32 ) alias Detect= uint; else static if ( TX.sizeof + TY.sizeof <= 64 ) alias Detect= ulong; else static if ( TX.sizeof + TY.sizeof <= 128 ) alias Detect= ucent; else static assert( 0, "Expected size TX+TY <= 128" ); } ``` Do a mixin
Re: change object class
On Sunday, 17 September 2023 at 15:05:59 UTC, Vitaliy Fadeev wrote: Hi! I want to change a method ```Draw``` on a custom object when the ```MouseIn``` event occurs. This is known as "Change State" of the object: ```Init``` -> ```Hovered```. [...] Interesting, but why would you want to do it that way? 😳
Re: change object class
On Friday, 22 September 2023 at 03:33:08 UTC, Vitaliy Fadeev wrote: On Friday, 22 September 2023 at 02:51:10 UTC, Vitaliy Fadeev wrote: ... ``` Chip id name Sense() Draw() ``` instance ``` chip = new Chip(); ``` compiled to ``` chip __vtbl -> Chip __monitor Sense() idDraw() name ``` I want ``` chip __vtbl --+ id | name | |-> Chip_Hovered | Sense() | Draw() | +-> Chip_Hovered Sense() Draw() ``` What I mean is, why not use other language constructs like mixins or inheritance with some mapping for example?
Re: parallelism with delegate
On Friday, 22 September 2023 at 04:24:19 UTC, Vitaliy Fadeev wrote: able ? how to use correctly? ```d import std.parallelism; auto async_task = task!fn( args ); // error // Error: no property `opCall` for type `app.A`, did you mean `new A`? async_task.executeInNewThread(); ``` where ```d auto a = new A(); auto fn = &a.download; class A { void fn( string url ) { // DO } } ``` Playground: https://run.dlang.io/is/HvhtoP gist: https://gist.github.com/run-dlang/218b69e1afd79e5944ea10aa7ca61e1b Also check out std.concurrency
Re: change object class
On Friday, 22 September 2023 at 14:03:40 UTC, Vitaliy Fadeev wrote: On Friday, 22 September 2023 at 12:53:28 UTC, Imperatorn wrote: On Friday, 22 September 2023 at 03:33:08 UTC, Vitaliy Fadeev wrote: [...] What I mean is, why not use other language constructs like mixins or inheritance with some mapping for example? Can you give an example? You're basically just describing polymorphism. I can post an example tomorrow, it's midnight here now.
Re: Vibe.d download function, how to get callback when done or error?
On Saturday, 23 September 2023 at 12:07:38 UTC, Joe wrote: I'm using download(url, filename) to download files in vibe.d. The issue is that I do not know when the download is finished or errors. There is a callback for the streaming side but not for the file download. If you want an asynchronous download just create a task or use spawn. Apparently there's also this in vibe: https://vibed.org/api/vibe.core.concurrency/async
Re: Is it possible to create a kernel for an operating system in D?
On Tuesday, 26 September 2023 at 03:31:36 UTC, I come from chill. wrote: It seems very obvious, but I have not been able to find any information on the subject to confirm this. So I'm wondering if it's possible. ** Maybe I shouldn't have created the account, literally this will be one of the few doubts I'll have about D :u, but it'll be worth it I guess **. A bit old but you can read about it: https://github.com/PowerNex/PowerNex https://github.com/Rikarin/Trinix https://github.com/xomboverlord/xomb/tree/unborn https://wiki.osdev.org/D_Bare_Bones
Re: Binary size optimization
On Thursday, 28 September 2023 at 08:38:42 UTC, Imperatorn wrote: Today I randomly tried compiling a hello world using DMD, LDC and gcc (yes, not gdc) I compared binary sizes and something looked off. The D ones were much larger. Sometimes 10x, with some optimizations still about 2x. But, then I tried using shared default lib and the size is even smaller than the one produced by gcc -Os! I just did two versions, one with betterC with extern(C) and one with std.stdio : printf (I didn't try dmd since I couldn't figure out easily how to share lib) [1] ldc2 -O -release -link-defaultlib-shared -betterC app.d [2] ldc2 -O -release -link-defaultlib-shared app.d Both are smaller than the gcc-version. How is this possible? What are the consequences and trade-offs? Maybe this should have been posted in Learn instead, but idk. Thanks Oops, typo, I actually posted it in learn :D
Re: startsWith
On Sunday, 1 October 2023 at 05:33:36 UTC, Joel wrote: ```d void main() { import std.string : split; import std.algorithm.searching : startsWith; string bk="Exo"; assert(("Gen Exo Lev Num Deu Jos Judg Rut 1Sam 2Sam".split~ "1Kin 2Kin 1Chr 2Chr Ezra Neh Est Job Psa Pro Ecc Son Isa Jer".split~ "Lam Eze Dan Hos Joel Amos Oba Jon Mic Nah Hab Zep Hag Zec".split~ "Mal Mat Mar Luk Joh Act Rom 1Cor 2Cor Gal Eph Phili Col".split~ "1The 2The Titu Phile Heb Jam 1Pet 2Pet 1Joh 2Joh 3Joh Jude Rev".split) .startsWith(bk)); } ``` Why doesn't this work? canFind works though. Because it starts with Gen, not Exo.
Re: Straight Forward Arrays
On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: Hi, Is there a straight forward Array type in D similar to C++'s vector class? Something along the lines of the tuple: (pointer to elements, length, capacity). [...] https://dlang.org/spec/simd.html https://dlang.org/phobos/core_simd.html Or if you want to use it, you can check out core.stdcpp.vector.
Re: Straight Forward Arrays
On Sunday, 1 October 2023 at 13:24:27 UTC, dhs wrote: On Sunday, 1 October 2023 at 13:05:12 UTC, Steven Schveighoffer wrote: On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: Hi, Is there a straight forward Array type in D similar to C++'s vector class? Something along the lines of the tuple: (pointer to elements, length, capacity). [...] Std::vector uses value semantics. D does not have anything like that. It could be done someone just has to do it. -Steve Yes, and therein lies the problem: writing a dynamic array is not a very difficult task for an old developer like me. I looked at the D runtime and at the Phobos implementation for reference. The code is so extremely difficult to understand and uses so many advanced D features, that I doubt that I am up to the task. For me, the point of switching to D was to use a language that is simpler to read and maintain. D can be very readable and maintainable, but since all the advanced features exist, we are tempted to use them, which can cause otherwise normal code to become a bit obfuscated.
Re: Key and value with ranges
On Monday, 2 October 2023 at 02:47:37 UTC, Joel wrote: ```d import std; auto data=“I went for a walk, and fell down a hole.”; void main(string[] args) { int[string] dic; struct WordCnt { string word; ulong count; string toString() const { return text("Word: ", word, " - number of instances: ", count); } } WordCnt[] wc; data .map!(c => lowercase.canFind(std.uni.toLower(c)) ? c : ' ') .to!string .splitter .each!(d => dic[d]+=1); foreach(key, value; dic) wc~=WordCnt(key, value); wc.sort!"a.count>b.count".each!writeln; } ``` How can I improve this code? Like avoiding using foreach. You don't need a struct at all, you can just have an int[string] aa
Re: Key and value with ranges
On Monday, 2 October 2023 at 02:47:37 UTC, Joel wrote: ```d import std; auto data=“I went for a walk, and fell down a hole.”; You can improve it further by inlining ```d import std; auto data = "I went for a walk, and fell down a hole."; void main(string[] args) { int[string] dic; data.split(' ').each!(w => dic[w]++); sort(dic.keys).each!(w => writeln(dic[w], " ",w)); } ```
Re: Define a new custom operator in D Language.
On Monday, 2 October 2023 at 18:34:13 UTC, BoQsc wrote: Here is my issue: I've found a formula on Wikipedia. It's called **Hashing by division**. ![](https://i.imgur.com/UJPAWIW.png) As you can see it uses **mod** keyword to achieve the modulus operation. In D language we use modulus operator `%` and it might look more like this: ``` h(x) M % m ``` This clearly introduces confusion between the source (wikipedia) and the implementation (dlang version). I would like to know how we could define/alia ourselves a `mod` operator in D Language. ``` h(x) M mod m ``` --- **This might lead to less gaps between math formulas and the implementation.** Or at the very least would allow to define a formula in the source code for further implementation and introduce some consistency. https://dlang.org/spec/operatoroverloading.html#binary
Re: Define a new custom operator in D Language.
On Monday, 2 October 2023 at 19:28:32 UTC, BoQsc wrote: On Monday, 2 October 2023 at 18:39:41 UTC, Imperatorn wrote: On Monday, 2 October 2023 at 18:34:13 UTC, BoQsc wrote: [...] https://dlang.org/spec/operatoroverloading.html#binary Overloading seems to only overload behaviour of existing operator, like: ``` + - * / % ^^ & | ^ <<>>>>>~ in ``` I'm unable to see how the operator overloading would allow to define a new custom operator. I guess I don't understand your confusion. % is the modulus operator, you can overload it if you want to instead do what you want according to your needs.
Re: The difference between T[] opIndex() and T[] opSlice()
On Tuesday, 3 October 2023 at 17:52:20 UTC, Paul Backus wrote: On Tuesday, 3 October 2023 at 16:45:39 UTC, Steven Schveighoffer wrote: OK, so it's not as bad as I thought, but surely the compiler should recognize that `opIndexAssign(val, idx)` doesn't work, but `opIndex(idx) = val` does? Maybe. On the other hand, if you make a typo in the body of your templated `opIndexAssign` overload, do you want the compiler to silently fall back to `opIndex`, or do you want an error? There are pros and cons to both approaches. At the very least, the spec should do a better job of documenting when the compiler will try a fallback and when it won't. Who will be the hero and add the documentation? 😇
Re: array setting : Whats going in here?
On Saturday, 7 October 2023 at 00:00:48 UTC, claptrap wrote: char[] foo; foo.length = 4; foo[] = 'a'; // ok sets all elements foo[] = "a"; // range error at runtime? foo[] = "ab"; // range error at runtime? So I meant to init with a char literal but accidently used double quotes. Should that even compile? Shouldn't the compiler at least complain when trying to init with "ab"? Even though you now have gotten answers, I still agree with you that there should be some kind of "warning" or suggestion like, did you mean to assign incompatible types? It could just check the element type and see if it matches the rhs type.
Re: array setting : Whats going in here?
On Monday, 9 October 2023 at 02:19:20 UTC, Jonathan M Davis wrote: On Sunday, October 8, 2023 8:08:46 AM MDT Imperatorn via Digitalmars-d-learn wrote: [...] Except that in those examples, they _do_ match. It's perfectly valid to copy elements of a string to a char[]. It's just copying immutable(char) to char. The compiler would complain if it couldn't implicitly convert the element type in the array being assigned from to the element type in the array being assigned to. The problem here is simply that the lengths of the arrays don't match. [...] Thanks, I think I read the code a little too fast
Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?
On Monday, 9 October 2023 at 16:55:41 UTC, rempas wrote: On Monday, 9 October 2023 at 16:53:55 UTC, mw wrote: but you `import std.stdio;`? Or copy the std/conv.d over to your build, or copy / write a toString(int) function yourself, which is compile-time callable. I do on that example just to use "write". It wouldn't be necessary, but I just included it. My normal project does not use Phobos. You could just add your own int to string I guess?
Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?
On Monday, 9 October 2023 at 22:49:11 UTC, Salih Dincer wrote: On Monday, 9 October 2023 at 16:33:32 UTC, rempas wrote: I'm trying to create a series of function. There will be ten of them, and they will be called `function_0`, `function_1`, etc. However, in my example, "stringof" returns the character "i" itself and turns that into a string instead of getting its actual value (number). Any ideas how I can achieve what I'm trying to achieve? Great masters generally warn to stay away from stringof. Please do not use it as much as possible. The following code snippet will be useful to you: ```d alias CN = __traits(allMembers, CardinalNumbers); static foreach(i; CN) { mixin(create_fn!(i[1])); } enum create_fn(char num) = ` auto function_`~ num ~`() => "Hello from function `~ num ~`!"; `; enum CardinalNumbers { n0, n1, n2, n3, n4, n5, n6, n7, n8, n9 } void main() { assert(function_9() == "Hello from function 9!"); } ``` SDB@79 If count < 10 then why not just ```d import std; static foreach(c; "0123456789") { mixin(create_fn!(c)); } enum create_fn(char num) = ` auto function_`~ num ~`() => "Hello from function `~ num ~`!"; `; void main() { assert(function_9() == "Hello from function 9!"); } ```
Re: is the array literal in a loop stack or heap allocated?
On Wednesday, 11 October 2023 at 02:54:53 UTC, mw wrote: Hi, I want to confirm: in the following loop, is the array literal `a` vs. `b` stack or heap allocated? and how many times? void main() { int[2] a; int[] b; int i; While(++i <=100) { a = [i, i+1]; // array literal b = [i, i+1]; } } Thanks. profile=gc
Re: extern (c)
On Wednesday, 11 October 2023 at 13:36:16 UTC, Paul wrote: On Wednesday, 11 October 2023 at 12:54:53 UTC, user1234 wrote: `extern(C)` on module level functions affect the mangling and the calling convention. - Mangling is used by the linker to link symbols between objects. - Calling convention affects the compiler backend in how code is generated for a CALL instruction. So C doesn't use name mangling and extern (C) in a D prog would turn off D mangling thereby allowing C and D object files to be linked together? I didn't know C and D had different calling conventions...i.e. different ABI's? https://dlang.org/spec/abi.html
D http benchmarks
Just sharing https://github.com/tchaloupka/httpbench
Re: The Power of Grammar Checkers: A Game-Changer for Writers!
On Thursday, 12 October 2023 at 06:08:43 UTC, charles reiley wrote: I hope you're all doing well in your writing endeavors! Today, I wanted to share my thoughts and experiences with grammar checkers, and I can't emphasize enough how much of a game-changer they've been for me at [url=https://myassignmenthelp.com/grammar-checker.html]www.myassignmenthelp.com[/url] How does this relate to D in any way?
Re: Need csv writer (std.csv only has csvReader)
On Thursday, 12 October 2023 at 23:18:23 UTC, John Xu wrote: Any friend can help me with a csvWriter? The std.csv only has a csvReader. I want to dump database from sqlite to mysql. If I do it manually, I need handle double quote("), \n, ',' specifically Have you looked at https://code.dlang.org/packages/mir-ion ?
Re: Need csv writer (std.csv only has csvReader)
On Thursday, 12 October 2023 at 23:18:23 UTC, John Xu wrote: Any friend can help me with a csvWriter? The std.csv only has a csvReader. I want to dump database from sqlite to mysql. If I do it manually, I need handle double quote("), \n, ',' specifically Also, if tsv is acceptable, I tried this previously https://code.dlang.org/packages/tsv-utils And it can convert csv to tsv
Re: use dmd for bare metal i386
On Friday, 13 October 2023 at 22:14:36 UTC, Dmitry Ponyatov wrote: Is dmd able to be forced not include some unneeded information into target object files to make bare metal 32-bit code? Need some samples and build scripts to do it. Or maybe move to ldc2 required You need ldc or gdc
Benchmarks
https://github.com/jinyus/related_post_gen
Re: Search for the dialog library
On Saturday, 14 October 2023 at 23:02:34 UTC, Alexander Zhirov wrote: Colleagues, tell me, please, is there any library on D for drawing [dialog](https://invisible-island.net/dialog/images/dialog.png) boxes using the dialog library, like in Python [pythondialog](https://pypi.org/project/pythondialog/)? Since it's a c lib you could try either ctod, ImportC, DPP, dstep or ohmygentool. Or just link with it and use what you need. There's also that cpp2d converter in Visual D you could try, but I don't know how good it works.
Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?
On Saturday, 14 October 2023 at 06:48:40 UTC, rempas wrote: On Friday, 13 October 2023 at 10:11:33 UTC, Nick Treleaven wrote: You can also do it using a string mixin: mixin(create_fn!(mixin("`", i, "`"))); I think that's equivalent to `i.stringof` anyway. Thank you for the info! You already got a lot of good answers, I thought I'd just share this for anyone searching for nogc string formatting compatible with betterC: https://code.dlang.org/packages/bc-string
Re: Benchmarks
On Friday, 13 October 2023 at 22:45:19 UTC, Imperatorn wrote: https://github.com/jinyus/related_post_gen Sequential processing time, less is better |Language| Time (5k posts) | 20k posts | 60k posts | Total | |:--:|:---:|:--:|:-:|::| | D | 24.76 ms| 314.14 ms | 2.70 s | 3.04 s | | C++| 24.00 ms| 337.33 ms | 2.94 s| 3.30 s | | Rust | 23.51 ms | 341.02 ms | 3.04 s| 3.40 s | | Go | 24.22 ms| 371.65 ms | 3.28 s| 3.67 s | | Nim| 30.02 ms| 521.70 ms | 3.56 s| 4.11 s | | Zig| 28.62 ms| 430.33 ms | 3.81 s| 4.27 s | | F# (AOT) | 32.77 ms| 485.67 ms | 4.13 s| 4.65 s | | Julia | 30.15 ms| 481.00 ms | 4.24 s| 4.75 s | | Odin | 41.15 ms| 689.07 ms | 5.05 s| 5.78 s | | Java (GraalVM) | 41.00 ms| 495.33 ms | 5.28 s| 5.82 s | | C# (AOT) | 42.70 ms| 615.80 ms | 5.39 s| 6.05 s | | F# (JIT) | 45.15 ms| 623.67 ms | 5.49 s| 6.16 s | | Swift | 50.68 ms| 712.61 ms | 6.16 s| 6.93 s | | Java (JIT) | 54.77 ms| 757.00 ms | 6.44 s| 7.25 s | | Vlang | 51.35 ms| 756.63 ms | 6.66 s| 7.46 s | | C# (JIT) | 57.97 ms| 772.78 ms | 6.77 s| 7.60 s | | Crystal| 64.96 ms| 974.49 ms | 8.64 s| 9.68 s | | LuaJIT | 109.53 ms | 1.51 s | 12.93 s | 14.55 s | | Dart VM| 138.85 ms | 2.41 s | 20.96 s | 23.51 s | | JS (Node) | 182.00 ms | 2.44 s | 22.50 s | 25.12 s | | Dart AOT | 185.38 ms | 2.89 s | 25.75 s | 28.83 s | | ocaml | 140.00 ms | 2.76 s | 32.71 s | 35.61 s | | JS (Deno) | 192.31 ms | 2.26 s | 41.13 s | 43.58 s | | JS (Bun) | 763.15 ms | 11.82 s| 108.87 s | 121.45 s | | Lua| 1.09 s | 16.78 s| 150.00 s | 167.87 s | | Python | 1.47 s | 23.48 s| 214.99 s | 239.94 s | | Numpy | 349.48 ms | 6.67 s | OOM | N/A | Parallel processing time, less is better | Language | Time (5k posts) | 20k posts | 60k posts | Total | |:-:|:---:|:--:|:-:|:--:| | D Concurrent | 15.10 ms| 145.10 ms | 1.16 s | 1.32 s | | C++ Concurrent| 13.85 ms| 163.67 ms | 1.38 s| 1.56 s | | Go Concurrent | 13.13 ms | 166.03 ms | 1.42 s| 1.60 s | | Rust Concurrent | 14.39 ms| 186.87 ms | 1.58 s| 1.78 s | | Julia Concurrent | 16.85 ms| 222.67 ms | 1.94 s| 2.18 s | | F# Concurrent (JIT) | 22.31 ms| 288.33 ms | 2.46 s| 2.77 s | | F# Concurrent (AOT) | 19.00 ms| 290.00 ms | 2.47 s| 2.78 s | | Swift Concurrent | 31.32 ms| 393.54 ms | 3.50 s| 3.93 s | | Java (GraalVM) Concurrent | 38.77 ms| 592.33 ms | 4.12 s| 4.75 s |
Re: Search for the dialog library
On Sunday, 15 October 2023 at 23:01:05 UTC, Alexander Zhirov wrote: On Sunday, 15 October 2023 at 21:46:44 UTC, Dmitry Ponyatov wrote: Maybe it's time to port the old warm tubby Turbo Vision into the glorious D lang? https://github.com/magiblot/tvision Since there was a conversation about the implementation of the wrapper, it is easier to write a wrapper for the `dialog` library, in fact, which is probably what I will do. I'll share a link here a little later. If anyone wants to help, it will be very cool! I think this library can be useful to many people. Porting is also possible now pretty easy with the tools mentioned. Yesterday I ported a small project in C to D in 10 minutes using ctod + manual fixes. Anyway, whatever you choose, remember to put it on dub ❤️
Re: strange link error: _My_struct__xtoHashFNbNeKxSQBlQBoQBiZm _My_struct__xopEqualsMxFKxSQBlQBoQBiZb
On Monday, 16 October 2023 at 18:20:27 UTC, mw wrote: Hi, I just encountered a strange link error: I have a `struct` type `My_struct`, the program compiles fine, but at link time, it errors out: undefined reference to _My_struct__xtoHashFNbNeKxSQBlQBoQBiZm undefined reference to _My_struct__xopEqualsMxFKxSQBlQBoQBiZb looks like it treats My_struct type as `class` type? I'm just wondering how to fix this? both compilers report the same link error: DMD64 D Compiler v2.105.0 LDC - the LLVM D compiler (1.35.0): Thanks. Show your code here on in Discord https://discord.gg/wKTvGNpc
Re: strange link error: _My_struct__xtoHashFNbNeKxSQBlQBoQBiZm _My_struct__xopEqualsMxFKxSQBlQBoQBiZb
On Monday, 16 October 2023 at 20:06:02 UTC, ryuukk_ wrote: On Monday, 16 October 2023 at 19:36:07 UTC, Imperatorn wrote: On Monday, 16 October 2023 at 18:20:27 UTC, mw wrote: [...] Show your code here on in Discord https://discord.gg/wKTvGNpc No, show your code here on the forum, don't need to siphon out people to Discord With the forums the problem + solution will be saved for other people I made a typo, it should say "or", not "on"
Re: std.format with named args
On Tuesday, 17 October 2023 at 06:46:31 UTC, Vitaliy Fadeev wrote: Hi all! I want readable mixin. I want pass variable to string. I want string with named args. Like this: ```D enum JMP_ADDR_R = "RAX"; mixin( format!"asm { jmp [JMP_ADDR_R]; }"( JMP_ADDR_R ));// IT NOT WORK ``` Not this: ```D enum JMP_ADDR_R = "RAX"; mixin( format!"asm { jmp [%s]; }"( JMP_ADDR_R ));// WORK, BUT NOT-READABLE ``` In large code named identifiers more readable. In future it will used in jump table, like this: ```D mixin( format!"asm { lea JMP_ADDR_R, qword ptr [ JMP_I_R * PTR_SIZE + TBL_ADDR ]; jmp [JMP_ADDR_R]; }"( JMP_I_R, PTR_SIZE, TBL_ADDR, JMP_ADDR_R )); ``` Please, help me find a solution... or exists std.format with named args ? or another solution with named args ? Without string interpolation the best you can do is https://dlang.org/library/std/conv/text.html Or write some code yourself, unfortunately
Re: std.format with named args
On Tuesday, 17 October 2023 at 07:53:28 UTC, Vitaliy Fadeev wrote: On Tuesday, 17 October 2023 at 07:22:41 UTC, Vitaliy Fadeev wrote: [...] `scriptlike` looks perfecto! ```D enum JMP_ADDR_R = ... ... import scriptlike; writeln( mixin(interp!" asm { lea ${JMP_ADDR_R}, qword ptr [ ${JMP_I_R} * ${PTR_SIZE} + ${TBL_ADDR} ]; jmp [${JMP_ADDR_R}]; } ") ); ``` produced: ``` asm { lea RAX, qword ptr [ RDX * 8 + 5594AA134290 ]; jmp [RAX]; } ``` Closed! `scriptlike` Thanks, all! Nice
Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?
On Tuesday, 17 October 2023 at 13:31:39 UTC, Salih Dincer wrote: On Sunday, 15 October 2023 at 07:22:53 UTC, Imperatorn wrote: You already got a lot of good answers, I thought I'd just share this for anyone searching for nogc string formatting compatible with betterC: https://code.dlang.org/packages/bc-string Doesn't it make more sense to use [ParseResult!T parse(T)(cstring str)](https://github.com/tchaloupka/bc-string/blob/master/source/bc/string/conv.d) instead of nested if's here: https://github.com/tchaloupka/bc-string/blob/master/source/bc/string/numeric.d Thanks, SDB@79 Omg, yeah, that looks like some kind of hack. Make a PR :)
github copilot and dlang
https://forum.dlang.org/post/lqwhddcncwrhcdlnw...@forum.dlang.org On Monday, 5 July 2021 at 15:56:38 UTC, Antonio wrote: Has someone tried github copilot (https://copilot.github.com/) with dlang? Access to the preview could be requested and, I think, main dlang team members could bypass the waitlist easily. I suspect that the "low" volume of dlang code (used to train OpenAI) compared to other languages could impact in the support (if there is any). Anyway, it could be really interesting to see how Copilot faces templates, traits, ... Yes it works. Some guys in the Discord server tested it and is quite impressed with it.
Re: Can't get into debugger in vscode on macOS
On Thursday, 19 October 2023 at 06:03:06 UTC, Daniel Zuncke wrote: Hello, I need some help getting into the debugger in vscode on macOS. It did work some months ago but that was finicky to set up. Maybe I am forgetting something now? [...] This can also happen if there's not a correct program database file or it can't find it.
Re: Installing DMD on Windows
On Friday, 20 October 2023 at 12:19:32 UTC, Quirin Schroll wrote: I recently removed Visual Studio 2017 and upgraded to 2022. When I installed the latest DMD, it told me it couldn’t find a Visual Studio installation and offered me to download e.g. Visual Studio 2019 or just VS 2019 Build Tools, etc. Unsure what to do, I thought VS 2019 Build Tools is probably the most light-weight. I just removed VS 2019 Build Tools and DMD seems to work just fine. Probably I could have gotten away with installing nothing. Is there something I’m missing or did the installer just not detect VS 2022? It’s installed at `C:\Program Files\Microsoft Visual Studio\2022\Professional`, the default install location. I will try with VS 2022 Professional as well
Want to try out string interpolation in D?
Here's a script to get you started ```bash git clone https://github.com/adamdruppe/dmd.git cd dmd git checkout interp rdmd compiler/src/build.d ``` I don't want to copy files anywhere, so the user has to do that manually: Copy dmd from the generated executable to your D bin installation folder Example: ``` copy generated\windows\release\64\dmd.exe C:\d\dmd2\windows\bin64 ``` Copy druntime/src/core/interpolation.d to your corresponding druntime folder + import Example: ``` copy druntime/src/core/interpolation.d C:\d\dmd2\src\druntime\import\core\ ``` Now try string interpolation: ```d import std.stdio; void main() { string name = "Johan"; int age = 37; int iq = 8001; int coffees = 1000; writeln(i"Your name is $name and you're $age years old"); writeln(i"You drink $coffees cups a day and it gives you $(coffees + iq) IQ"); } ``` Output: ``` Your name is Johan and you're 37 years old You drink 1000 cups a day and it gives you 9001 IQ ```
Re: Want to try out string interpolation in D?
On Friday, 20 October 2023 at 16:41:40 UTC, Imperatorn wrote: Here's a script to get you started ```bash git clone https://github.com/adamdruppe/dmd.git cd dmd git checkout interp rdmd compiler/src/build.d ``` [...] We just need support for it in the tools, then D will be a Dream come true
Re: Want to try out string interpolation in D?
On Friday, 20 October 2023 at 16:41:40 UTC, Imperatorn wrote: Here's a script to get you started Same instructions for DIP1027: ``` git clone https://github.com/WalterBright/dmd.git cd dmd git checkout dip1027 rdmd compiler/src/build.d ``` Then same instructions as above but without the need to copy interpolation.d
Profiling using Visual Studio
I would just like to share some knowledge about profiling an exe using Visual Studio, since many might already have that installed. After you have built your executable with symbols, open VS and choose "Continue without code". Then just choose open Project/Solution (Ctrl+Shift+O) and go to "Debug -> Performance Profiler" (Alt+F2). You will be presented with a windows looking something like this ![Analysis](https://i.ibb.co/L96C9yk/analysis.png) Press start and wait for the profiling to complete. You should now have a diagsession available to inspect. The default view is the call tree: ![Call tree](https://i.ibb.co/52V2X46/analysis3.png) You can also view by module, caller/callee, functions and flame graph. This is an example of flame graph: ![Flame graph](https://i.ibb.co/D1zZb5V/analysis4.png) And here's an example showing that you can go into phobos as well: ![Phobos](https://i.ibb.co/3rzKyqh/analysis4.png) Just sharing this here if someone with VS wants an easy way to profile with existing tools.
Re: Profiling using Visual Studio
On Sunday, 22 October 2023 at 13:13:55 UTC, Imperatorn wrote: I would just like to share some knowledge about profiling an exe using Visual Studio, since many might already have that installed. [...] On Sunday, 22 October 2023 at 13:13:55 UTC, Imperatorn wrote: Just a clarification. "open Project/Solution (Ctrl+Shift+O)" means, you open the executable in that file dialog :)
Re: Profiling using Visual Studio
On Sunday, 22 October 2023 at 13:16:11 UTC, Imperatorn wrote: On Sunday, 22 October 2023 at 13:13:55 UTC, Imperatorn wrote: I would just like to share some knowledge about profiling an exe using Visual Studio, since many might already have that installed. [...] On Sunday, 22 October 2023 at 13:13:55 UTC, Imperatorn wrote: Just a clarification. "open Project/Solution (Ctrl+Shift+O)" means, you open the executable in that file dialog :) You can also use Intel® VTune which integrates with Visual Studio as well, however, it naturally requires you to download and install it. When installed, you can navigate to here after doing the process as described for VS. ![Navigation](https://i.ibb.co/DpXWH4P/vTune.png) If you do, you can get something similar to this: ![Intel vTune](https://i.ibb.co/Fgh9pZx/vTune.png) This can be used to see if you can for example rewrite some code to complexity. For example form O(N^2) to O(T * N) or perhaps O(N log N). It can be a really useful tool
Re: Want to try out string interpolation in D?
On Monday, 23 October 2023 at 11:12:20 UTC, matheus wrote: On Friday, 20 October 2023 at 16:41:40 UTC, Imperatorn wrote: Here's a script to get you started ... Now try string interpolation: ```d import std.stdio; void main() { string name = "Johan"; int age = 37; int iq = 8001; int coffees = 1000; writeln(i"Your name is $name and you're $age years old"); writeln(i"You drink $coffees cups a day and it gives you $(coffees + iq) IQ"); } ``` Output: ``` Your name is Johan and you're 37 years old You drink 1000 cups a day and it gives you 9001 IQ ``` First of all thanks for writing this. Well this seems pretty nice... What DIP number is this? - I'd like to read why it was rejected. Matheus. Which one did you try? The first one is YAIDIP: https://github.com/John-Colvin/YAIDIP and the second one is DIP1027: https://github.com/dlang/DIPs/blob/master/DIPs/rejected/DIP1027.md Make sure you try them both
Re: DlangUI: how to change AppFrames?
On Tuesday, 24 October 2023 at 04:38:58 UTC, Ki Rill wrote: I know how to change the current AppFrame: ```D window.mainWidget = myFrame; ``` But how do I exit this frame? I press the button, change to new frame, do the work, and now I want to return to the previous frame. How would I do this? Saving the previous frame not an option?
Re: Want to try out string interpolation in D?
On Monday, 23 October 2023 at 11:43:33 UTC, Imperatorn wrote: On Monday, 23 October 2023 at 11:12:20 UTC, matheus wrote: On Friday, 20 October 2023 at 16:41:40 UTC, Imperatorn wrote: [...] First of all thanks for writing this. Well this seems pretty nice... What DIP number is this? - I'd like to read why it was rejected. Matheus. Which one did you try? The first one is YAIDIP: https://github.com/John-Colvin/YAIDIP and the second one is DIP1027: https://github.com/dlang/DIPs/blob/master/DIPs/rejected/DIP1027.md Make sure you try them both Note: The YAIDIP is now superseed by the 1036e.
Re: Unable to use template functions to define variables of a class
On Saturday, 28 October 2023 at 12:38:42 UTC, Subhaditya Nath wrote: This works fine – I think it's because you're using a class. Try for example: ```d import std.range; import std.stdio; import std.algorithm.iteration; void main() { auto cls = new Class; cls.range1.each!writeln; } class Class { auto range1() { return iota(0, 100).filter!(x => x % 2).take(25); } } ``` The lambda function x => x % 2 is created within the class scope, which means it implicitly captures this. The filter function is a template that gets instantiated in a way that requires access to this, which is not available in the static context. The range1 member is declared like a field within the Class, but it's initialized in place, outside of a constructor or method. This sort of initialization doesn't have access to this because it's not happening within an instance context (like within a method where this is valid). So, then maybe you understand why it didn't work.
Re: bigEndian in std.bitmanip
On Tuesday, 31 October 2023 at 10:09:53 UTC, Salih Dincer wrote: Hello, Why isn't Endian.littleEndian the default setting for read() in std.bitmanip? Okay, we can easily change this if we want (I could use enum LE in the example) and I can also be reversed with data.retro.array(). ```d void main() { import std.conv : hexString; string helloD = hexString!"48656C6C6F204421"; // compile time converted literal string -ˆ import std.string : format; auto hexF = helloD.format!"%(%02X%)"; import std.digest: toHexString; auto arr = cast(ubyte[])"Hello D!"; auto hex = arr.toHexString; assert(hex == hexF); import std.stdio : writeln; hex.writeln(": ", helloD); // 48656C6C6F204421: Hello D! assert(helloD == "Hello D!"); auto data = arr.readBytes!size_t; data.code.writeln(": ", data.bytes); // 2397076564600448328: Hello D! } template readBytes(T, R) { union Bytes { T code; char[T.sizeof] bytes; } import std.bitmanip; enum LE = Endian.littleEndian; auto readBytes(ref R data) { import std.range : retro, array; auto reverse = data.retro.array; return Bytes(reverse.read!T); } } ``` However, I think it is not compatible with Union. Thanks... SDB@79 It might make sense to change since little endian is the most common when it comes to hardware. But big endian is most common when it comes to networking. So I guess it depends on your view of what is most common. Interacting with your local hardware or networking.
Re: win32 api & lib issue
On Thursday, 2 November 2023 at 08:31:41 UTC, Peter Hu wrote: Greetings! From time to time I encountered issues on the subjected after I upgraded my dmd package.Given below code : import core.sys.windows.windows; import core.sys.windows.commdlg; import core.sys.windows.winuser; extern(Windows) BOOL GetOpenFileNameW(LPOPENFILENAMEW); extern(Windows) int MessageBoxW(HWND,LPCWSTR,LPCWSTR,UINT); void main() { wchar[256] fileName; fileName[0]=0; OPENFILENAMEW ofn; ofn.lStructSize=OPENFILENAMEW.sizeof; ofn.lpstrFilter= "Text Files\0*.txt\0 D files\0*.d;*.di\0\0"w.ptr; ofn.lpstrFile=fileName.ptr; ofn.nMaxFile=fileName.length; if(GetOpenFileNameW(&ofn)) { MessageBoxW(null,ofn.lpstrFile,"File Selected:"w.ptr,0); } } The compiler failed to build this small program.It complains GetOpenFileNameW & MessageBoxW are unresolved external symbol. DMD 2.103+VS Community 2015+Win10 64bit. estwinapi.obj : error LNK2019: 无法解析的外部符号 _GetOpenFileNameW@4,该符号在函数 __Dmain 中被引用 testwinapi.obj : error LNK2019: 无法解析的外部符号 _MessageBoxW@16,该符号在函数 __Dmain 中被引用 testwinapi.exe : fatal error LNK1120: 2 个无法解析的外部命令 Error: linker exited with status 1120 Appreciated any help on figuring me out what the issue is and how to fix it. Works for me. But you don't need to declare the functions, they are already declared in commdlg and winuser. ```d import core.sys.windows.windows; import core.sys.windows.commdlg; import core.sys.windows.winuser; void main() { wchar[256] fileName; fileName[0]=0; OPENFILENAMEW ofn; ofn.lStructSize=OPENFILENAMEW.sizeof; ofn.lpstrFilter= "Text Files\0*.txt\0 D files\0*.d;*.di\0\0"w.ptr; ofn.lpstrFile=fileName.ptr; ofn.nMaxFile=fileName.length; if(GetOpenFileNameW(&ofn)) { MessageBoxW(null,ofn.lpstrFile,"File Selected:"w.ptr,0); } } ```
Re: win32 api & lib issue
On Thursday, 2 November 2023 at 09:01:06 UTC, Imperatorn wrote: On Thursday, 2 November 2023 at 08:31:41 UTC, Peter Hu wrote: [...] Works for me. This is all you need ```d import core.sys.windows.commdlg; import core.sys.windows.winuser; void main() { wchar[256] fileName; OPENFILENAMEW ofn; ofn.lStructSize = OPENFILENAMEW.sizeof; ofn.lpstrFilter = "Text Files\0*.txt\0 D files\0*.d;*.di\0\0"w.ptr; ofn.lpstrFile = fileName.ptr; ofn.nMaxFile = fileName.length; if (GetOpenFileNameW(&ofn)) { MessageBoxW(null, ofn.lpstrFile, "File Selected:"w.ptr, 0); } } ```
Re: win32 api & lib issue
On Thursday, 2 November 2023 at 08:31:41 UTC, Peter Hu wrote: Greetings! From time to time I encountered issues on the subjected after I upgraded my dmd package.Given below code : [...] If it still doesn't work try adding this: ```d pragma(lib, "user32"); pragma(lib, "comdlg32"); ```
Re: win32 api & lib issue
On Thursday, 2 November 2023 at 09:08:02 UTC, Imperatorn wrote: On Thursday, 2 November 2023 at 08:31:41 UTC, Peter Hu wrote: Greetings! From time to time I encountered issues on the subjected after I upgraded my dmd package.Given below code : [...] If it still doesn't work try adding this: ```d pragma(lib, "user32"); pragma(lib, "comdlg32"); ``` Another alternative if you're using dub is to add this in your dub.json instead: ```json "libs": ["user32", "comdlg32"] ``` This seems be something related to DMD vs LDC. Because if I change the compiler to DMD I also get unresolved external symbols, but not with LDC. It seems the forwarding of directives from submodules are different.