Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?
On Sunday, 8 September 2024 at 22:01:10 UTC, WraithGlade wrote: Basically, I want there to be a way to print both an expression and its value but to only have to write the expression once (which also aids refactoring). Such a feature is extremely useful for faster print-based debugging. [...] I want to just be able to write this: ``` show!(1 + 2) ``` Try this: ``` import core.interpolation; void show(Args...)(InterpolationHeader hdr, Args args, InterpolationFooter ftr) { import std.stdio; foreach(arg; args) { static if(is(typeof(arg) == InterpolatedExpression!code, string code)) write(code); else static if(is(typeof(arg) == InterpolatedLiteral!str, string str)) write(str); else write(" = ", arg); } writeln(); } ``` Used like: ``` void main() { int a = 5, b = 22; show(i`$(a), $(b), $(a + b)`); } ``` Output: a = 5, b = 22, a + b = 27 You can show as many expressions as you want in there, each $() thing is expanded to `code inside = result`. So show(i"$(1 + 2)"); // prints 1 + 2 = 3 The interpolated sequence syntax makes it a bit heavier: that `i"$( )"` around it is required here, but it works anyway.
Re: Deriving a struct from another one via template: Easy way to propagate UDAs?
On Saturday, 16 March 2024 at 20:34:57 UTC, Inkrementator wrote: Nice. Btw I vaguely remember you also wrote about how and why to reduce the usage string mixins, with some real example of alternative techniques you used go to the main page: http://dpldocs.info/this-week-in-d/Blog.html and use ctrl+f and hope i said it in the summary lol but the two that pop up there are: http://dpldocs.info/this-week-in-d/Blog.Posted_2022_12_26.html#more-mixin-techniques and https://forum.dlang.org/post/fbcltjuysmjrxmebe...@forum.dlang.org The general rule is to try to use the local name inside the string instead of concatenating its result, and remember the built in compiler-tuple - which is what __traits(getAttributes) and the parameters reflection and other things - can be used directly in a lot of places, you can very often substitute one of those for a value and it will put it in for you. I encourage you to experiment with plugging these things directly in at the use site and seeing what happens before falling back to strings. fyi don't really follow this forum anymore, you got a bit lucky that i popped in for the dconf online link, so i might not see any further replies to this.
Re: Deriving a struct from another one via template: Easy way to propagate UDAs?
On Thursday, 14 March 2024 at 23:19:37 UTC, Inkrementator wrote: * Is UDA propagation possible without string mixins? @(__traits(getAttributes, thingYouWantToForward)) void yourNewThing() {} * Are template mixins vulnerable to name collisions? http://dpldocs.info/this-week-in-d/Blog.Posted_2020_01_20.html#understanding-mixin-templates
Re: Non-blocking keyboard input
On Wednesday, 27 December 2023 at 05:07:04 UTC, Joe wrote: ??? Surely there there is a one liner library solution for this? It is not one line because it needs a bit of setup (and teardown, but the objects' destructors do that for you) but it is close: http://arsd-official.dpldocs.info/arsd.terminal.html#single-key `input.getch` waits for a single line, but you can use `if(input.kbhit())` to see if it would block before calling it. This shouldn't be hard... yet it is. Better be careful, the mods are out in force deleting posts this week that tell the hard truth. But yeah, the stdlib in D has very little activity: https://github.com/dlang/phobos/graphs/contributors? So you can't expect much from it. My arsd libs provide a broad set of functionality missing from it: stuff like this terminal/console stuff, window creation, basic guis, web servers, etc. If you want to try them, you can use it from the dub system, but I recommend just `git clone https://github.com/adamdruppe/arsd.git` in your working directory then import what you want and use `dmd -i` to automatically include them in the build.
Re: SIGSEGV (Segmentation Fault) upon setting character in char array (object member var)
On Tuesday, 19 December 2023 at 13:10:40 UTC, John Kiro wrote: class Test { static enum MAX = 10; uint index = 0; auto intArray = new int[MAX]; auto charArray = new char[MAX]; This is run at compile time, and the compiler treats any char array at compile time as an immutable string literal when it crosses the barrier into run time. Moreover, this would be a static instance of the initial array; the default reference is shared across all objects created (so if you modify intArray then `new` another object, you'll see the modified intArray!). You almost never want to assign arrays or objects at compile time like this in a class definition; use constructors instead. I think the `new char[]` thing being immutable in runtime is a compiler bug, it makes it immutable but it is still typed as mutable in the type system. but this whole static init thing is probably not what you want anyway.
Re: Operator "+=" overloading for class?
On Sunday, 17 December 2023 at 04:13:20 UTC, Ki Rill wrote: auto opOpAssign(string op)(in ElementType rhs) { mixin("return this" ~ op ~ "rhs;"); } ``` check what `op` is. pretty sure it is "+" not "+=" so your element isnt' saved anywhere. also a bit iffy there isn't a member here to work on
Re: Is it possible to set/override the name of the source file when piping it into DMD via stdin?
On Wednesday, 13 December 2023 at 19:37:09 UTC, Siarhei Siamashka wrote: Now I'm curious. Is it possible to somehow communicate the real source file name to `dmd`, so that it shows up in the error log instead of "__stdin.d"? the sequence `#line "filename.d" 1` at the top of the thing might do what you need. https://dlang.org/spec/lex.html#special-token-sequence might also suggest putting a `module` declaration in the file.
Re: question
On Wednesday, 13 December 2023 at 12:49:14 UTC, fred wrote: a bug ? It helps if you explain what you're talking about so we don't have to guess. I tried the code on my computer and it worked fine. But then figuring, you must be saying something doesn't work right, I tried it on another compiler and saw it endlessly loop. So it ended using my dmd 2.098, looped on my dmd 2.105 but this is actually just coincidence. Consider this: --- void s2() { shared(bool) isDone = false; spawn(&w2, &isDone); Thread.sleep(400.msecs); w("done"); isDone = true; } --- The variable `isDone` is temporary; as a local variable, it ceases to exist when s2 returns. So when w2 tries to check if it is done or not, it takes a bit of luck for the memory to still be the same value as it was; it has likely been recycled or otherwise cleared by then. You need to keep the variable alive until *both* threads are done with it, either by doing some fancy synchronization between the threads or just letting the garbage collector manage the shared variable: ``` void s2() { // let the GC do it shared(bool)* isDone = new shared bool; spawn(&w2, isDone); Thread.sleep(400.msecs); w("done"); *isDone = true; } ```
Re: union default initialization values
On Tuesday, 5 December 2023 at 19:24:51 UTC, confuzzled wrote: Given the following union union F { double x; struct { ulong lo; ulong hi; } } The default value of this would be `double.init`, since the first member of the union is a `double`, which is a kind of NaN. This is non-zero. You can use `double x = 0;` to specify you want it to be zero initialized. fp.x.writefln!"%20.98f"; // Also, why is precision completely lost after 16 digits (18 if I change the type of x to real)? idk about this.
Re: struct initializer
On Friday, 1 December 2023 at 13:02:06 UTC, Dom DiSc wrote: Either allow it for all initializations, or get rid of it, like DIP 1031 suggested. I thought the decision actually was made to just get rid of it.
Re: 'typeof' question
On Tuesday, 28 November 2023 at 18:41:49 UTC, DLearner wrote: A* A_Ptr; struct B { int BFld2; typeof(A_Ptr)[0..($-1)] ASUB; // Idea is ASUB of type A, from A_Ptr of type A*. I think what you really want is typeof(*A_Ptr) ASUB; the typeof thing returns the type you'd get from the code inside
Re: Why this compiles?
On Sunday, 26 November 2023 at 21:45:21 UTC, Antonio wrote: In this example, ```a``` and ```b``` vars are not of the same type and don't implement the same interface. **why ```assert(a==b)``` compiles?** They're both subclasses of Object and inherit a generic opEquals from that base.
Re: mixin under -betterC
On Thursday, 23 November 2023 at 16:33:52 UTC, DLearner wrote: string mxnTest(string strVar1, string strVar2) { return `(int Var1, int Var2) { if (Var1 > Var2) { return true; } else { return false; } }(` ~ strVar1 ~ `,` ~ strVar2 ~ `)`; } ``` This function exists at runtime. Another module could, in theory, import it and call it. A shared library could, in theory, export it. You used it at compile time, but the function is available for other users too. betterC doesn't know the difference between theory and practice.
Re: under gdb: received signal SIG34, Real-time event 34.; received signal SIG35, Real-time event 35
On Tuesday, 14 November 2023 at 21:31:39 UTC, mw wrote: handle SIGUSR1 noprint handle SIGUSR2 noprint These are what the GC used to use to stop/start threads. received signal SIG34, Real-time event 34. received signal SIG35, Real-time event 35. And this is what it uses now. druntime just replaced usr1/2 with rt34/35 to lessen the likelyhood of conflicts with other libraries.
Re: D: How do I pipe (|) through three programs using std.process?
On Sunday, 12 November 2023 at 13:39:25 UTC, BoQsc wrote: However the question of why `spawnProcess(["find", "string to find"]` is not working and produces error is still unresolved. spawnProcess always encodes its arguments in a very specific way and the receiving programs are not always compatible with that thing. A Windows process does not take an array of args, but rather a single string command line. spawnProcess tries to turn the unix-style array into a single string that can then be turned back into arguments by the receiving program. But it makes a lot of assumptions in how that happens that just don't always match reality.
Re: why remove octal literal support?
On Friday, 3 November 2023 at 15:07:41 UTC, d007 wrote: dlang is know for compile speed, but in reality d project compile slow because so much ctfe and tempalte. Some ctfe and templates are slow. Usually larger functions or array/string append loops end up being to blame. Octal literals don't really matter either way because they're so small.
Re: Keyword "package" prevents from importing a package module "package.d"
On Friday, 3 November 2023 at 00:19:48 UTC, Andrey Zherikov wrote: Is there any guide how one can refactor single-module package into multi-module package with distinction between public and private modules? Call the modules literally anything else and it works better. So say you have module foo.bar. You could keep that and put your multiple modules in a different thing like foo.bar_parts.part and foo.bar_parts.part2. This maintains compatibility on the user side; if they were previously using foo.bar, things keep working for them. Or, you could keep everything under foo.bar, but add a foo.bar.all that provides the old api. Users would have to adjust their imports to say `import foo.bar.all;` instead. This has more potential for transition breakage, but it keeps the new modules under the old namespace. I recommend option 1: having the new foo.bar_parts where the implementation actually goes. (Or you could call it whatever you want.) This avoids the whole package.d thing while still letting you and your user arrange modules how you like. You might also have a thing like `foo.bar_implementation` which is not intended for public use.
Re: Keyword "package" prevents from importing a package module "package.d"
On Thursday, 2 November 2023 at 19:30:58 UTC, Jonathan M Davis wrote: The entire reason that it was added to the language was to be able to split up existing modules without breaking code. And it does that well. No, it doesn't do that well at all. In fact, it does that so extremely poorly that (as you might recall) there were a very large number of support requests shortly after Phobos started using it about broken builds, since it would keep the old file and the new file when you updated and this stupid, idiotic design can't handle that situation. This only subsided because enough time has passed that nobody tries using it to break up existing modules anymore. It is just a *terrible* design that never should have passed review. It is randomly inconsistent with the rest of the language and this manifests as several bugs. (including but not limited to: https://issues.dlang.org/show_bug.cgi?id=14687 doesn't work with .di https://issues.dlang.org/show_bug.cgi?id=17699 breaks if you try to use it for its intended purpose https://issues.dlang.org/show_bug.cgi?id=20563 error messages hit random problems all-at-once vs separate compilation of package leads to inconsistent reflection results im sure the list went on if i spent a few more minutes looking for my archives) package.d is indeed completely unnecessary for creating a module that publicly imports other modules in order to be able to import a single module and get several modules. Yeah, it is a terrible feature that is poorly designed, hackily implemented, and serves no legitimate use case.
Re: Keyword "package" prevents from importing a package module "package.d"
On Thursday, 2 November 2023 at 12:52:35 UTC, BoQsc wrote: Therefore the need to import `package.d` is needed and I can't see a solution, which means tbh package.d should never be used. It is a poorly designed, buggy misfeature of the language with plenty of better working alternatives (it is no different than making a `module yourthing.all;` people can import execpt with more limitations and bugs.)
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. Make an empty file called object.d in your build directory then compile with dmd and it won't emit much of anything in there. I've run dmd programs on bare metal x86 many times in the past (but not recently, i have so many other things to do) including for one section of my "D Cookbook" almost ten years ago now (it is easier now than it used to be, back then you had to have something in object.d, now an empty one is mostly permitted)
Re: Straight Forward Arrays
On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: When D creates a dynamic array, it returns a slice. Functions that add or remove elements begin by asking the memory manager for the dynamic array that the slice belongs to. Only then can they go on and add elements. Why is this a problem? It is convenient and usually works fine. I use the built in arrays very very often for a lot of things.
Re: Is this a ctfe bugs ? ref scope const(ubyte)[32]
On Wednesday, 6 September 2023 at 12:04:40 UTC, d007 wrote: extern(C) int test(ref scope const(ubyte)[32] b); extern(C) int test(ref scope const(ubyte[32]) b); These are the same thing since the ref cannot be rebound anyway; a static array just is its contents.
Re: parallel threads stalls until all thread batches are finished.
On Wednesday, 23 August 2023 at 13:03:36 UTC, Joe wrote: to download files from the internet. Are they particularly big files? You might consider using one of the other libs that does it all in one thread. (i ask about size cuz mine ive never tested doing big files at once, i usually use it for smaller things, but i think it can do it) The reason why this causes me problems is that the downloaded files, which are cashed to a temporary file, stick around and do not free up space(think of it just as using memory) and this can cause some problems some of the time. this is why im a lil worried about my thing, like do they have to be temporary files or can it be memory that is recycled?
Re: How to create an .exe without execute the terminal in Windows?
On Saturday, 12 August 2023 at 23:13:39 UTC, thePengüin wrote: I would know how to make some this but in Dlang: best way is to use the linker switch. On Win32, you can pass -L/subsystem:windows if you don't want a console to be automatically allocated. Please note when compiling on Win64, you need to explicitly list -Lgdi32.lib -Luser32.lib on the build command. If you want the Windows subsystem too, use -L/subsystem:windows -L/entry:mainCRTStartup. If using ldc instead of dmd, use -L/entry:wmainCRTStartup instead of mainCRTStartup; note the "w". import core.sys.windows.windows; void hideConsoleWindow() { ShowWindow(GetConsoleWindow(),SW_HIDE); } ``` woudl also work.
Re: pragma lib doesn't support static libraries?
On Sunday, 30 July 2023 at 05:53:55 UTC, Mike Parker wrote: And I'm unaware of any mechanism for embedding static library names in an object file for a linker to read later. There is a mechanism on Windows, so it tends to work there, but yeah no luck on the other platforms.
Re: Unicode in strings
On Thursday, 27 July 2023 at 22:15:47 UTC, Cecil Ward wrote: How do I get a wstring or dstring with a code point of 0xA0 in it ? note that you don't need wstring and dstring to express all unicode strings.
Re: array index out of bound may not throw exception?
On Friday, 21 July 2023 at 21:27:45 UTC, mw wrote: However, I just debugged a case, where out of bound array index didn't throw exception, and just hang the thread Uncaught exceptions in a thread terminate that thread and are reported when you call the `join` method of the thread. I think you can still get a debugger to break on them but im not entirely sure, it is a different switch than in the main thread i think. But you might want to do your own try/catch block around a thread to report it differently if you have a better way for your application.
Re: Redirecting standard streams in Windows
On Tuesday, 18 July 2023 at 23:52:06 UTC, Alexander Zhirov wrote: PS C:\dlang\test> cat .\stderr.txt How does the cat program know what the encoding of the file is? Try opening it in notepad or something and specifying the encoding. I betcha it is perfectly fine.
Re: Redirecting standard streams in Windows
On Tuesday, 18 July 2023 at 21:31:54 UTC, Alexander Zhirov wrote: HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE); WriteConsoleW(h_stderr, str.ptr, cast(DWORD)str.length, NULL, NULL); If you checked the return value of this call, you'd find it fails since WriteConsole only works if the output is, in fact, a console. You need to use WriteFile when it is redirected, which you can detect with GetFileType to see if it is a character device or not.
Re: Inlined functions and their original bodies - bloat
On Sunday, 9 July 2023 at 18:05:48 UTC, Cecil Ward wrote: This is with full -O3 optimisation try -fvisibility=hidden -release sux btw
Re: Reading an environment variable value
On Thursday, 29 June 2023 at 18:47:48 UTC, Josh Holtrop wrote: $ ldc2 -of environment environment.d Since you named the file `environment.d` and didn't use an explicit `module name.thing;` declaration, the compiler assumes it should match the filename. So it injects an implicit `module environment;` to the top of the file. Now when you mention `environment`, it uses *that* name instead of the imported name, so it thinks you are trying to pass it the module called environment instead of the object. If you add `module yourapp.environment;` or something to the top it'd fix it (unless you tried to use something called `yourapp`, then the name might conflict again!) or rename the file.
Re: pragma msg field name?
On Tuesday, 27 June 2023 at 22:20:22 UTC, Chris Katko wrote: pragma(msg, t.stringof); // does not see any new fields! D's declarations are all order-independent, in theory those foreaches are done simultaneously, so it is kinda a race condition. In practice, the compiler does them in two passes but both based on the same initial state. Adding stuff and then reflecting over the stuff you add must be done as explicit steps on the outside, like you can make a `struct step1 {}` then `alias step2 = transform!step1;` then `alias step3 = transform_again!step2;` or something.
Re: pragma msg field name?
On Tuesday, 27 June 2023 at 04:25:13 UTC, Chris Katko wrote: How do I get just the field name? __traits(identifier, field) And why does it think this is a run-time value? It is the same as if you wrote `Class.field`
Re: Mixin and compile-time functions for code generation
On Saturday, 24 June 2023 at 17:31:31 UTC, Cecil Ward wrote: Can I get mixin whatever to do this for me? Mixin with a function that runs at compile-time and creates the required source ? have you tried it?
Re: Union with bits ?
On Wednesday, 14 June 2023 at 08:51:19 UTC, Rene Zwanenburg wrote: You can do something like this if you don't mind compiling with -preview=bitfields: That doesn't do what you think it does. There's no guarantee the bits will actually line up with the status byte. The best way to do what the OP wants is to add property getters and setters to the struct with the ubyte that masks the member.
Re: How get struct value by member name string ?
On Monday, 29 May 2023 at 09:35:11 UTC, John Xu wrote: Error: variable `column` cannot be read at compile time you should generally getMember on a variable T t; __traits(getMember, t, "name") like that, that's as if you wrote t.name
Re: Complicated @property access only works when I write an extra parenthesis "()"
On Friday, 26 May 2023 at 21:00:20 UTC, realhet wrote: Only the extra () let it compile successfuly. No way to fix it. If the function takes an extra argument you can kinda trick it but for zero arg function pointer return from a property it is just plain broken and has been the whole time. Don't expect it to ever be fixed.
Re: Given an object, how to call an alias to a member function on it?
On Tuesday, 2 May 2023 at 13:57:23 UTC, Steven Schveighoffer wrote: Isn't that what `__traits(child)` is for? https://dlang.org/spec/traits.html#child Yes, __traits(child, object, method_alias)(args) is the way to do it.
Re: std.socket tutorials? examples?
On Sunday, 30 April 2023 at 22:10:31 UTC, Cecil Ward wrote: How do we wait for an ‘or’ of multiple asynchronous events in this kind of code? You can set a timeout value for Socket.select, but Phobos isn't going to help you with anything other than sockets and timeouts (despite the fact the underlying operating systems can, in fact, do it). There's a few other libs that can help with this, including one I'm aiming to release some time in May, or vibe.d has its own ways of doing it, among others. You can also import core.sys.stuff and call the OS functions without a middle man. But the D stdlib is quite underpowered when it comes to these things. Socket.select is ok but just the basics.
Re: A Programmer's Dilema: juggling with C, BetterC, D, Macros and Cross Compiling, etc.
On Sunday, 30 April 2023 at 17:51:15 UTC, Eric P626 wrote: * Use D for everything, no C compatibility. This is a false dilemma: D has full C compatibility.
Re: std.socket tutorials? examples?
On Saturday, 29 April 2023 at 10:56:46 UTC, Jan Allersma wrote: auto clientResult = Socket.select(clientSet, null, null); There's probably nothing in clientSet, so it is waiting for nothing you almost always want to have just one call to select in the program, not two, the whole point is to combine checks. I wrote a thing you might want to read too: http://dpldocs.info/this-week-in-d/Blog.Posted_2019_11_11.html#sockets-tutorial
Re: DlangUI Layout Justification
On Friday, 7 April 2023 at 15:52:02 UTC, Ali Çehreli wrote: I don't know how relevant it is but there is also Hipreme Engine that supports Android: I think the question is if you are doing games vs doing other applications. There's some overlap between game and gui, but not actually that much. Both draw things to the screen and accept user input... but even these two things they tend to do quite differently. Guis tend to favor responsiveness. I know, there's people saying "games have to be even more responsive!" but let me finish: games tend to favor *predictability*. (Some exceptions of course.) A gui will want to respond to input as soon as it can. If I can press a key and see a response on screen in one millisecond, great! Or, on the other hand, if it takes 200 ms... not so great, but I can maybe still live with it. A game will want to respond to input *on a strict schedule*. Responding too fast might break its rules - the world physics aren't infinitely precise and are designed with certain limits in mind. It might also give an unfair advantage to some players over others. Responding too slowly means players will miss their jumps and other frustrating feelings of lack of control. But notice that if something is *predictably* slow, players will get used to it - a lot of things deliberately have some delay according to the rules of the game. Something is only ever "too slow" if it is inconsistently slow. Thus it is common for games to poll input on a timer, whereas guis wait for input on events. Both games and guis draw, but games tend to draw many active things at once, showing a game world that is changing with the passage of time, and guis tend to draw one difference at a time, in response to either a user input or some request finishing. Sure, some guis will do large animations that are similar to how a game works, but these are exceptional circumstances; most the time, a game is drawing to keep the screen in sync with the state of the game world and most the time a gui is idle, waiting for something to happen. That's just the differences in functionality where they overlap. Other things are very different. Games often (but not always) value predictable latency audio, to maintain its a/v sync. Guis, being idle more often than not, can typically defer opening an audio device until they need it, then close it as soon as that effect is done. Most games contain themselves to one large, multi-role window. Guis often use several, with varying roles including temporary single-purpose windows (e.g. popup menus and toolips). Guis need to implement a variety of input patterns that games rarely care about - interprocess drag and drop, copy and paste, ui automation and accessibility apis; guis are more often part of a bigger cooperative whole than just on their own. Games just want to take whatever global input they get into their own self-contained game world, and games are more likely to care about joysticks and gamepads than guis. One library can help with both games and guis but it is unlikely to be a complete solution for either, certainly not both.
Re: Why are globals set to tls by default? and why is fast code ugly by default?
On Saturday, 1 April 2023 at 13:11:46 UTC, Guillaume Piolat wrote: TLS could be explicit and we wouldn't need a -vtls flag. Yeah, I think what we should do is make each thing be explicitly marked. When I want tls, I tend to comment that it was intentional anyway to make it clear I didn't just forget to put a shared note on the static.
Re: Read a text file at once for regex searching
On Monday, 20 March 2023 at 17:42:17 UTC, Paul wrote: Do we have some such function in our std library? Try static import std.file; string s = std.file.readText("filename.txt"); http://phobos.dpldocs.info/std.file.readText.html
Re: Code organization, dub, etc.
On Monday, 13 March 2023 at 13:20:21 UTC, Joe wrote: Yeah, it seems like it's *only* for libraries (and a few single-exe utilities). Looking at code.dlang.org, under "Stand-alone applications/Server software", the top rated item is "handy-httpd" which according to its dub.json builds a library! I'm not particularly interested in defending dub - i consider it a useless piece of crap that I only suffer through cuz some users demanded it - but you can use the subpackage thing to build multiple executables. My thing here does it: https://code.dlang.org/packages/adr-terminalemulator relevant config code here: https://github.com/adamdruppe/terminal-emulator/blob/master/dub.json#L31 So the mactabs exe and the attach exe and so on are all a bit different programs you can run from the code.
Re: 'auto' keyword
On Sunday, 12 March 2023 at 13:07:58 UTC, DLearner wrote: Is it correct that this _single_ keyword is used to indicate _two_ quite different things: No, it only actually does #2 in your thing. The type is optional meaning *any* storage class will work for type inference. `auto` is not special in variable declarations. (it can be special in other contexts though). auto A = 5; static A = 5; const A = 5; all the same.
Re: Desiring bool any_key_pressed()
On Friday, 3 March 2023 at 03:38:56 UTC, Daren Scot Wilson wrote: Here is a very simple version of the program I'm working on. Is there a way to write is_any_key_pressed() that doesn't block, doesn't require the Enter key, and doesn't require dragging in any complex libraries or dealing with low-level stuff like ioctl()? You have to do something since the normal behavior is the operating system holds on to the input until the user presses enter. You must tell it not to do that somehow. My terminal.d lib at least stands alone (for now, the next version will probably require two files instead of just one) and has things for this: http://arsd-official.dpldocs.info/arsd.terminal.html#single-key It is `input.kbhit()` just to test without getting the thing. Though... testing for input like this is a kinda iffy thing to do too, you might be able to adjust the program to be more event driven. Anyway, it is the "RealTimeConsoleInput" object in the library that tells the OS to stop buffering and send things directly. Its code isn't too complex - calls to tcgetattr and tcsetattr and similar for Windows - but still.
Re: Can't load FreeImage.dll with Windows
On Friday, 3 March 2023 at 19:07:14 UTC, WhatMeWorry wrote: loadFreeImage(`c:\Users\Admin\Downloads\FreeImage3180Win32Win64\FreeImage\Dist\x64\FreeImage.dll`); is your application build 64 bit too?
Re: How to get only the field name from an alias?
On Tuesday, 21 February 2023 at 02:41:34 UTC, Elfstone wrote: apparently F.stringof You almost never want to use .stringof, instead try __traits(identifier, F) and see what it gives you. Alternatively, loop over __traits(allMembers) which gives you the member names and pass that down. You can pull all the info out of allMembers with getMember and then other things to filter it out.
Re: Non-ugly ways to implement a 'static' class or namespace?
On Saturday, 18 February 2023 at 21:23:24 UTC, ProtectAndHide wrote: The more I look at D, the more I like C++. cya
Re: Want a module to import from a sister directork; How?
On Tuesday, 14 February 2023 at 21:23:26 UTC, ryuukk_ wrote: module name must correspond to its path this is not true.
Re: Non-ugly ways to implement a 'static' class or namespace?
On Thursday, 9 February 2023 at 13:00:04 UTC, thebluepandabear wrote: For my school I am commissioned to create many types of software. I tried to have a look at some of the gui kits in D but there was no tutorial for how to use them and they seemed as if they are lacking features in comparison to Qt/JavaFX. So your objection is one of newbie documentation. That's fair. Qt I always thought had nice docs, they're hard to beat. I've been slowly adding more to my stuff but it is a slow process. idk about features though, you saying "seemed" means you probably don't even actually know what they have so that's not as actionable.
Re: Non-ugly ways to implement a 'static' class or namespace?
On Thursday, 9 February 2023 at 12:31:03 UTC, thebluepandabear wrote: I am actually taking a computer science class and I need to create desktop apps to pass and get through school. This is pretty easy in D. Like what specific kind of desktop app?
Re: betterC DLL in Windows
On Saturday, 4 February 2023 at 18:40:51 UTC, Tamas wrote: I do take your word for it, but now I have to re-evaluate my expectations towards D and perhaps use it for another project. I've got most of my project working in C already, but I was hoping to add some safety and better readability/managability by using some of the convenient features D offers over C. This is achieved without the betterC switch, and severely limited with it. Also, your words give me the impression that I cannot trust the documentation; which isn't a great start into the learning process. There's a lot of things described in the documentation that don't actually work. D can be an *extremely* productive language if you know which parts to focus on, but most the newer hyped features just don't deliver. The table of contents on the left side of the site is in roughly chronological order. The things near the top are pretty reliable, with a few exceptions (which are generally called out in the documentation if you read it carefully, like how the "static initialization of associative arrays" is "not yet implemented", or misuse of shared is "is not an error yet by default"). The things near the bottom are not reliable. The C++ interface works in some cases but you aren't likely to get far using it in any real world project; the C++ stdlib bindings are extremely minimal and Windows-only. The Objective-C interface works beautifully on dmd which cannot target the new Apple devices. ldc can generate code for those arm chips, but the Objective-C interface is not implemented on ldc. The portability guide and named character entities are pretty much ok. The memory safety `@safe` stuff only actually works if you 1) opt into it in the functions and 2) opt into it on command line params. This is mentioned in the docs as a small note near the bottom. The design of @safe also allows several things that can escape it on certain systems. The ABI page is ok, but there are several bugs in the debug info output. I find it good enough but it can be annoying. The vector extensions work on dmd if you can piece together the magic but the other compilers do it differently. The betterC page has several falsehoods on it, including the misinformation that you need to use it to link into C applications. This is just 100% nonsense. It also claims nearly the full language remains available, but this is also simply false. Some of the things listed there can be made to work with a bunch of code, but many things just plain don't work, even if you add the small amounts of code necessary to enable them. For example, interfaces don't work, even if you implement your own dynamic cast function. It just doesn't let them link. It claims constructors and destructors work, which is true, unless they're `static`, in which case you get random errors. Delegates and lambdas work if you manage captured variables in your own functors, but otherwise are simply disabled, even if you had your own backing system. Even module imports can fail because betterC disables outputting the module data info, even if it would otherwise be required by language rules, despite it not using the druntime. Then importC only works for toy examples. Using two separate headers or modules will result in spurious compile errors (and bugs detailing how to address this have been closed WONTFIX), and there's several kinds of C apis it just doesn't support. And finally, the @live functions also only work in toy examples and the design is fundamentally limited to only direct function calls, no struct aggregation is supported at all. It is a complete dead end. On the other hand, if you avoid most the compiler switches and stick to the more solid features - "Interfacing to C" and above on the list, for the most part - you'll find D is a very capable conservative language.
Re: betterC DLL in Windows
On Saturday, 4 February 2023 at 19:49:41 UTC, bachmeier wrote: I'm not sure what Adam's getting at when he says "hopelessly broken" but it's basically a subset of D. You're almost guaranteed to hit some wall with it and have no solution. Some of these are bugs but some of them are by design; betterC is a set of arbitrary restrictions without much consistent reasoning behind them. For example, with dlls, you still have to deal with all the potential problems of C library version mismatches, but if you use any module that touches a D feature it is likely to compile but then fail to link when someone uses it! All pain, no gain.
Re: betterC DLL in Windows
On Saturday, 4 February 2023 at 18:11:05 UTC, Tamas wrote: Well, as I'm new to D this isn't something I have insight into. Then you'd probably be better off taking my word for it (or even trusting your own limited experience where things worked until you added the switch) and just not using -betterC switch. It is hopelessly broken, but thankfully, it also brings zero benefit, so simply not using it is a viable path forward. I mostly need interop with C libraries and D would only serve as a glue, so I don't really need several features like GC etc. Just don't call those functions and they won't hurt you, aside from adding ~200 KB of size to the dll. On the other hand, the -betterC switch is hurting you - as evidenced by your own attempt working until you added it. Perhaps, but this doesn't help me much. It is a very easy solution to your problem. It is up to you if you want to take it and continue on in productivity or keep suffering for no benefit (and you'll find more trouble the further you go using the broken, barely supported switch).
Re: betterC DLL in Windows
On Saturday, 4 February 2023 at 16:45:31 UTC, Tamas wrote: and they compile without `-betterC`, but fail with link errors when using the switch. then don't use the switch lol -betterC is barely supported and completely useless so better to just not use it. export extern (C) void main() mixin SimpleDllMain; No need to ever mix two mains together, the DllMain is the required one. error LNK2019: unresolved external symbol _D4core3sys7windows3dll18dll_process_attachFPvbZb referenced in function DllMain This is just betterC breaking the code.
Re: Which TOML package, or SDLang?
On Monday, 30 January 2023 at 15:37:56 UTC, Guillaume Piolat wrote: Why not XML? :) It has comments, you can use backslashes too. no kidding, xml is an underrated format.
Re: Non-ugly ways to implement a 'static' class or namespace?
On Monday, 23 January 2023 at 00:21:12 UTC, thebluepandabear wrote: there's nothing in the language currently that would 'force' the user Why do you hate freedom?
Re: How to write a library
On Saturday, 21 January 2023 at 22:53:19 UTC, Matt wrote: but what is the D equivalent to header files, and what do I have to do to prepare and use my library in another project? The most common and easiest thing in D is to just distribute the source files, the compiler can pull whatever it needs out of there. I almost never even build libraries separately, instead letting the compiler include them as-needed in the build.
Re: Is there a way to get a template’s parameters and constraints?
On Friday, 20 January 2023 at 17:15:31 UTC, Quirin Schroll wrote: Is there a trait (or a combination of traits) that gives me the constraints of a template? No, reflection over templates is very limited.
Re: D Static Array
On Sunday, 15 January 2023 at 14:23:59 UTC, Salih Dincer wrote: int[0] arr = 40; // ? The = 40 means fill all array entries with the number 40. The [0] means there are no array elements. So it filled all the 0 elements with the number 40. If it was like int[3] arr = 40, then arr[0], arr[1], and arr[2] would all be 40. In C99 and later C standards, an array size can be defined as 0 and it can include a feature called flexible array member (FAM) which is an array member without specifying its size This is not supported in D.
Re: Mixin helper help
On Saturday, 14 January 2023 at 18:57:21 UTC, John Chapman wrote: I wanted to remove the double braces in my static foreach (needed as I declared some aliases inside but since it creates a scope those new variables can't be referred to outside of it). Inside a function, you can often just use plain foreach instead of static foreach and simplify things. But it depends on the whole context. Where the helper thing helps a lot is outside functions, where normal foreach and double brace are both prohibited.
Re: Failed to archive JPEG (ArchiveMember): Invalid UTF-8 sequence (at index 1)
On Saturday, 14 January 2023 at 01:08:25 UTC, Ki Rill wrote: a JPEG image. member.expandedData(file.readText().dup().representation()); A jpeg image is not a text file. Read it with `std.file.read()` instead of `readText`. Then you can get rid of those useless dup.representation calls too.
Re: enum functions
On Sunday, 8 January 2023 at 18:42:58 UTC, Salih Dincer wrote: I'm wondering 2 things; firstly, does having an enum mean there is no auto-return? Or could it be CTFE? It means nothing. The keyword tells the parser a function is about to begin, which triggers return type inference (exactly the same as `auto`), but otherwise it is completely ignored.
Re: Error "Outer Function Context is Needed" when class declared in unittest
On Thursday, 5 January 2023 at 16:38:49 UTC, Vijay Nayar wrote: Does that class inherit the scope of the function it is inside, similar to how an inner class does with an outer class? yup. They can see the local variables from the function.
Re: Error "Outer Function Context is Needed" when class declared in unittest
On Thursday, 5 January 2023 at 13:27:23 UTC, Vijay Nayar wrote: Why is this error only found when declaring a class in the unittest? A unittest is just a special function, it can run code and have local variables. classes and structs declared inside it have access to those local contexts, which it calls the outer function context. Make the outer class `static` too to lift it out of this and your error should go away.
Re: Vibe.d MongoDB database connection
On Monday, 26 December 2022 at 21:32:51 UTC, eXodiquas wrote: I looked a bit closer into the problem and I found an issue in the vibe.d repository that states that the current version of vibe.d is not compatible with MongoDB version >= 5.1 the mongo driver in the standalone package shares some code with vibe's but handled this 5.1 thing a bit differently and *might* work idk i haven't tested on one that new https://code.dlang.org/packages/mongo-standalone
Re: [Win32 API] MessageBox Example without MSVCR120.dll dependency
On Sunday, 25 December 2022 at 18:30:12 UTC, BoQsc wrote: This is a working Hello World example without dependency on Microsoft C Runtime Library you might also consider using `-m32omf` switch to dmd which will make it bundle the old digital mars c lib. this is generally worse but since it is bundled it can be convenient.
Re: How to create a API server?
On Sunday, 18 December 2022 at 09:34:06 UTC, TTK Ciar wrote: Oops, wrong module!! I meant arsd.cgi, very sorry! Yes, http2.d is the client side for http, arsd.cgi implements the http server.
Re: _Symbols _with _leading _underscores
On Saturday, 17 December 2022 at 02:42:22 UTC, Paul wrote: Are the leading underscores significant, in general, in the D language? The code you linked is a copy/paste from some C runtime library code, where the leading __ is the convention to indicate it is part of the private platform implementation, which user code shouldn't use. This ensures no name conflicts. D has this rule too, you're actually not supposed to use __ prefixes in your own code either, since the compiler will use it for auto-generated names. But since it was a copy paste, I was too lazy to change it. A single leading _ is sometimes used by some programmers to indicate private members, but that's no special meaning in the language.
Re: arsd.jni
On Monday, 12 December 2022 at 11:17:47 UTC, jni wrote: It's good. But you did the java bindings by hand or is there a generator in arsd.jni for that too? It does it automatically. You compile jni.d with `-version=WithClassLoadSupport` and then write a main function that calls `jarToD("path/to/file.jar", "whatever.d.name", "output_directory", JavaTranslatorConfig(true, true, true));` Or something like that. It has been 3 years lol. But I put some docs in there too http://arsd-official.dpldocs.info/arsd.jni.jarToD.html http://arsd-official.dpldocs.info/arsd.jni.JavaTranslationConfig.html For the C .h files, I used the `dstep` program https://github.com/jacob-carlborg/dstep/ with a bit of hand edits after.
Re: arsd.jni
On Monday, 12 December 2022 at 01:19:23 UTC, jni wrote: The boilerplate is easy but Then the other part is a problem for me is the necessary other Java classes. They are not part of the NDK so the only way to load the jar is to use jni? Is that correct? I haven't updated this for a while,but I translated the whole api back in 2020 for my d_android package https://code.dlang.org/packages/d_android see for example: https://github.com/adamdruppe/d_android/blob/master/java_bindings/android/java/android/net/ConnectivityManager_d_interface.d (but be warned if you import these it can be very slow to compile, so just bringing only the classes you need can be much faster) I also translated the ndk headers to D back then: https://github.com/adamdruppe/d_android/tree/master/translated_headers/android/ndk But I never used android beyond hello world so i just don't know THAT much about it.
Re: arsd.jni
I don't know how to do much of anything on Android, but if you can post a small Java code example, I can suggest how to use it from D. You can bind many classes through the jni. The biggest limitation is you can't do callbacks or subclasses through android jni, so it is kinda limited for interactive components.
Re: Idiomatic D using GC as a library writer
On Sunday, 4 December 2022 at 22:46:52 UTC, Ali Çehreli wrote: That's way beyond my pay grade. Explain please. :) The reason that the GC stops threads right now is to ensure that something doesn't change in the middle of its analysis. Consider for example, the GC scans address 0 - 1000 and finds nothing. Then a running thread moves a reference from memory address 2200 down to address 800 while the GC is scanning 1000-2000. Then the GC scans 2000-3000, where the object used to be, but it isn't there anymore... and the GC has no clue it needs to scan address 800 again. It, never having seen the object, thinks the object is just dead and frees it. Then the thread tries to use the object, leading to a crash. The current implementation prevents this by stopping all threads. If nothing is running, nothing can move objects around while the GC is trying to find them. But, actually stopping everything requires 1) the GC knows which threads are there and has a way to stop them and 2) is overkill! All it really needs to do is prevent certain operations that might change the GC's analysis while it is running, like what happened in the example. It isn't important to stop numeric work, that won't change the GC. It isn't important to stop pointer reads (well not in D's gc anyway, there's some that do need to stop this) so it doesn't need to stop them either. Since what the GC cares about are pointer locations, it is possible to hook that specifically, which we call write barriers; they either block pointer writes or at least notify the GC about them. (And btw not all pointer writes need to be blocked either, just ones that would point to a different memory block. So things like slice iterations can also be allowed to continue. More on my blog http://dpldocs.info/this-week-in-d/Blog.Posted_2022_10_31.html#thoughts-on-pointer-barriers ) So what happens then: GC scans address 0 - 1000 and finds nothing. Then a running thread moves a reference from memory address 2200 down to address 800... which would trigger the write barrier. The thread isn't allowed to complete this operation until the GC is done. Notice that the GC didn't have to know about this thread ahead of time, since the running thread is responsible for communicating its intentions to the GC as it happens. (Essentially, the GC holds a mutex and all pointer writes in generated D code are synchronized on it, but there's various implementations.) Then the GC scans 2000-3000, and the object is still there since the write is paused! It doesn't free it. The GC finishes its work and releases the barriers. The thread now resumes and finishes the move, with the object still alive and well. No crash. This would be a concurrent GC, not stopping threads that are doing self-contained work, but it would also be more compatible with external threads, since no matter what the thread, it'd use that gc mutex barrier.
Re: Idiomatic D using GC as a library writer
On Sunday, 4 December 2022 at 21:55:52 UTC, Siarhei Siamashka wrote: Do you mean the top of the https://code.dlang.org/?sort=score&category=library list? Well, I was referring to the five that appear on the homepage, which shows silly instead of emsi containers. How do you know that they embrace GC? I looked at the projects. Except for that arsd-official thing, that's a big mystery to me, the code is completely unreadable. But vibe and dub use it pretty broadly. Unit-threaded and silly are test runners, which isn't even really a library (I find it weird that they are consistently at the top of the list), so much of them don't need the GC anyway, but you can still see that they use it without worry when they do want it like when building the test list with ~=. emsi-containers is built on the allocators thing so it works with or without gc (it works better without though as you learn if you try to use them.) Is it possible to filter packages in this list by @nogc or @safe compatibility? No. I do have an idea for it, searching for @nogc attributes or attached @nogc unittests, but I haven't gotten around to trying it.
Re: Idiomatic D using GC as a library writer
On Sunday, 4 December 2022 at 17:53:00 UTC, Adam D Ruppe wrote: Interesting... you know, maybe D's GC should formally expose a mutex that you can synchronize on for when it is running. .. or compile in write barriers. then it doesn't matter if the thread is unregistered, the write barrier will protect it as-needed!
Re: Idiomatic D using GC as a library writer
On Sunday, 4 December 2022 at 16:02:28 UTC, Ali Çehreli wrote: D's GC needed to stop the world, which meant it would have to know what threads were running. You can never be sure whether your D library function is being called from a thread you've known or whether the Java runtime (or other user code) just decided to start another thread. Interesting... you know, maybe D's GC should formally expose a mutex that you can synchronize on for when it is running. So you can cooperatively do this in the jni bridge or something. Might be worth considering. I've heard stories about similar things happening with C#.
Re: Idiomatic D using GC as a library writer
On Sunday, 4 December 2022 at 09:53:41 UTC, vushu wrote: What are your thoughts about using GC as a library writer? Do it. It is lots of gain for very little loss. If you wan't to include a library into your project aren't you more inclined to use a library which is gc free? No, GC free means the library is necessarily more complicated to use and will likely result in a buggier program. Since to get most exposure as a D library writer you kinda need to make it gc free right? All of the top 5 most popular libraries on code.dlang.org embrace the GC.
Re: How do you print all Unicode characters in a range - I want the subscripts, can't google a range of Unicode.
On Saturday, 3 December 2022 at 14:43:15 UTC, Adam D Ruppe wrote: The problem is just that writeln to the console is broken. You can either write to a function instead and load it in a text editor aaargh not to a "function" i meant to a "file". like auto f = File("test.txt", "wt"); f.writeln(s); then open test.txt and make sure it is opened in utf-8 mode.
Re: How do you print all Unicode characters in a range - I want the subscripts, can't google a range of Unicode.
On Friday, 2 December 2022 at 05:27:40 UTC, Daniel Donnelly, Jr. wrote: Doesn't work. The result I get is shit: The problem is just that writeln to the console is broken. You can either write to a function instead and load it in a text editor, or use a non-broken writeln like my terminal.d's ``` void main() { // using the same string... dstring s = ""; for (dchar i='ₐ'; i < 'ₜ'; i++) s ~= i; // this will output correctly import arsd.terminal; auto terminal = Terminal(ConsoleOutputMode.linear); terminal.writeln(s); // this will not import std.stdio; writeln(s); } ``` Screenshot output: http://arsdnet.net/dcode/writelnsux.png Now, while it outputs correctly, you'll still note a bunch of empty boxes. That's because the *font* I'm using doesn't include those characters. If you changed fonts there's a decent chance you can see those too.
Re: How do you print all Unicode characters in a range - I want the subscripts, can't google a range of Unicode.
On Saturday, 3 December 2022 at 14:43:15 UTC, Adam D Ruppe wrote: import arsd.terminal; oh yeah my module: can download direct and compile with your program https://github.com/adamdruppe/arsd/blob/master/terminal.d or it is also on dub https://code.dlang.org/packages/arsd-official%3Aterminal
Re: Why can't D store all UTF-8 code units in char type? (not really understanding explanation)
On Friday, 2 December 2022 at 21:26:40 UTC, rikki cattermole wrote: char is always UTF-8 codepoint and therefore exactly 1 byte. wchar is always UTF-16 codepoint and therefore exactly 2 bytes. dchar is always UTF-32 codepoint and therefore exactly 4 bytes; You mean "code unit". There's no such thing as a utf-8/16/32 codepoint. A codepoint is a more abstract concept that is encoded in one of the utf formats.
Re: Why can't D store all UTF-8 code units in char type? (not really understanding explanation)
On Friday, 2 December 2022 at 21:18:44 UTC, thebluepandabear wrote: It's his explanation as to why this code doesn't compile even though Ğ is a UTF-8 code unit: That's not a utf-8 code unit. A utf-8 code unit is just a single byte with a particular interpretation. If I do `char.sizeof` it's 2 bytes Are you sure about that? `char.sizeof` is 1. A char is just a single byte. The Ğ code point (note code units and code points are two different things, a code point is an abstract idea, like a number, and a code unit is one byte that, when combined, can create the number).
Re: Is it just me, or does vibe.d's api doc look strange?
On Friday, 2 December 2022 at 20:46:35 UTC, Christian Köstlin wrote: Please see this screenshot: https://imgur.com/Ez9TcqD of my browser (firefox or chrome) of https://vibed.org/api/vibe.web.auth/ Not just you, there's something broken in their html. You can use my website for vibe docs too: http://dpldocs.info/vibe.web.auth Though this specific example doesn't show in my docs because there's other declarations in the middle of it. But you can at least view it under the see source. http://vibe-d.dpldocs.info/source/vibe.web.auth.d.html#L15 then most everythign else works on the regular site anyway
Re: Syntax Sugar for Initializing a Fixed float Array as void*?
On Thursday, 1 December 2022 at 00:39:21 UTC, jwatson-CO-edu wrote: Is there a way to write a single statement that creates a void pointer that points to an initialized float array? void* f = [1.0f, 1.0f, 1.0f].ptr; Though I'd recommend keeping it typed as float[] until the last possible moment. If you are passing it a function, remmeber pointers convert to void* automatically, so you can do like: float[] f = [1,1,1]; some_function_taking_void(f.ptr); and it just works.
Re: pragma(linkerDirective,_) removes double quotes, dmd ignores LIB
On Monday, 28 November 2022 at 14:19:46 UTC, NonNull wrote: double quotes whatsoever into the linker command line via pragma(linkerDirective,_). linkerDirective doesn't add things to the linker command line at all. https://dlang.org/spec/pragma.html#linkerDirective "Implementation Defined: The string literal specifies a linker directive to be embedded in the generated object file. Linker directives are only supported for MS-COFF output. " "embedded in the generated object file" is not "added to linker command line". Only some switches are supported for embedding and the syntax might be different. This is why the error message also says "invalid directive". This is the Microsoft doc page for the feature the pragma uses: https://learn.microsoft.com/en-us/cpp/preprocessor/comment-c-cpp?source=recommendations&view=msvc-170#linker It looks like they actually removed some options in the recent update, I know /SUBSYSTEM used to work there too but it is no longer listed and there's people on the web saying it stopped working after updating to the 2022 visual studio. So yeah I think they removed support for that. But /LIBPATH has never been supported as far as I know. You'll want to use a build script/makefile/dub config/whatever to set linker command line options.
Re: Seeking in arsd.simpleaudio?
On Sunday, 20 November 2022 at 23:03:49 UTC, Adam D Ruppe wrote: Looking at doing it for mp3 is why I didn't put it in the interface yet... my mp3 code ported to D doesn't have a seek function! This is fixed on my computer now too, just need to check the rest of the bugs. So mp3 support will be coming before long as well. I'll do .wav too later in the week. Not sure about the emulated midi yet, but I'd love them all to implement the same interface, so I'll try. The next arsd tag is gonna have a lot of cool little things.
Re: Seeking in arsd.simpleaudio?
On Sunday, 20 November 2022 at 20:23:28 UTC, TheZipCreator wrote: and it appears that arsd.simpleaudio doesn't have a seek function. Is there a way to do this via other means? I want something like: Here's the patch for ogg, you can download those two files off git master too (i can't tag yet since i have a lot of pending stuff before regression testing but you can copy them into your current dir or replace the dub cache if you're using that directly and it will work) https://github.com/adamdruppe/arsd/commit/1f6ead0a178a8cfbb284d7719fe38863610165e2 It looks like: auto controller = aot.playOgg("myAudio.ogg"); controller.seek(5.0); // a float that is seconds in the file Looking at doing it for mp3 is why I didn't put it in the interface yet... my mp3 code ported to D doesn't have a seek function! But ogg did, it was just buggy.
Re: Seeking in arsd.simpleaudio?
On Sunday, 20 November 2022 at 22:26:26 UTC, TheZipCreator wrote: I guess in the meantime I'll just use a python script to cut the audio before execution i found the problem the library called seek(-thing) and my seek had a if(x <= 0) return; when it should have been if(x == 0) return. so it wouldn't go backward in the file! i'll add it to the interface and do some more fixes, then i can link you to the new file. should ACTUALLY be closer to 30 mins now but no promises i might still find new bugs yet but it is working in the one test file very well now.
Re: Seeking in arsd.simpleaudio?
On Sunday, 20 November 2022 at 20:34:44 UTC, Adam D Ruppe wrote: i'll get back to you in a lil i went overbudget lol. but yeah the seek function in the underlying lib fails and idk why it is so hard to even trace what error actually happened in these C codebases
Re: Seeking in arsd.simpleaudio?
On Sunday, 20 November 2022 at 20:23:28 UTC, TheZipCreator wrote: so how would you implement this hypothetical `seek` function? (or if you could tell me a different library that already has this functionality that'd be great too) My underlying vorbis lib has it, but haven't added to the simpleaudio interface yet. (Partly cuz i haven't figured it out for the ogg/mp3/wav combo yet) Give me a half hour lemme see if I can do it right now. I'll actually put it on the interface returned by playOgg.. i'll get back to you in a lil
Re: Can we ease WASM in D ?
On Wednesday, 16 November 2022 at 23:16:26 UTC, H. S. Teoh wrote: You mean with Phobos and everything included? I think there may be issues with that... Yes, this is a problem, but I think I have a solution: defer GC runs until javascript is running. There's also some llvm features that might fix it. If I had a spare day I think I could play with it. Which actually gave me the idea of a D-based framework that uses compile-time introspection, etc., to auto-generate the necessary JS glue code (e.g., as a pre-compile step[1]) so that the user does not actually have to write any JS manually for things to work. Sebastiaan Koppe generates the D/JS glue code from web standards. I've done it more dynamically inside D itself (exposing an `eval` hook on the JS side). Sebastiaans: https://github.com/skoppe/spasm mine: http://dpldocs.info/this-week-in-d/Blog.Posted_2020_08_10.html Actually pretty easy to solve.
Re: Can we ease WASM in D ?
On Wednesday, 16 November 2022 at 22:51:31 UTC, bioinfornatics wrote: And since then I ask myself can we at compile time convert a D code to an extern C code for wasm ? It would be pretty cool if you could just mark `@wasm` on a function and have it magically convert... the dcompute thing i *think* does something like this. but im not sure. Indeed, if a library/framework would wrap this to let end user write his code in plain D that would be awesome. So did you think it is possible to do it by using metaprogramming, mixin, mixin template, mixin string … ? What I've done before (including the webassembly.arsdnet.net website) is have the server call the compiler as-needed when requesting the file, which makes it feel pretty transparent. You might want to do that too, it'd be on the file level instead of on the function level but it works.
Re: Why am I getting different array size depending where I calling?
On Monday, 14 November 2022 at 21:00:38 UTC, matheus wrote: void[] getFoo(){ writeln(cast(int[])bar); auto foo = getFoo(); writeln(foo); Prints: [1, 0] [2, 0, 0, 0, 0, 0, 0, 0] Looking through godbolt.org the ASM generated with both So why the array generated from getFoo() is 4 times bigger than the other? It isn't. You're casting one to int[] and not casting the other, leaving it as void[], which writeln will interpret as just raw bytes. Since an int is 4x bigger than a byte, casting it to int shows 1/4 the number of ints. But the actual array is the same.
Re: Using glibc headers with ImportC
On Saturday, 12 November 2022 at 14:39:14 UTC, qua wrote: Do I have to do anything else? I've read that importc doesn't have a preprocessor and I assume it is related to that, however "ImportC can automatically run the C preprocessor associated with the Associated C Compiler". I still don't think that's been released yet, so if you aren't on the git master or at least the latest beta build it isn't going to work. Which dmd version are you running?
Re: Using glibc headers with ImportC
On Saturday, 12 November 2022 at 13:46:27 UTC, qua wrote: This is supposed to work, right? No, it isn't. And it probably never will. importC looks for a .c file in the current directory. It is that .c file's responsibility to #include whatever .h files you want.
Re: My new programming book ...
On Monday, 7 November 2022 at 06:10:46 UTC, zjh wrote: How is your `minigui`? Please write an `introduction` when you have time. It is on my list but minigui is a pretty simple class collection of basic widgets. It works pretty well now. I don't have too many intro examples yet though. My blog has one thing but it uses an experimental piece (http://dpldocs.info/this-week-in-d/Blog.Posted_2020_11_02.html) that isn't really representative of the average program. But if I make it to the dconf online I'll probably show off a minigui application there this year.
Re: My new programming book ...
On Monday, 7 November 2022 at 04:54:05 UTC, ikelaiah wrote: I'm aware of the publication date. However, I find the content still highly relevant to many day-to-day tasks (my use case). Yeah, I tried to focus more on the ideas behind it than the specifics of a library. My thought is if you understand what it is trying to do, the adjustments to bring it up to date shouldn't be too hard. It took some effort to avoid talking more about my libraries though lol. I did do a few small examples near the end of the book, and some of those have had minor changes, like I've since renamed "import simpledisplay" to "import arsd.simpledisplay". But the rest of it should still work, i try to keep things pretty stable in my libs. BTW one of the things in chapter 2 i found surprisingly popular was the talk about std.socket. I did write a follow-up to that in my blog here: http://dpldocs.info/this-week-in-d/Blog.Posted_2019_11_11.html#sockets-tutorial Since the socket api is the same as C, I assumed people would know it from other sources, but the C api isn't as common knowledge as it used to be. So this tries to explain (tho even there I didn't go into ipv6 fallbacks and whatnot but it still lays the foundation). And of course always feel free to ask here or whatever about anything, if I'm online I try to answer things pretty quickly.
Re: Passing a string by reference
On Tuesday, 8 November 2022 at 12:30:50 UTC, Alexander Zhirov wrote: Do I understand correctly that in order for me to pass a string when creating an object, I must pass it by value? You should almost never use `ref string`. Just use plain `string`. In fact, ref in general in D is a lot more rare than in languages like C++. The main reason to use it for arrays is when you need changes to the length to be visible to the caller... which is fairly rare. In the case of the variable `c`, a drop occurs. Why? An object is not being created on the stack? nope, an object isn't created there at all. you should use `new C`.