Re: Dub generated a visuald project for me that includes pegged + dqt (Qt widgets). Basic linking error fix?
I see now. https://github.com/tim-dlang/dqt has examples of where these libs are found within Qt itself.
Dub generated a visuald project for me that includes pegged + dqt (Qt widgets). Basic linking error fix?
``` Build started at 7:16 PM... -- Build started: Project: d--, Configuration: debug x64 -- Building C:\Users\fruit\OneDrive\Desktop\Code\StateMachine\D--\d--.exe... LINK : fatal error LNK1181: cannot open input file 'Qt5Widgets.lib' Building C:\Users\fruit\OneDrive\Desktop\Code\StateMachine\D--\d--.exe failed (error code 1181)! Details saved as "file://C:\Users\fruit\OneDrive\Desktop\Code\StateMachine\D--\.dub\obj\debug\dummy\d--\d--.buildlog.html" == Build: 0 succeeded, 1 failed, 4 up-to-date, 0 skipped == == Build completed at 7:16 PM and took 00.841 seconds == ``` Just wondering where / what in settings to change and what folder to point it to. Thanks! I'm making a public project on GitHub called D--. https://github.com/enjoysmath/D-- It's not a language extension, but will include new tools for visualizing your code and even refactoring it. D is like a host language for it, and also the code it will generate naturally. It's most likely only going to support a subset of D, though I will strive for the full grammar. Hence D-- sounds about right! The name is a play on the C++ is to C analogy.
Re: Challenge: Make a data type for holding one of 8 directions allowing increment and overflow
On Tuesday, 12 March 2024 at 05:38:03 UTC, Liam McGillivray wrote: I am in need of a data type for holding direction information; one of 8 directions on a single axis. They are named in terms of compass directions. If D had a 4-bit datatype, I would just use this and do `+=2` whenever I want to change the datatype, but it doesn't. Perhaps this would be a good programming challenge for someone more experienced than me. Make a data type (probably a struct) for holding one of 8 directional values using 3 bits. It should accept the use of increment operators to change the angle. Ideally (but optionally), it should work as an enum of the same name; "Direction". Here's a unittest that it should ideally pass: D actually supports both 3 and 4 bit integers. People will likely warn you of minor portability risks... but if you target a limited amount of platforms and prefer concise readable code, then it's a text book example for bitfields. The risk can easily be mitigated by having an unittest to catch the error directly(if you try to port to some exotic platform). dmd -preview=bitfields (Some lines stolen from Rikki) ```d struct Direction { private uint value : 3; alias this = value; enum Direction N = Direction(0); enum Direction NE = Direction(1); enum Direction E = Direction(2); enum Direction SE = Direction(3); enum Direction S = Direction(4); enum Direction SW = Direction(5); enum Direction W = Direction(6); enum Direction NW = Direction(7); } ```
Re: Help optimize D solution to phone encoding problem: extremely slow performace.
Dne so 20. 1. 2024 21:21 uživatel Renato via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> napsal: > On Saturday, 20 January 2024 at 19:45:19 UTC, Daniel Kozak wrote: > > On Sat, Jan 20, 2024 at 2:11 PM Renato via Digitalmars-d-learn > > < digitalmars-d-learn@puremagic.com> wrote: > > > >> Wow, fantastic feedback from lots of people, thanks so much! > >> ... > >> > >> > evilrat: > >> > There is another important difference, i quickly looked up D > >> > associative array implementation and the search looks like > >> > nlog(n) complexity with plain loop iteration of hashes, > >> > whereas > >> > rust's implementation is using "swisstable" algorithm > >> > implementation that has packed SIMD optimized lookups, this > >> > is > >> > likely where the 3x speed difference comes from. > >> > >> I am not using the default hash implementation in Rust (which > >> is hashbrown as you've found out). That's too slow (because > >> it's ddos secure - still Java's hash also is and it's still > >> faster). I had to replace that with a library called `ahash`. > >> > >> If you're interested in knowing more about that, please [read > >> my blog > >> post](https://renato.athaydes.com/posts/how-to-write-fast-rust-code) > about optimising the Rust code. > >> > >> So, no, that's not where the difference is coming from... in > >> fact, I am using a faster hashing function in D. > >> > >> You can [see my custom hashing function > >> here]( > >> > https://github.com/renatoathaydes/prechelt-phone-number-encoding/commit/d1fa1b77ad928f7d536728fba11f2d69b4afe7e3 > ). > >> This function is not good for the general purpose case, but > >> it's probably > >> as good as it gets for this problem (see my int128 trick in a > >> previous post > >> on this thread to understand why). I did try a few variations > >> of hashing > >> before settling on this one... Rust, if anything, is at a > >> disadvantage here. > >> > > > > And here you are wrong, it is the hashing when the slowdown > > comes. It is not only about the speed of hashing function. It > > is about the quality of hashing functiuon for this particular > > problem and it is about how hashing table (associative array) > > is implemented. > > I've explained why this function is almost a perfect hash > function for this problem (there will be almost no collisions > except for very large inputs where the shift-left will > "overflow", and even then the probability of collisions should be > very low). If you're going to claim I'm wrong, you must show > exactly where I'm wrong, and preferrably you should provide a > faster implementation. I will even accept a theoretical > explanation if you can give one. What I will not accept, is for > you to call me "wrong" just because you say so. That's childish > behaviour and uncalled for on a technical discussion. > If you provided info that hash is perfect, than I am sorry. I have probably missed that in this thread my fault. Than I will need to looked into this more carefully and do much more than just assumption. >
Re: Help optimize D solution to phone encoding problem: extremely slow performace.
On Sat, Jan 20, 2024 at 2:11 PM Renato via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Wow, fantastic feedback from lots of people, thanks so much! > ... > > > evilrat: > > There is another important difference, i quickly looked up D > > associative array implementation and the search looks like > > nlog(n) complexity with plain loop iteration of hashes, whereas > > rust's implementation is using "swisstable" algorithm > > implementation that has packed SIMD optimized lookups, this is > > likely where the 3x speed difference comes from. > > I am not using the default hash implementation in Rust (which is > hashbrown as you've found out). That's too slow (because it's > ddos secure - still Java's hash also is and it's still faster). I > had to replace that with a library called `ahash`. > > If you're interested in knowing more about that, please [read my > blog > post](https://renato.athaydes.com/posts/how-to-write-fast-rust-code) > about optimising the Rust code. > > So, no, that's not where the difference is coming from... in > fact, I am using a faster hashing function in D. > > You can [see my custom hashing function > here]( > https://github.com/renatoathaydes/prechelt-phone-number-encoding/commit/d1fa1b77ad928f7d536728fba11f2d69b4afe7e3). > This function is not good for the general purpose case, but it's probably > as good as it gets for this problem (see my int128 trick in a previous post > on this thread to understand why). I did try a few variations of hashing > before settling on this one... Rust, if anything, is at a disadvantage here. > And here you are wrong, it is the hashing when the slowdown comes. It is not only about the speed of hashing function. It is about the quality of hashing functiuon for this particular problem and it is about how hashing table (associative array) is implemented.
Re: Help optimize D solution to phone encoding problem: extremely slow performace.
On Fri, Jan 19, 2024 at 4:44 PM H. S. Teoh via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Taking a look at this code: > ... > Try addressing the points I wrote above and see if it makes a > difference. > > I have tried it (all of it) even before you wrote it here, because I have completely the same ideas, but to be fair it has almost zero effect on speed. There is my version (It still use OOP, but I have try it wit Printer and Counter to be structs and it has no effect at all) https://paste.ofcode.org/38vKWLS8DHRazpv6MTidRJY The only difference in speed in the end is caused by hash implementation of dlang associative arrays and rust HashMap, actually if you modify rust to not used ahash it has almost same speed as D
Dlang installer with VSCode broken
Q.jb (vscode-file://vscode-app/c:/Users/deepa/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2702:18090) 2023-11-05 22:23:10.119 [error] No remote extension installed to resolve dev-container.: CodeExpectedError: No remote extension installed to resolve dev-container. at Q.rb (vscode-file://vscode-app/c:/Users/deepa/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2702:21248) at async Q.qb (vscode-file://vscode-app/c:/Users/deepa/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2702:20507) at async Q.Ob (vscode-file://vscode-app/c:/Users/deepa/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2703:11479) at async Q.jb (vscode-file://vscode-app/c:/Users/deepa/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2702:18090) 2023-11-05 22:23:12.098 [error] No remote extension installed to resolve dev-container.: CodeExpectedError: No remote extension installed to resolve dev-container. at Q.rb (vscode-file://vscode-app/c:/Users/deepa/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2702:21248) at async Q.qb (vscode-file://vscode-app/c:/Users/deepa/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2702:20507) at async Q.Ob (vscode-file://vscode-app/c:/Users/deepa/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2703:11479) at async Q.jb (vscode-file://vscode-app/c:/Users/deepa/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2702:18090) 2023-11-05 22:25:53.031 [error] No remote extension installed to resolve dev-container.: CodeExpectedError: No remote extension installed to resolve dev-container. at Q.rb (vscode-file://vscode-app/c:/Users/deepa/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2702:21248) at async Q.qb (vscode-file://vscode-app/c:/Users/deepa/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2702:20507) at async Q.Ob (vscode-file://vscode-app/c:/Users/deepa/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2703:11479) at async Q.jb (vscode-file://vscode- app/c:/Users/deepa/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2702:18090) This is on my friend's machine, who I am teaching D. What can be done? Thanks, Daniel Donnelly
Re: Can't get into debugger in vscode on macOS
On Thursday, 19 October 2023 at 15:25:36 UTC, ryuukk_ wrote: ``` "stopOnEntry": true, ``` Thanks, my bad I missed that. The entry point I get is a dynamic link error and the program exits after trying to do a single step (I've put the asm below). Since calling `./bin/dfmt` works in the terminal and from lldb in the terminal I don't see how any linker error makes sense or why calling it from code lldb should be different. The only maybe related thing I can think of is that dmd produces linker error too (below). I have both ldc2 and dmd installed but dmd doesn't work for me (dmd neither functions if installed with brew or the install.sh). I had problems with the debugger already when dmd wasn't installed but RemedyBG debugger has problems with debugging llvm executables and dmd works so I wanted to try both here. I have found that the cpp debugger works to step around which might be enough for now so I am not wasting more time here if I don't have to. Thanks for the suggestions though. If you want me to try something I can do that. `stopOnEntry` brings me here: ```asm ; Symbol: _dyld_start ; Source: unknown 1006BD040: 48 89 E7movq %rsp, %rdi 1006BD043: 48 83 E4 F0 andq $-0x10, %rsp 1006BD047: 48 C7 C5 00 00 00 00movq $0x0, %rbp 1006BD04E: 6A 00 pushq $0x0 1006BD050: E9 BB 0B 00 00 jmp0x1006bdc10 ; start ``` dmd linker error running `dub build --build debug --compiler dmd`; dub.json has `"lflags": ["-ld_classic", "-v"]` specified so I don't know why clang suggests to specify `-v`. ``` @(#)PROGRAM:ld PROJECT:dyld-1015.7 BUILD 18:48:43 Aug 22 2023 configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em will use ld-classic for: armv6 armv7 armv7s arm64_32 i386 armv6m armv7k armv7m armv7em LTO support using: LLVM version 15.0.0 (static support for 29, runtime is 29) TAPI support using: Apple TAPI version 15.0.0 (tapi-1500.0.12.3) Library search paths: /usr/local/opt/dmd/lib /usr/local/lib Framework search paths: ld: multiple errors: symbol count from symbol table and dynamic symbol table differ in '/Users/dz/.dub/cache/dfmt/~master/build/application-debug-tVygsEVCB8Pzk4_L3pjNiA/dfmt.o' in '/Users/dz/.dub/cache/dfmt/~master/build/application-debug-tVygsEVCB8Pzk4_L3pjNiA/dfmt.o'; address=0x0 points to section(2) with no content in '/usr/local/opt/dmd/lib/libphobos2.a[3177](config_a68_4c3.o)' clang: error: linker command failed with exit code 1 (use -v to see invocation) Error: linker exited with status 1 Error dmd failed with exit code 1. ```
Re: Can't get into debugger in vscode on macOS
On Thursday, 19 October 2023 at 14:30:06 UTC, evilrat wrote: Could it be is that it instantly crashes? Thanks, but I have found it doesn't get that far* while debugging in vscode, it seems to be a linker error. \* If I randomly change program arguments (`--help`, `./tests/issue0578.d` or none) and recompile (same `dub build --build debug --compiler ldc2 --force`) it works maybe once in 20 tries and I get into vs-code debugger, from then on it the program executes without error. Changing nothing and hitting debug after that gives an error again.
Can't get into debugger in vscode on macOS
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? I am compiling the project with `dub build --build debug --compiler ldc2 --force` (the `-ld_classic` flag to fix the new Xcode linker is set in dub.json). Debugging in the terminal with lldb works as expected `lldb bin/dfmt -- --help`. In vscode I the debug process immediately exits with error (as far as I can tell, don't know how to get more output). All required extensions should be installed since it worked some time ago (mainly CodeLLDB, code-d and C++ from what I remember). I have tried 2 launch configs (launch.json): ```json { "version": "0.2.0", "configurations": [ { "type": "lldb", "request": "launch", "name": "debug lldb", "cwd": "${workspaceFolder}", "program": "./bin/dfmt", "args": ["--help"], }, { "type": "code-d", "request": "launch", "name": "debug code-d", "cwd": "${workspaceFolder}", "program": "./bin/dfmt", "args": ["--help"], }, ] } ``` And both fail the same way (vscode Debug Console output): ``` Launching: /Users/dz/dev/dfmt/issue578/bin/dfmt --help Launched process 24999 Process exited with code -1. ``` Any ideas what the problem could be? Can I get more verbose output what the problem is after launching the process?
How do we display Unicode in Visual D console output?
Right now, fresh install of VS and Visual D, all up-to-date. Can't display ∈, so how can we fix this? There is no project setting for Unicode chars. Thanks! EnjoysMath
How do you print all Unicode characters in a range - I want the subscripts, can't google a range of Unicode.
``` dstring s = ""; for (dchar i='ₐ'; i < 'ₜ'; i++) s ~= i; writeln(s); ``` Doesn't work. The result I get is shit: ΓéÉΓéæΓéÆΓéôΓéöΓéòΓéûΓéùΓéÿΓéÖΓéÜΓé¢
Re: How do you return a subclass instance from a base class method?
On Thursday, 17 November 2022 at 05:34:49 UTC, zjh wrote: On Thursday, 17 November 2022 at 04:25:13 UTC, Daniel Donnelly, Jr. wrote: ... `crtp`, will it work? Can't use CRTP, because once you choose a derived class to pass into the template system, how do you pass in subclasses of that class and so on...
Re: How do you return a subclass instance from a base class method?
On Thursday, 17 November 2022 at 05:21:05 UTC, MorteFeuille123 wrote: On Thursday, 17 November 2022 at 04:25:13 UTC, Daniel Donnelly, Jr. wrote: [...] You can use TypeInfoClass: [...] I don't get it - you never made use of b1 or b2...
Re: How do you return a subclass instance from a base class method?
``` PosetRelation transitivity(PosetRelation R, PosetRelation S) { // These if conditions are typically ordered from easiest to // most involved-to-check. if (R.op == S.op && is(typeof(R) == typeof(S)) && R.right == S.left) { return new typeof(R)( R.left, S.right, by("transitivity of " ~ R.op)); // Proof by this axiom } return null; } ``` Not sure if that would work yet. Have to test it.
How do you return a subclass instance from a base class method?
I have SubclassOf derived from PosetRelation. For any poset relation, the transitivity law applies, however, I'd like to return the correct type: ``` PosetRelation transitivity(PosetRelation R, PosetRelation S) { if (R.op == S.op) { if (R.right is S.left) return new SubclassOf(R.left, S.right); } return null; } ``` How does one accomplish this in D? Because PosetRelation doesn't know about SubclassOf, in general.
Re: is dmd a virus?
On Saturday, 22 October 2022 at 13:29:00 UTC, Salih Dincer wrote: On Saturday, 22 October 2022 at 09:49:28 UTC, Salih Dincer wrote: 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 It's our sweet virus... It must have happened to every last man of us the binary code you have implemented correctly is blocked by the antivirus. SDB79 Create a viral installer for D, that attacks C++ build tool binaries. It could also inject itself into source code of developers machines, which is probably more easily done than injecting into a binary because of OS security restrictions.
Re: Real simple question... for good programmers
On Saturday, 22 October 2022 at 22:01:09 UTC, Enjoys Math wrote: On Saturday, 22 October 2022 at 21:53:05 UTC, WhatMeWorry wrote: string[] tokens = userSID.output.split!isWhite; writeln("tokens = ", tokens); tokens = ["SID", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "S-1-5-21-3823976785-3597194045-4221507747-1779", "", "", "", "", "", "", "", ""] Is there a clever way that I can discard all the extra null strings in the resultant string array? I've been playing with isControl, whitespace, etc. Ready to rip my hair out. Why not `strip`? Works on ranges: https://dlang.org/phobos/std_algorithm_mutation.html#.strip Strip won't work because it only works on the beginning and ends of the range. What you want is `remove`. See my other MWE post.
Re: Can you access the same classes from C++ and D and vise versa, or do the classes have to not form dependency cycle?
On Sunday, 11 September 2022 at 02:14:51 UTC, zjh wrote: On Saturday, 10 September 2022 at 22:07:32 UTC, Ali Çehreli wrote: On 9/10/22 13:04, Daniel Donnell wrote: > https://dlang.org/spec/cpp_interface.html At DConf, Manu indicated that that page is outdated and that D's C++ support is actually a lot better. Update it quickly, This is a big selling point. So what is the answer here? I'm not sure what they were getting at...
How could I fix (debug) the VisualD plugin so that it actually works with the folders / files seen in Windows 10 file man.?
As you may already know if you want to move a file or rename a folder in VisualD, you can't simply do it. I've even had to edit the project file with Notepad++ in order to repair it. So, I'm humbly asking how can we fix this? I'm considering doing something in C++ which I'd rather not because I'm reluctant about all the memory leaks I'm going to make. Right now my project folder lay in disarray and I don't feel like going through fixing the folders for the 20th time. So has anyone got a workaround for these issues (it has many). I apologize for not recalling exactly the problem, but if you use VisualD you will be made aware of them if you don't want to keep all your files in single folder.
Can you access the same classes from C++ and D and vise versa, or do the classes have to not form dependency cycle?
https://dlang.org/spec/cpp_interface.html According to that C++ / D .object files can interoperate both ways, but one has to be compiled before the other, order depending on direction. My question is, can you have a class C (C++) use a class D (Dlang) in such a way that D can also use C as in the article? I'm guessing using all pointers on the C++ side might work. I have never gotten rid of cyclical dependencies in C++ other than putting a bunch of classes in the same file, but in D, cyclic dependency is resolved beautifully somehow, so I can split up my classes into each their own d-module.
Re: gdc or ldc for faster programs?
On Tuesday, 25 January 2022 at 20:04:04 UTC, Adam D Ruppe wrote: On Tuesday, 25 January 2022 at 19:52:17 UTC, Ali Çehreli wrote: ldc: ~0.95 seconds gdc: ~0.79 seconds dmd: ~1.77 seconds Maybe you can try --ffast-math on ldc.
Re: vibe.d community/forum/whatever ?
On Mon, Aug 30, 2021 at 8:20 AM bauss via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Monday, 30 August 2021 at 02:39:06 UTC, someone wrote: > > https://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/ > > > > I've been reading vibe.d tour and some documentation today to > > get some first impressions. https://vibed.org/community pointed > > to the link above ... but it seems it is full of crap. > > Just use these forums as pretty much the same people are here > that are in the vibe.d community. > Maybe add a new group to the forum for vibed and redirect https://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed there
Re: Performance issue with fiber
On Wed, Jul 28, 2021 at 11:41 PM hanabi1224 via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Wednesday, 28 July 2021 at 16:26:49 UTC, drug wrote: > > I profiled the provided example (not `FiberScheduler`) using > > perf. Both dmd and ldc2 gave the same result - `void > > filterInner(int, int)` took ~90% of the run time. The time was > > divided between: > > `int std.concurrency.receiveOnly!(int).receiveOnly()` - 58% > > `void std.concurrency.send!(int).send(std.concurrency.Tid, > > int)` - 31% > > > > So most of the time is messages passing. > > > > Between the fibers creating took very few time. Perf output > > contains information only of `void > > std.concurrency.FiberScheduler.create(void delegate()).wrap()` > > which took less than 0.5%. But I wouldn't say that I did the > > profiling ideally so take it with a grain of salt. > > Very interesting findings! After making the Fiber fix, I also > made profiling with valgrind, the result shows MessageBox related > staff contributes to ~13.7% of total cycles, swapContex related > staff add up to a larger percentage (My rough estimation is > >50%), I'd like to share the result svg but did not figure out > how to upload here. > I have rewrite it to be same as dart version import std; void main(string[] args) { auto n = args.length > 1 ? args[1].to!int() : 5; auto r = new Generator!int( { for(auto i = 2;;i++) yield(i); }); for(auto i=0;i
Re: Test thread
D could be the greatest thing on the planet. Like Python, D will take over the world of coding.
Re: Test thread
On Thursday, 20 May 2021 at 22:54:18 UTC, Daniel Donnelly, Jr wrote: Hi, I'm just testing whether I can post here. Thank you. Okay it worked. I am installing Visual D now. I am going to write a program that tries to guess a mathematical model of data using < 10 operators. I won't include elementary functions, but will include % function composition and indexing into the previous data. I'm just telling you that because I can't delete this test post, and I don't want my account banned for spam.
Test thread
Hi, I'm just testing whether I can post here. Thank you.
Re: How can I allocate a int[] array on stack?
On Fri, Mar 26, 2021 at 7:31 AM Daniel Kozak wrote: > On Fri, Mar 26, 2021 at 6:50 AM Jack via Digitalmars-d-learn < > digitalmars-d-learn@puremagic.com> wrote: > >> What's the equivalent of C's VLA in D? scoped from std.typecons >> doesn't seem to work with arrays. Should I use alloca() for my >> array or is there something else? >> > > https://dlang.org/library/std/array/static_array.html > Sorry I was misread this
Re: How can I allocate a int[] array on stack?
On Fri, Mar 26, 2021 at 7:36 AM Daniel Kozak wrote: > On Fri, Mar 26, 2021 at 7:31 AM Daniel Kozak wrote: > >> On Fri, Mar 26, 2021 at 6:50 AM Jack via Digitalmars-d-learn < >> digitalmars-d-learn@puremagic.com> wrote: >> >>> What's the equivalent of C's VLA in D? scoped from std.typecons >>> doesn't seem to work with arrays. Should I use alloca() for my >>> array or is there something else? >>> >> >> https://dlang.org/library/std/array/static_array.html >> > Sorry I was misread this > You can use allocator: import std.experimental.allocator.showcase; import std.experimental.allocator; import std.stdio; StackFront!4096 stackAlloc; void main() { int[] a = stackAlloc.makeArray!int(2); writeln(a); }
Re: How can I allocate a int[] array on stack?
On Fri, Mar 26, 2021 at 6:50 AM Jack via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > What's the equivalent of C's VLA in D? scoped from std.typecons > doesn't seem to work with arrays. Should I use alloca() for my > array or is there something else? > https://dlang.org/library/std/array/static_array.html
Re: Trying to reduce memory usage
On Saturday, 13 February 2021 at 04:19:17 UTC, Ali Çehreli wrote: On 2/11/21 6:22 PM, H. S. Teoh wrote: >bool[size_t] hashes; I would start with an even simpler solution until it's proven that there still is a memory issue: import std.stdio; void main() { bool[string] lines; foreach (line; stdin.byLine) { if (line !in lines) { stdout.writeln(line); lines[line.idup] = true; } // else this line already seen before; just skip it } } (Grr... Thanks for the tab characters! :p) Ali Try this Boost Licensed tool. https://github.com/eBay/tsv-utils/tree/master/tsv-uniq
Re: which free operating systems have a gtkd package?
On Sat, Jan 23, 2021 at 7:15 AM dan via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > ... > So debian 10 and ubuntu 20.4 are candidates, but i'm wondering if > there are others. (I tried to find gtkd on linux mint but did > not see a package for it, but man i could sure be wrong.) > > Thanks in advance for any info! > > dan > Anything archlinux based (Manjaro, Arch linux, EndeavourOS, RebornOS, Artix ...), Alpine linux, Fedora and many others. https://pkgs.org/search/?q=gtkd
Re: Directory recursive walking
On Fri, Jan 15, 2021 at 10:30 AM dog2002 via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > ... > Okay, the reason is incredibly stupid: using WinMain instead of > main causes high memory usage. I don't know why, I use the same > code. If I replace WinMain with main, the memory consumption is > about 6 MB. > https://wiki.dlang.org/D_for_Win32
Re: Directory recursive walking
On Fri, Jan 15, 2021 at 8:20 AM dog2002 via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Friday, 15 January 2021 at 06:56:36 UTC, dog2002 wrote: > > On Friday, 15 January 2021 at 06:33:55 UTC, Paul Backus wrote: > >> On Friday, 15 January 2021 at 06:31:18 UTC, Paul Backus wrote: > >>> > >>> You can save a little bit of memory here by allocating > >>> tempBuffer on the stack: > >>> > >>> ubyte[512] tempBuffer; > >>> _inputFile.rawRead(tempBuffer[]); // note the explicit [] > >> > >> I made a mistake; this should be: > >> > >> ubyte[512] tempArray; > >> ubyte[] tempBuffer = _inputFile.rawRead(tempArray[]); > >> > >> ...with the rest the same as your original version. > > > > Thank you so much! It saves a lot of memory! > > > > And one last question: why the application crashes, if I > > allocate 1 MB array? > > > >>ubyte[1024000] tempBuffer; > > Solved: > > ubyte[] tempBuffer = new ubyte[1024000]; > You can still use ubyte[1024000] tempBuffer; but you have to place it somewhere outside recursion or use a static static ubyte[1024000] tempBuffer;
Re: Directory recursive walking
On Fri, Jan 15, 2021 at 8:00 AM dog2002 via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Friday, 15 January 2021 at 06:33:55 UTC, Paul Backus wrote: > > On Friday, 15 January 2021 at 06:31:18 UTC, Paul Backus wrote: > >> > >> You can save a little bit of memory here by allocating > >> tempBuffer on the stack: > >> > >> ubyte[512] tempBuffer; > >> _inputFile.rawRead(tempBuffer[]); // note the explicit [] > > > > I made a mistake; this should be: > > > > ubyte[512] tempArray; > > ubyte[] tempBuffer = _inputFile.rawRead(tempArray[]); > > > > ...with the rest the same as your original version. > > Thank you so much! It saves a lot of memory! > > And one last question: why the application crashes, if I allocate > 1 MB array? > > >ubyte[1024000] tempBuffer; > Because of stack overflow
Re: How to debug D on Linux
On Wed, Jan 13, 2021 at 4:10 PM Roguish via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Wednesday, 13 January 2021 at 14:17:51 UTC, Rikki Cattermole > wrote: > > > > Same thing. > > Clear, thanks. > > I'm just discovering today that DMD and LDC are two different > compilers. I got a different impression from the following > webpage, which claims that ldmd2 is a wrapper invoking ldc2. > > > https://stackoverflow.com/questions/35515138/ldc2-vs-ldmd2-whats-the-difference > > Perhaps this is just a peculiarity of how D is distributed on > Debian? I simply installed the 'ldc' package from Debian's > official repos, and that contains both a binary called ldc2 and > one called ldmd2. > There are 3 main compilers which share same frontend, DMD (using own backend), LDC2(llvm backend) a GDC(gcc backend) ldmd and gdmd are some wrappers to make similar interface for compiling with any of these compilers. So generally dmd, gdmd and ldmd2(on some distribution ldmd without 2) should have accept same args So calling -arg1 -arg2 -arg3 should do the same but with different compilers behind the scene.
Re: Why is (int[int] s = int[int].init) not allowed
Dne st 23. 12. 2020 1:00 uživatel Steven Schveighoffer via Digitalmars-d-learn napsal: > On 12/22/20 5:44 PM, Daniel Kozak wrote: > > On Tue, Dec 22, 2020 at 10:15 PM Andre Pany via Digitalmars-d-learn > > > <mailto:digitalmars-d-learn@puremagic.com>> wrote: > > > > Hi, > > > > I am really confused, why is this valid: > > void sample(string[string] s = string[string].init){} > > > > while this causes syntax errors? > > > > void sample_invalid1(double[string] s = double[string].init){} > > void sample_invalid2(int[int] s = int[int].init){} > > > > Kind regards > > André > > > > > > As has been said this is an oddity in the grammar. But why would anyone > > need to use this anyway? > > > >void sample_invalid2(int[int] s = int[int].init){} > > > > seems really awful to me anyway. > > Yeah: > > void sample_valid(int[int] s = null) > > -Steve Yes AA.init is null per doc. https://dlang.org/spec/hash-map.html#construction_and_ref_semantic
Re: Why is (int[int] s = int[int].init) not allowed
On Tue, Dec 22, 2020 at 10:15 PM Andre Pany via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Hi, > > I am really confused, why is this valid: > void sample(string[string] s = string[string].init){} > > while this causes syntax errors? > > void sample_invalid1(double[string] s = double[string].init){} > void sample_invalid2(int[int] s = int[int].init){} > > Kind regards > André > As has been said this is an oddity in the grammar. But why would anyone need to use this anyway? void sample_invalid2(int[int] s = int[int].init){} seems really awful to me anyway.
Re: Is garbage detection a thing?
On Sunday, 29 November 2020 at 16:35:26 UTC, Mark wrote: Maybe I should just install Linux. But ... the drivers... My Thinkpad just doesn't like any Linux. I run out of ideas. In the first place all I wanted to do is make some music. Kind regards You could try a linux image in VirtualBox or VMware, to more easily evaluate if linux + ASAN matches your expectations or if it's another dead-end. Regards, Daniel
Re: Is garbage detection a thing?
On Sunday, 29 November 2020 at 16:05:04 UTC, Mark wrote: Thanks a lot for reading, and sorry for a lot of text that is off-topic and is not related to D. Sounds like what you want is ASAN? You can use it with plain C or D(LDC). https://clang.llvm.org/docs/AddressSanitizer.html
Re: why is "hello".writeln considered bad?
On Fri, Nov 20, 2020 at 8:55 AM Mike Parker via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > ... > Eh, I wouldn't quite put it that way. If we're thinking of the > same thread, one person said he thought it was a bad idea. That > doesn't make it bad practice. It's just his opinion. I think UFCS > is an awesome feature. And it's widely used in D code. > I remember days when I liked UFCS too . Unfortunately it is not so awesome when you use it with IDE. So I am now avoiding UFCS as much as possible and it is a much better experience for me.
Re: Task when used on a function that takes parameters doesnt work.
On Thu, Nov 12, 2020 at 4:12 PM Daniel Kozak wrote: > On Thu, Nov 12, 2020 at 4:05 PM Ruby The Roobster via Digitalmars-d-learn < > digitalmars-d-learn@puremagic.com> wrote: > >> Here is a test that I did: >> >> void func(int i) >> { >> Thread.sleep(i.seconds); >> } >> void main() { >> auto test = Task!func(3); >> test.executeInNewThread(); >> test.yeildForce(); >> } >> >> This gives the following errors(I'm using Code::Blocks as an IDE >> by the way, so this is what the IDE outputted): >> d:\Programs\D\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d|516|Error: >> function `hello.func(int i)` is not callable using argument types `()`| >> >> d:\Programs\D\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d|516| >>missing argument for parameter #1: `int i`| >> >> hello.d|8|Error: template instance `std.parallelism.Task!(func)` >> error instantiating| >> >> >> Any fix for this? >> > > You have some typos there > > import core.thread; > import std.parallelism; > > void func(int i) > { > Thread.sleep(i.seconds); > } > void main() { > auto test = task!(func)(3); > test.executeInNewThread(); > test.yieldForce(); > } > Typos: instead of Task you should write task, instead of yeildForce you should write yieldForce
Re: Task when used on a function that takes parameters doesnt work.
On Thu, Nov 12, 2020 at 4:05 PM Ruby The Roobster via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Here is a test that I did: > > void func(int i) > { > Thread.sleep(i.seconds); > } > void main() { > auto test = Task!func(3); > test.executeInNewThread(); > test.yeildForce(); > } > > This gives the following errors(I'm using Code::Blocks as an IDE > by the way, so this is what the IDE outputted): > d:\Programs\D\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d|516|Error: > function `hello.func(int i)` is not callable using argument types `()`| > > d:\Programs\D\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d|516| >missing argument for parameter #1: `int i`| > > hello.d|8|Error: template instance `std.parallelism.Task!(func)` > error instantiating| > > > Any fix for this? > You have some typos there import core.thread; import std.parallelism; void func(int i) { Thread.sleep(i.seconds); } void main() { auto test = task!(func)(3); test.executeInNewThread(); test.yieldForce(); }
Re: How to get address of a nested function?
On Tue, Nov 10, 2020 at 11:55 AM Max Samukha via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > We can get the compile time equivalent of a member function's > address by applying '&' to the function in a static context: > > struct S { > void foo() {} > } > > enum pfoo = // ok > > void main() { > // now we can use the pointer to create, for example, a > delegate > S s; > void delegate() dg; > dg.ptr = > dg.funcptr = pfoo; > dg(); > } > > However, we can't do that to a nested function: > > void main() { > void foo() { > } > enum pfoo = // weird kind of an enum delegate; > pfoo.funcptr can't be accessed at compile time. > } > > Is there a way to get a pointer to a non-static nested function? > non static nested function is a delegate, so you can just assign it to delegate like I have posted or you can du this: import std.stdio; void main() { void foo() { writeln("It works as expected"); } enum pfoo = void delegate() dg; dg.ptr = pfoo.ptr; dg.funcptr = pfoo.funcptr; dg(); }
Re: How to get address of a nested function?
On Tue, Nov 10, 2020 at 8:50 PM Max Samukha via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Tuesday, 10 November 2020 at 14:36:04 UTC, Steven > Schveighoffer wrote: > > >> > >> Is there a way to get a pointer to a non-static nested > >> function? > > > > I don't think you can do it at compile time. You can at runtime > > by accessing the funcptr of the delegate. > > > > -Steve > > Thanks for the reply. I will post the issue to bugzilla. > Why? It works for me import std.stdio; void main() { void foo() { writeln("It works as expected"); } enum pfoo = void delegate() dg = pfoo; dg(); }
Re: std.net.curl : Performance
On Mon, Nov 9, 2020 at 9:50 PM rinfz via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Monday, 9 November 2020 at 20:40:59 UTC, rinfz wrote: > > On Monday, 9 November 2020 at 19:55:07 UTC, Vino wrote: > >> ... > > > > The only curl option you need to set within the loop is the > > CurlOption.url. So your foreach block should look more like: > > > > foreach (...) { > > string url = chain(apihost, only(':'), to!string(apiport), > > apiuri).to!string; > > https.handle.set(CurlOption.url, url); > > https.perform(); > > scope(failure) exit(-4); > > scope(exit) https.shutdown; > > apidata.insert(tuple(seq, cast(string) content)); > > content = []; > > } > > > > Every other line can be placed before the foreach. > > In fact, you don't need url in there either since it's not > dependent on loop variables, and you don't need the scope guards > if this is running in main (you can move them out of the loop > too). > > foreach (...) { > https.handle.set(CurlOption.url, url); > https.perform(); > apidata.insert(tuple(seq, cast(string) content)); > content = []; > } > In fact he does not need foreach. Because he use it on empty result
Re: std.net.curl : Performance
Just delete it On Mon, Nov 9, 2020 at 9:00 PM Vino via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Hi All, > >Request your help to on how to improve the performance of the > below code. > > import std.conv: to; > import std.net.curl : get, HTTP, CurlOption; > import std.parallelism: parallel; > import std.range: chain, only; > import std.typecons: Tuple, tuple; > > void main () > { > Array!(Tuple!(int,string)) apidata; > Row[] result; > string apihost = "abc.com"; int apiport = 1830; string apiuri = > /getdata; > string apiuser = "user"; string apipass = "pass"; > foreach(i, k; parallel(result,1)) > { >string url = chain(apihost, only(':'), to!string(apiport), > apiuri).to!string; >string usrpass = chain(apiuser, only(':'), > apipass).to!string; >auto https = HTTP(); >https.handle.set(CurlOption.buffersize, 512000); >https.handle.set(CurlOption.userpwd, usrpass); >https.handle.set(CurlOption.connecttimeout, 600); >https.handle.set(CurlOption.tcp_nodelay, 1); >https.handle.set(CurlOption.http_version, 2); >https.handle.set(CurlOption.sslversion, 1; >https.handle.set(CurlOption.use_ssl, 3); >https.handle.set(CurlOption.ssl_verifypeer, 0); >https.handle.set(CurlOption.url, url); >https.method(HTTP.Method.get); >https.StatusLine st; >https.onReceiveStatusLine = (https.StatusLine st) { if > (st.code != 200) { throw new Exception(st.reason); } }; >ubyte[] content; >https.onReceive = (ubyte[] data) { content ~= data; return > data.length; }; >https.perform(); >scope(failure) { https.shutdown; exit(-4); } scope(exit) > https.shutdown; >apidata.insert(tuple(seq, cast(string) content)); > } > return apidata[].sort; > } > > From, > Vino.B >
Re: New vs length on dymamic array
On Monday, 9 November 2020 at 08:06:54 UTC, Andrey wrote: Hello, Are here any differences in creation of dynamic array with known size? auto array = new wchar[](111); and wchar[] array; array.length = 111; In theory auto array = new wchar[111]; // or new wchar[](111); should do less work, but in practice I would guess there will be almost zero difference in speed. If you need to create new dynamic array with known size you should prefere auto array = new wchar[111]; // or new wchar[](111); because it is make much more sense than create empty non initialized array and then set it a length
Re: What is the difference between enum and shared immutable?
On Thu, Oct 29, 2020 at 4:13 PM H. S. Teoh via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > > But why can't that be treated differently from explicitly writing @safe > on a declaration? I mean, yeah, it's easier to implement the compiler > that way, but ease of implementation shouldn't count against proper > language design! > > > T > > -- > Doubt is a self-fulfilling prophecy. > But what about this: shared { some_ type some_var; immutable int x = 1; } There are many ways to define it and last time when I was looking at how this is implemented in D frontend it was implemented as a bitmask variable and you have no context from where it comes. So only way would be to disallow this within lexer which I do not see as a good options
Re: Why was new(size_t s) { } deprecated in favor of an external allocator?
On Wed, Oct 14, 2020 at 10:30 PM Jack via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > What was the reasoning behind this decision? > https://dlang.org/deprecate.html#Class allocators and deallocators
Re: question on dub and postgresql
On Mon, Oct 5, 2020 at 10:25 AM Alaindevos via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Can I say python has pip, ruby has bundle and D has dub. > Meaning they perform the same function ? > Or am I wrong? > Yes and no. Dub is Dlang dependency solution but it is not installer as pip is > > As I use unix the parameters for include and library are a real > pain. > I have totally no idea how to connect to a postgresql database. > Where and how do I start to connect to a postgresql database ? > I write a .d program to connect. > But then I need to include the database-connection-library.d file. > Where do I place it ? > And link a database-connection. object file. > How is it installed ? There is a only a git i can clone ? > Do I need to create and edit a specific dub json config file ? > It is very unclear how to start. > Yes if you want to use any of dub packages you need to add it as a dependency to your dub.json (dub.sdl)
Re: Whats going on with this?
On Sat, Oct 3, 2020 at 11:30 PM Steven Schveighoffer via Digitalmars-d-learn wrote: > > > "StructMemberInitializers with the NonVoidInitializer syntax appear in > the lexical order of the fields in the StructDeclaration" seems to > suggest it will not call the constructor, but instead initialize the > fields according to the list. > > The fields are not a static array, so clearly it is calling the > constructor, and not initializing the fields. > > I really don't think this case is in the spec. > > But I know it works, for instance: > > Variant v = anything; > > If this required an explicit Variant constructor, it would be quite > annoying. > > -Steve > Yes you are right
Re: Whats going on with this?
On Sat, Oct 3, 2020 at 10:40 PM Daniel Kozak wrote: > I would say it is here you just need to read it carefully: > > https://dlang.org/spec/struct.html#static_struct_init > > For case specification is change I will paste it here: ''' If a StructInitializer is supplied, the fields are initialized by the StructMemberInitializer syntax. StructMemberInitializers with the Identifier : NonVoidInitializer syntax may be appear in any order, where Identifier is the field identifier. StructMemberInitializers with the NonVoidInitializer syntax appear in the lexical order of the fields in the StructDeclaration. ''' And StructMemberInitializer is defined as: ''' StructMemberInitializer: NonVoidInitializer Identifier : NonVoidInitializer ''' And NonVoidInitializer is defined as: ''' NonVoidInitializer: ExpInitializer ArrayInitializer StructInitializer ''' And as you can see there is ArrayInitializer And there is definition of Array literals here https://dlang.org/spec/expression.html#array_literals and in section 2. there is this text: ''' By default, an array literal is typed as a dynamic array, but the element count is known at compile time. So all array literals can be implicitly converted to static array types. '''
Re: Whats going on with this?
On Sat, Oct 3, 2020 at 4:45 PM Steven Schveighoffer via Digitalmars-d-learn wrote: > On 10/3/20 6:52 AM, claptrap wrote: > > On Saturday, 3 October 2020 at 00:15:02 UTC, Steven Schveighoffer wrote: > >> On 10/2/20 7:28 PM, claptrap wrote: > >> > >>> Why would putting in the writeln cause it to fail? Is it maybe trying > >>> to create the foo at compile time? > >>> > >> > >> Yes, it is. Any static initialization of static variables happens at > >> compile-time. > >> > >> https://dlang.org/spec/declaration.html#global_static_init > >> > > > > Ah.. ok, any idea why this works? > > > > Foo foo = [300,300]; > > Yeah, it's calling the constructor. I agree with Adam, there's nothing > in the spec that talks about this that I can find. > > -Steve > I would say it is here you just need to read it carefully: https://dlang.org/spec/struct.html#static_struct_init
Re: vibe.de multiple ports.
On Wed, Sep 30, 2020 at 2:40 PM seany via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Wednesday, 30 September 2020 at 12:29:06 UTC, Daniel Kozak > wrote: > > to separate the messages from the IoT responses quickly and > forward them to different programs, and to have the capability in > hand, so that when later i have an idea to exploit the > capability, I can also do it. > Ok as Adam said you can do something like this: void main() { immutable ushort startPort = 5500; import std.range : iota; foreach (ushort port; iota!(ushort,ushort)(startPort, startPort + 100)) { auto settings = new HTTPServerSettings; settings.port = port; settings.bindAddresses = ["::1", "127.0.0.1"]; listenHTTP(settings, ); } runApplication(); } void hello(HTTPServerRequest req, HTTPServerResponse res) { import std.conv : to; res.writeBody(req.fullURL.port.to!string); }
Re: vibe.de multiple ports.
Dne st 30. 9. 2020 13:25 uživatel seany via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> napsal: > Hello > > I am trying to use this example for a iot application: > https://aberba.com/2018/using-vibe-d-web-interface/ > > The code i use is: > > ushort port = 5504; > > void main(char[][] args) > { > > auto router = new URLRouter; > router.post("/archive", ); > router.get("/archive", ); > > auto settings = new HTTPServerSettings; > settings.port = port; > settings.bindAddresses = ["::1", "0.0.0.0"]; > listenHTTP(settings, router); > > runApplication(); > } > > > This is fine. But now that we have ~ 100 IoT devices in the > field, I would like to assign each a new port. > Why? I do not see any reason for that. >
Re: Why private methods cant be virtual?
On Tue, Sep 22, 2020 at 3:05 PM claptrap via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > > The thread title is... > > "Why private methods cant be virtual?" > > IE Not... > > "how do I override private functions in a non-polymorphic manner." > > And what you suggest wont work because I was asking about virtual > functions, so I specifically want polymorphism. And FWIW it's no > big deal I can just use protected, i wasn't looking for a > solution, I was looking for an explanation as to why it was done > that way. But apparently there is none. > > And I did not try to show solution. It was just an answer to this part of your response: So final private functions can be overriden? It seems not, but the sentence is definitely confusing if not just plain wrong. So the reason why there is this: "Functions marked as final may not be overridden in a derived class, unless they are also private" Is because with private methods final keyword has no meaning. And there is a reason "Why private methods cant be virtual?". It is because it would break existing code. And because private methods are final it makes them fast. And yes compiler probably could findout that method could be made non-virtual but I am not sure how easy is this and how it would slow down compilation times
Re: Why private methods cant be virtual?
On Tue, Sep 22, 2020 at 1:30 PM ShadoLight via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > > > This is not really "overriding", it is more akin to "overloading" > No it is not overloading, overloading is when you have more methods with same name and differents params. It is overriding > It is also not polymorphic > I did not say otherwise :-)
Re: Why private methods cant be virtual?
On Tue, Sep 22, 2020 at 11:06 AM claptrap via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > > "Functions marked as final may not be overridden in a derived > class, unless they are also private" > > So final private functions can be overriden? It seems not, but > the sentence is definitely confusing if not just plain wrong. > > Yes they can, if you have class A in one module and class B in another module this will work: //a.d class A { private final void overrideFun() { import std.stdio : writeln; writeln("A::overrideFun"); } } //b.d import a; class B : A { void overrideFun() { import std.stdio : writeln; writeln("B::overrideFun"); } } // main.d import b; void main(string[] args) { B b = new B; b.overrideFun; }
Re: Why private methods cant be virtual?
On Tue, Sep 22, 2020 at 12:23 PM Daniel Kozak wrote: > ... > void main(string[] args) > { > B b = new B; > b.overrideFun; > } > You can have A and B in one module too of course
Re: Why does compose from std.functional return a templated function
On Wed, Sep 16, 2020 at 12:50 PM Daniel Kozak wrote: > > > On Wed, Sep 16, 2020 at 12:00 PM Jan Hönig via Digitalmars-d-learn < > digitalmars-d-learn@puremagic.com> wrote: > >> ... >> >> My main question is why? Is there something, which I am missing, >> that explains, why it is beneficial to return a templated >> function? >> >> (maybe, because I might want to compose together templated >> non-initialized functions?) > > (maybe, because I might want to compose together templated non-initialized functions?) Yes
Re: Why does compose from std.functional return a templated function
On Wed, Sep 16, 2020 at 12:00 PM Jan Hönig via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > ... > > My main question is why? Is there something, which I am missing, > that explains, why it is beneficial to return a templated > function? > > (maybe, because I might want to compose together templated > non-initialized functions?) > It has to be templated because than you can alias it and use it many times something like import std.stdio; import std.functional : compose; import std.algorithm.comparison : equal; import std.algorithm.iteration : map; import std.array : split, array; import std.conv : to; alias StrArrToIntArr = compose!(array,map!(to!int), split); void main() { auto str1 = "2 4 8 9"; int[] intArr = StrArrToIntArr(str1); } If compose would not be template it would need to store functions addresses so it would need to have some array of functions, this would be ineffective and need to use GC
Re: Vibe-D File Question
On Fri, Sep 11, 2020 at 1:15 PM Daniel Kozak wrote: > On Fri, Sep 11, 2020 at 1:10 PM Selim Ozel via Digitalmars-d-learn < > digitalmars-d-learn@puremagic.com> wrote: > >> It seems like rejected-software forum is flooded with spam, so I >> decided to ask it here. Is there a way to generate a file -csv >> for example- on the back-end and serve it to the front-end as a >> file. >> >> Serve static file [1] function does this for files saved on the >> disk. I want to be able to generate a file during runtime and >> serve it to the client. Is this possible? >> >> Thanks, >> S >> >> >> [1] https://vibed.org/api/vibe.http.fileserver/serveStaticFile >> >> >> > https://vibed.org/api/vibe.http.server/HTTPServerResponse.writeBody > import vibe.core.core; import vibe.http.server; void main() { runWorkerTaskDist(); runApplication(); } void wrap() { auto settings = new HTTPServerSettings(":8080"); settings.options |= HTTPServerOption.reusePort; listenHTTP(settings, ); } void fun(HTTPServerRequest req, HTTPServerResponse res) nothrow { try { res.headers["Content-Disposition"] = "filename=\"muj.csv\""; res.writeBody("some;csv;data", "text/csv"); } catch (Exception e) {} }
Re: Vibe-D File Question
On Fri, Sep 11, 2020 at 1:10 PM Selim Ozel via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > It seems like rejected-software forum is flooded with spam, so I > decided to ask it here. Is there a way to generate a file -csv > for example- on the back-end and serve it to the front-end as a > file. > > Serve static file [1] function does this for files saved on the > disk. I want to be able to generate a file during runtime and > serve it to the client. Is this possible? > > Thanks, > S > > > [1] https://vibed.org/api/vibe.http.fileserver/serveStaticFile > > > https://vibed.org/api/vibe.http.server/HTTPServerResponse.writeBody
Re: vibe.d and my first web service
On Wed, Aug 12, 2020 at 3:51 PM James Blachly via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Unfortunately the problem still occurs with Vibe.d 0.9.0 > > IMO **this is the single most important problem to fix** for vibe.d -- > if the most basic of examples (indeed, supplied by dub itself) fails so > spectacularly, the casual new user will not spend the time to find out > why this is happening, but instead move on. The ctrl-C non-termination > bug has existed since at least 2015 from what I can tell from the forums. > > Tangent: > > Does Sönke have a Patreon or the project an OpenCollective etc. ? I > would be willing to support fixing of some of these bugs. > > Alternatively, could we vote on whether a web framework is worthy of > foundation support? Having an ergonomic, workable web framework is > absolutely essential to surviving as a language in 2020 (notable > exception being 800# gorilla incumbents C/C++). > Unfortunately, I think vibe-d is dead. With every release it is worse than before and it seems there is almost no activity. So D really need new champion here maybe hunt will be next champion.
Re: LDC cross-module-inlining
On Mon, Aug 10, 2020 at 1:15 PM Per Nordlöw via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Monday, 10 August 2020 at 05:54:14 UTC, Daniel Kozak wrote: > > I am not sure but last time I checked ldc does not do cross > > module inlinig by default, and LTO only help if your > > ldc(druntime+phobos) are built with enabled LTO[1] > > > > [1] > > https://github.com/ldc-developers/ldc/issues/2182#issuecomment-343166633 > > Are the official LDC-releases builtin with or without LTO? > AFAIK only for OSX, but Arch linux ldc package is now build with LTO enabled
Re: LDC cross-module-inlining
On Mon, Aug 10, 2020 at 12:50 AM claptrap via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Sunday, 9 August 2020 at 22:18:13 UTC, Per Nordlöw wrote: > > ... > If you enable link time optimisation you get cross module > inlining, > > -flto=full > > I'm not 100% sure but I think LDC did cross module inlining by > default at some point, then I updated the compiler and had to add > the LTO thing. I think there is an option to enable just cross > module inlining, but if you want speed you'll probably want to > have LTO enabled anyway? > I am not sure but last time I checked ldc does not do cross module inlinig by default, and LTO only help if your ldc(druntime+phobos) are built with enabled LTO[1] [1] https://github.com/ldc-developers/ldc/issues/2182#issuecomment-343166633
Re: LDC cross-module-inlining
On Mon, Aug 10, 2020 at 12:20 AM Per Nordlöw via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > > Is cross-module-inlining enabled by default in LDC when compiling > in release mode or do I have to use explicitly flag for it? I > can't find any such flag from the output of neither > > ldc2 -h > > nor > > ldmd2 -h > > Johan Engelen mentioned this, then experimental, flag in his > DConf talk from 2017 [1] > > [1] https://www.youtube.com/watch?v=IZY67TBZ0V4 ldc2 --help-hidden | grep cross --disable-demotion - Clone multicolor basic blocks but do not demote cross scopes * --enable-cross-module-inlining= - (*) Enable cross-module function inlining (default disabled)* --iterative-counter-promotion - Allow counter promotion across the whole loop nest. --jump-threading-across-loop-headers- Allow JumpThreading to thread across loop headers, for testing --licm-n2-threshold= - How many instruction to cross product using AA --lsr-backedge-indexing - Enable the generation of cross iteration indexed memops =cross-dso-cfi- Cross-DSO CFI =cross-dso-cfi- Cross-DSO CFI --split-dwarf-cross-cu-references - Enable cross-cu references in DWO files --x86-align-branch-boundary=
Re: vibe / CTRL+C not terminating server
On Sat, Jun 13, 2020 at 9:20 PM Robert M. Münch via Digitalmars-d-learn wrote: > > After a CTRL+C I still have the server process running on OSX. Any idea? > > [main() INF] Listening for requests on http://[::1]:8080/ > [main() INF] Listening for requests on http://127.0.0.1:8080/ > [main() INF] Please open http://127.0.0.1:8080/ in your browser. > ^C > [main() INF] Received signal 2. Shutting down. > > After this, the server is still running. > > -- > Robert M. Münch > http://www.saphirion.com > smarter | better | faster > https://github.com/vibe-d/vibe-core/issues/205 https://github.com/vibe-d/vibe.d/issues/2436
Re: m32mscoff with lld-link causes SEH errors
On Tuesday, 26 May 2020 at 15:56:31 UTC, kinke wrote: Using `-L/safeseh:no` should work around this. It successfully made the executable, and it runs fine - until exit lol. Must be more tweaks needed. Edit source/app.d to start your project. object.Error@(0): Access Violation 0x0045F058 0x0040139F 0x0040100D 0x00405879 0x00405710 0x00402A1E 0x00401030 0x75C6347D in BaseThreadInitThunk 0x77059852 in RtlInitializeExceptionChain 0x77059825 in RtlInitializeExceptionChain - CreateProcess Program Exit code: 1 -
Re: m32mscoff with lld-link causes SEH errors
On Tuesday, 26 May 2020 at 15:56:31 UTC, kinke wrote: On Monday, 25 May 2020 at 01:32:58 UTC, Daniel C wrote: Is lld-link only for 64-bit compiles (-m64 is the only one that gives no errors) Nope, but SafeSEH is a 32-bit-only feature. DMD doesn't emit SafeSEH compatible object files, and LLD seems to have a different default setting in that regard compared to MS link.exe. Using `-L/safeseh:no` should work around this. Thank you! One more thing to add to my compile/link notes =)
Re: Using Vibe.d for not HTTP
On Sun, May 24, 2020 at 10:10 AM Russel Winder via Digitalmars-d-learn wrote: > > Hi, > > Clearly Vibe.d is mostly for people doing HTTP and HTTPS stuff. Yet it claims > to be able to support TCP and UDP working with other protocols. However, all > the serious examples are HTTP/HTTPS related. All the TCP and UDP examples are > basically trivial and thus useless to me for learning. > > I am hoping I have just missed the page/example that does something more than > just echo for a TCP server. If I haven't, is ther an example somewhere people > know of that I can look at? https://run.dlang.io/is/SMLuA2
Re: Learning Vibe.d
On Sun, May 24, 2020 at 10:06 AM Russel Winder via Digitalmars-d-learn wrote: > > For my purposes switching to using SIGKILL rather than SIGTERM in my tests > seems to work with 1.9.1, so I'll go with that till 1.9.2 or 1.10.0 produces a > fix rather than revert to 1.8.1. > You can use VibeHighEventPriority version in your dub as a workaround for now, there is no need to revert to 1.8.1
m32mscoff with lld-link causes SEH errors
Hi, I have a simple program with just one line (below). I've compiled on Windows using dmd -ms32coff app.d and have had LINKCMD set to lld-link, but get the following errors. Is lld-link only for 64-bit compiles (-m64 is the only one that gives no errors) lld-link: error: /safeseh: app.obj is not compatible with SEH lld-link: error: /safeseh: ti_Ag_2714_4a7.obj is not compatible with SEH lld-link: error: /safeseh: stdio_4_58e.obj is not compatible with SEH lld-link: error: /safeseh: stdio_1_180.obj is not compatible with SEH lld-link: error: /safeseh: exception_2baa_5b5.obj is not compatible with SEH lld-link: error: /safeseh: deh_win32_256e_60b.obj is not compatible with SEH lld-link: error: /safeseh: deh_win32_2577_653.obj is not compatible with SEH lld-link: error: /safeseh: lifetime_25bb_4e0.obj is not compatible with SEH lld-link: error: /safeseh: lifetime_25a5_482.obj is not compatible with SEH lld-link: error: /safeseh: dmain2_2597_47b.obj is not compatible with SEH lld-link: error: /safeseh: deh_win32_2571_3b9.obj is not compatible with SEH lld-link: error: /safeseh: object_cf_6f6.obj is not compatible with SEH lld-link: error: /safeseh: object_10_583.obj is not compatible with SEH lld-link: error: /safeseh: ti_Ag_2712_42f.obj is not compatible with SEH lld-link: error: /safeseh: object_266_6bb.obj is not compatible with SEH lld-link: error: /safeseh: object_7_32e.obj is not compatible with SEH lld-link: error: /safeseh: ti_Ag_270e_435.obj is not compatible with SEH lld-link: error: /safeseh: ti_Ag_270f_436.obj is not compatible with SEH lld-link: error: /safeseh: object_a_58c.obj is not compatible with SEH lld-link: error: /safeseh: stdio_10_cfb.obj is not compatible with SEH app.d: import std.stdio; void main() { writeln("Edit source/app.d to start your project."); }
Re: gzip and vibe.d
On Wed, May 20, 2020 at 9:45 AM Atwork via Digitalmars-d-learn wrote: > > Is it possible to have vibe.d gzip responses? > > I cannot find anything in the documentation about it. > > I am not talking about gzipping ex. files/streams but ALL > responses as a whole. > > Is there a configuration or something I need to set for it to be > supported? https://vibed.org/api/vibe.http.server/HTTPServerSettings.useCompressionIfPossible
Re: gzip and vibe.d
https://vibed.org/api/vibe.http.server/HTTPServerSettings.useCompressionIfPossible On Wed, May 20, 2020 at 9:45 AM Atwork via Digitalmars-d-learn wrote: > > Is it possible to have vibe.d gzip responses? > > I cannot find anything in the documentation about it. > > I am not talking about gzipping ex. files/streams but ALL > responses as a whole. > > Is there a configuration or something I need to set for it to be > supported?
Re: D and Async I/O
On Mon, May 11, 2020 at 4:03 PM Russel Winder via Digitalmars-d-learn wrote: > > ... > I notice that Hunt uses it's own library eschewing all of Phobos. Is this an > indicator that Phobos is not suitable for networking activity? Vibe-d do that too, But https://code.dlang.org/packages/async use phobos socket and works well
Re: Rust, D, GTK+, and asynchronous working
On Mon, Apr 27, 2020 at 11:56 AM Russel Winder via Digitalmars-d-learn wrote: > > Hi, > > Background: I chose to rewrite a Python/PySide2/Qt application in > X/GTK+. After much dithering I was pushed to Rust/gtk-rs/GTK+ and set > to it. Then I decided to do D/GtkD/GTK+ as well. > > Totally unscientific, biased, and indeed prejudiced result is that D is > a nicer programming language to work with than Rust for doing GTK+ > related UIs. > > BUT… > > Now I have to add the networking. > > GTK+ (and therefore both gtk-rs and GtkD) has APIs for all the socket > stuff so as to be harmonious with the Glib/GIO/GTK way of the world. > The Big Question™ is how to add monitoring a read socket stream in the > event loop. > > Qt just does it automatically as far as I can tell, but GTK+ appears > not to. Which is totally bizarre. > > Rust now has async/await and futures such that you can create something > to put on the GTK+ event loop very easily. It also has very nice tools > for doing "reactive programming" using classic programming constructs > that turn into event loop manangement with futures. > > Does D have anything similar or has it missed the "programming with > event loops" boat. Currently I am having a hard time finding ways of > doing what is easy with Rust/gtk-rs/GTK+ using D/GtkD/GTK+ and this is > rather frustrating given how much nicer D is for working with GTK+ than > Rust is. > > > -- > Russel. > === > Dr Russel Winder t: +44 20 7585 2200 > 41 Buckmaster Roadm: +44 7770 465 077 > London SW11 1EN, UK w: www.russel.org.uk > D does not have any builtin async/await but you can use libraries https://code.dlang.org/packages/vibe-core https://code.dlang.org/packages/dawait
Re: Using LDC2 on ARM
On Mon, Mar 2, 2020 at 6:50 PM Severin Teona via Digitalmars-d-learn wrote: > > Hello, > > I am working on a project that uses a Raspberry Pi (armv7l) and > the latest LDC version I found for this architecture is 1.13.0. > Can you help me install the latest version(1.20.0)? > > Also, I'm having problems using the DPP package with the 1.13.0 > LDC version, most likely because the latest version of DPP(0.4.1) > is using a newer version of Phobos. > > Is there any reason why the LDC team stopped releasing pre-built > binaries for arm? > > I'm looking forward to your help. > Teona. Do you really need to build you app on arm, could not you use crosscompiling?
Re: Using LDC2 on ARM
On Mon, Mar 2, 2020 at 7:40 PM Daniel Kozak wrote: > > On Mon, Mar 2, 2020 at 6:50 PM Severin Teona via Digitalmars-d-learn > Do you really need to build you app on arm, could not you use crosscompiling? https://wiki.dlang.org/Cross-compiling_with_LDC
Re: Using LDC2 on ARM
On Mon, Mar 2, 2020 at 7:40 PM Daniel Kozak wrote: > > On Mon, Mar 2, 2020 at 6:50 PM Severin Teona via Digitalmars-d-learn > wrote: > > > > Hello, > > > > I am working on a project that uses a Raspberry Pi (armv7l) and > > the latest LDC version I found for this architecture is 1.13.0. > > Can you help me install the latest version(1.20.0)? > > > > Also, I'm having problems using the DPP package with the 1.13.0 > > LDC version, most likely because the latest version of DPP(0.4.1) > > is using a newer version of Phobos. > > > > Is there any reason why the LDC team stopped releasing pre-built > > binaries for arm? > > > > I'm looking forward to your help. > > Teona. > > Do you really need to build you app on arm, could not you use crosscompiling? But if you really wan to compile it on RPI you could try use archlinuxarm and ldc package: https://archlinuxarm.org/packages/armv7h/ldc
Re: GtkD on Windows: notes + question
"lflags-windows": ["/SUBSYSTEM:WINDOWS", "/ENTRY:mainCRTStartup"], On Sun, Feb 9, 2020 at 2:30 PM mark via Digitalmars-d-learn wrote: > > I found a much easier way to get GtkD working on windows than > that described in > https://gtkdcoding.com/2019/01/11/-introduction-to-gtkDcoding.html > > 1. I downloaded and installed the Gtk3 runtime (the link is on > https://gtkdcoding.com/2019/01/11/-introduction-to-gtkDcoding.html) > > 2. I downloaded and unzipped the GtkD3 zip to C:\bin\GtkD3 > > 3. Since I'd already installed LDC I just had to run: > > dub add-path C:\bin\GtkD3 > > Now I'm able to build and run on windows using dub. And again, I > get static builds so have deployable .exes. > > However, when I double-click a GtkD .exe it pops up a console > window, then the GUI window, and the console window stays until I > close the GUI. > > Is there a way to avoid the console Window, at least for release > builds? >
Re: ints.choice vs. chars.choice
On Mon, Nov 18, 2019 at 7:25 PM Steven Schveighoffer via Digitalmars-d-learn wrote: > > > You could also use cast(dchar[]), and avoid the cast back to char. > > -Steve or use byCodeUnit writeln(['a', 'b', 'c'].byCodeUnit.choice);
Re: Alias sleep(int) for Thread.sleep(dur!("seconds")( int ));
On Tue, Nov 12, 2019 at 11:50 PM Marcone via Digitalmars-d-learn wrote: > > > Can you make Alias for: > task!func().executeInNewThread(); > > Thank you! AFAIK that is not possible without some wrapper because executeInNewThread is member function of Task so it will need this reference for object
Re: Alias sleep(int) for Thread.sleep(dur!("seconds")( int ));
On Tuesday, 12 November 2019 at 21:24:54 UTC, Marcone wrote: I am using this function to sleep, but I want a simple Alias. How can I alias this? // Function sleep(int) void sleep(int seconds){ Thread.sleep(dur!("seconds")( seconds )); } sleep(1); // Using function. You can do this: import std.functional; import core.time; import core.thread; alias sleep = compose!(Thread.sleep, dur!("seconds")); void main() { sleep(10); }
Re: Hum humm, build latest release with ldc
On Mon, Nov 4, 2019 at 10:45 AM Treebeard via Digitalmars-d-learn wrote: > > Hoom, hum, can you tell me some nice instructions to compile the > latest release of DMD using LDC? > > I walk slowly, but I love fast compilers. > > --- > But I spoke hastily. We must not be hasty. I have become too hot. > I must cool myself and think; for it is easier to shout stop! > than to do it - The Two Towers https://git.archlinux.org/svntogit/community.git/tree/repos/community-x86_64/PKGBUILD?h=packages/dmd=344d0f94265571a55ca8213882151a5910bc4400#n54
Re: Accuracy of floating point calculations
On Tue, Oct 29, 2019 at 5:09 PM Daniel Kozak wrote: > > On Tue, Oct 29, 2019 at 4:45 PM Twilight via Digitalmars-d-learn > wrote: > > > > D calculation: > >mport std.stdio; import std.math : pow; import core.stdc.math; void main() { writefln("%12.3F",log(1-0.)/log(1-(1-0.6)^^20)); } > >writefln("%12.2F",log(1-0.)/log(1-(1-0.6)^^20)); > > > > 837675572.38 > > > > C++ calculation: > > > >cout< > <<'\n'; > > > > 837675573.587 > > > > As a second data point, changing 0. to 0.75 yields > > 126082736.96 (Dlang) vs 126082737.142 (C++). > > > > The discrepancy stood out as I was ultimately taking the ceil of > > the results and noticed an off by one anomaly. Testing with > > octave, www.desmos.com/scientific, and libreoffice(calc) gave > > results consistent with the C++ result. Is the dlang calculation > > within the error bound of what double precision should yield? > > If you use gdc or ldc you will get same results as c++, or you can use > C log directly: > > import std.stdio; > import std.math : pow; > import core.stdc.math; > > void main() > { > writefln("%12.3F",log(1-0.)/log(1-(1-0.6)^^20)); > } My fault, for ldc and gdc you will get same result as C++ only when you use pow not ^^(operator) and use doubles: import std.stdio; import std.math; void main() { writefln("%12.3F",log(1-0.)/log((1-pow(1-0.6,20; }
Re: Accuracy of floating point calculations
On Tue, Oct 29, 2019 at 5:09 PM Daniel Kozak wrote: > > > If you use gdc or ldc you will get same results as c++, or you can use > C log directly: > > import std.stdio; > import std.math : pow; > import core.stdc.math; > > void main() > { > writefln("%12.3F",log(1-0.)/log(1-(1-0.6)^^20)); > } AFAIK dmd use real for floating point operations instead of double
Re: Accuracy of floating point calculations
On Tue, Oct 29, 2019 at 4:45 PM Twilight via Digitalmars-d-learn wrote: > > D calculation: > >writefln("%12.2F",log(1-0.)/log(1-(1-0.6)^^20)); > > 837675572.38 > > C++ calculation: > >cout< <<'\n'; > > 837675573.587 > > As a second data point, changing 0. to 0.75 yields > 126082736.96 (Dlang) vs 126082737.142 (C++). > > The discrepancy stood out as I was ultimately taking the ceil of > the results and noticed an off by one anomaly. Testing with > octave, www.desmos.com/scientific, and libreoffice(calc) gave > results consistent with the C++ result. Is the dlang calculation > within the error bound of what double precision should yield? If you use gdc or ldc you will get same results as c++, or you can use C log directly: import std.stdio; import std.math : pow; import core.stdc.math; void main() { writefln("%12.3F",log(1-0.)/log(1-(1-0.6)^^20)); }
Re: Running unittests of a module with -betterC
On Mon, Oct 28, 2019 at 9:40 AM Per Nordlöw via Digitalmars-d-learn wrote: > > Is it possible to run the unittests of a module with -betterC like > > dmd -D -g -main -unittest -betterC f.d > > ? > > This currently errors as > > /usr/include/dmd/druntime/import/core/internal/entrypoint.d:34: > error: undefined reference to '_d_run_main' > > for an empty file f.d AFAIK no, https://dlang.org/spec/betterc.html#unittests
Re: Converting a ulong to a byte array and constructing a ulong from it
On Thu, Oct 24, 2019 at 3:35 PM 9898287 via Digitalmars-d-learn wrote: > > What's the function for converting a ulong to a native-endian > byte array? > For example, > > auto bytes = 0x1234567890123456u64.to_ne_bytes(); > // should yield > // [0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56] in big-endian > and > // [0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12] in > little-endian systems > > Also, what's the function for constructing a ulong from a > native-endian byte array? > For example, > > auto value = from_be_bytes!ulong([0x12, 0x34, 0x56, 0x78, 0x90, > 0x12, 0x34, 0x56]); > // value is 0x1234567890123456 > > Rust equivalent: > https://doc.rust-lang.org/std/primitive.u64.html#method.to_ne_bytes You could use https://dlang.org/phobos/std_bitmanip.html#write https://dlang.org/phobos/std_bitmanip.html#read
Re: Differences between two dates (in days...)
On Thu, Oct 24, 2019 at 1:55 PM Mil58 via Digitalmars-d-learn wrote: > > Hi All... > I am desperate for the answer to the following problem: > to obtain the difference between the date of today and an older > date (results in days...) > > See my script below, where I would like to do: > "date of today" (var: auj) - "an older date" (var: deb) = xx days > > import std.stdio; > import std.datetime; > import core.time : Duration; > > void main() > { > auto deb = DateTime(2019, 9, 5); > auto auj = Clock.currTime(); > writeln("Aujourd'hui : ", auj.day, " ", auj.month, " ", auj.year); > writeln("Le début : ", deb.day, " ", deb.month, " ", deb.year); > } > > Thanks in advance ! :-) import std.stdio; import std.datetime; import core.time : Duration; void main() { auto deb = DateTime(2019, 9, 5); auto auj = Clock.currTime(); writeln("Aujourd'hui : ", auj.day, " ", auj.month, " ", auj.year); writeln("Le début : ", deb.day, " ", deb.month, " ", deb.year); writeln("Diff in days : ", (cast(DateTime)auj - deb).total!"days"); }
Re: How to use classes from another d files
On Tue, Oct 22, 2019 at 8:30 PM Vinod K Chandran via Digitalmars-d-learn wrote: > > On Tuesday, 22 October 2019 at 17:38:58 UTC, Adam D. Ruppe wrote: > > On Tuesday, 22 October 2019 at 17:34:51 UTC, Vinod K Chandran > > wrote: > >> Hi all, > >> I am new to D. But some fair experience with vb.net. I was > >> playing with D classes. I wrote a class in a D file. > >> The file name is "classFile.d" > > > > did you compile with dmd -i or list both files on the dmd > > command line? > > Thanks for the reply. Nope. I just typed this code in VS Code and > hit the run button. Thats all. i think this cmd business will be > difficult for me. You should use dub. You will probably need it anyway in the future. VS Code have nice plugins to work with D you can install D Language utility extension pack
Re: undefined symbol: _D3std7variant...
On Tue, Oct 22, 2019 at 2:20 PM Andrey via Digitalmars-d-learn wrote: > > Hello, > During compilation on linking stage I get strange errors (LDC): > lld-link: error: undefined symbol: > _D3std7variant__T8VariantNVmi56TSQBf8typecons__T5TupleTAyuTSQCgQCf__TQCaVmi32TSQCzQBu__TQBoTAQBmTQBqZQCbTQnTQCbZQDrZQCqTQBcTQCrZQEh4typeMxFNbNdNeZC8TypeInfo > >>> referenced by E:\Programs\LDC2\import\std\variant.d:753 > >>> > >>> .dub\obj\builder.obj:(_D3std7variant__T8VariantNVmi56TSQBf8typecons__T5TupleTAyuTSQCgQCf__TQCaVmi32TSQCzQBu__TQBoTAQBmTQBqZQCbTQnTQCbZQDrZQCqTQBcTQCrZQEh__T4peekTQDhZQkMNgFNdZPNgAyu) > >>>referenced by > >>> E:\Programs\LDC2\import\std\variant.d:753 > >>> > >>> .dub\obj\builder.obj:(_D3std7variant__T8VariantNVmi56TSQBf8typecons__T5TupleTAyuTSQCgQCf__TQCaVmi32TSQCzQBu__TQBoTAQBmTQBqZQCbTQnTQCbZQDrZQCqTQBcTQCrZQEh__T4peekTQBwZQkMNgFNdZPNgAAyu) > >>> referenced by > >>> E:\Programs\LDC2\import\std\variant.d:820 > >>> > >>> .dub\obj\builder.obj:(_D3std7variant__T8VariantNVmi56TSQBf8typecons__T5TupleTAyuTSQCgQCf__TQCaVmi32TSQCzQBu__TQBoTAQBmTQBqZQCbTQnTQCbZQDrZQCqTQBcTQCrZQEh__T3getTQEdZQjMNgFNdZNgSQFxQEs__TQEmTQEjTQEjZQEy) > > How to solve? > This is the first time when linking fails on Phobos library. Have you try to clean all caches? Try to remove .dub folder
Re: D for sciencetific scripting / rapid protoryping
On Tue, Oct 22, 2019 at 10:25 AM Prokop Hapala via Digitalmars-d-learn wrote: > > ... > > Also where is RDMD in the equation? I really like the idea run > binary programs like: > > #!/usr/bin/env rdmd > import std.stdio; > void main(){ > writeln("Hello, world!"); > } > > But I cannot find any documentation how to use rdmd with any > libraries/dependencies and dub.json ? Not even statically linked, > not to say dynamic. > You can't use rdmd with dub, but for simple scripts you can use dub directly: https://dub.pm/advanced_usage.html
Re: D for sciencetific scripting / rapid protoryping
On Tue, Oct 22, 2019 at 8:00 AM Prokop Hapala via Digitalmars-d-learn wrote: > > I'm examining the possibility to move from Python+C/C++ to D or > Python+D. I read > (https://wiki.dlang.org/Programming_in_D_for_Python_Programmers) > and > (https://jackstouffer.com/blog/nd_slice.html), where is mentioned > PyD, Mir-algorithm, all seems very promising. But I did not test > it yet. >... You should try to use https://github.com/BindBC/bindbc-opengl and https://github.com/BindBC/bindbc-sdl. There seems to be an issue with derelict packages (mainly with the gl3 one) And as far as I know derelict should be replaced by bindbc anyway in future. And if you plan to have *.so libs you should add "targetType" : "dynamicLibrary", to you dub.json
Re: How can I make a program which uses all cores and 100% of cpu power?
On Fri, Oct 11, 2019 at 6:58 AM Daniel Kozak wrote: > > so can stress your CPU. can't
Re: How can I make a program which uses all cores and 100% of cpu power?
On Fri, Oct 11, 2019 at 2:45 AM Murilo via Digitalmars-d-learn wrote: > > I have started working with neural networks and for that I need a > lot of computing power but the programs I make only use around > 30% of the cpu, or at least that is what Task Manager tells me. > How can I make it use all 4 cores of my AMD FX-4300 and how can I > make it use 100% of it? You should use minimally same amount of threads as you have cores. So in your case 4 or even more. Than you should buy a new CPU if you really need a lot of computing power :). Other issue can be using blocking IO, so your threads are in idle, so can stress your CPU.
Re: D man pages
On Thursday, 10 October 2019 at 19:26:36 UTC, Daniel Kozak wrote: On Thursday, 10 October 2019 at 19:25:22 UTC, Daniel Kozak wrote: On Thursday, 10 October 2019 at 19:21:06 UTC, Daniel Kozak wrote: On Thursday, 10 October 2019 at 19:19:42 UTC, Daniel Kozak wrote: On Thursday, 10 October 2019 at 18:52:32 UTC, Jarek wrote: On Monday, 23 September 2019 at 12:31:16 UTC, Adam D. Ruppe wrote: [...] Hello, thanks for reply. This is my first dlang work: import std.stdio; import std.conv; import core.sys.posix.dirent; [...] You should use fromStringZ: https://dlang.org/phobos/std_string.html#.fromStringz stdout.writeln("Subdir: ", ent.d_name.fromStringz); One more time :) stdout.writeln("Subdir: ", ent.d_name.ptr.fromStringz); and to!string works too: ent.d_name.ptr.to!string and there is a more D idiomatic version: import std.stdio; import std.algorithm; import std.file; import std.path; int main() { try { auto dFiles = dirEntries("/proc", SpanMode.shallow) .filter!(f => f.isDir) .each!((a){writefln("Subdir: %s", a.baseName);}); } catch (FileException fe) { stderr.writeln(fe.msg); return 1; } return 0; }
Re: D man pages
On Thursday, 10 October 2019 at 19:21:06 UTC, Daniel Kozak wrote: On Thursday, 10 October 2019 at 19:19:42 UTC, Daniel Kozak wrote: On Thursday, 10 October 2019 at 18:52:32 UTC, Jarek wrote: On Monday, 23 September 2019 at 12:31:16 UTC, Adam D. Ruppe wrote: [...] Hello, thanks for reply. This is my first dlang work: import std.stdio; import std.conv; import core.sys.posix.dirent; [...] You should use fromStringZ: https://dlang.org/phobos/std_string.html#.fromStringz stdout.writeln("Subdir: ", ent.d_name.fromStringz); One more time :) stdout.writeln("Subdir: ", ent.d_name.ptr.fromStringz);