Re: Explain function syntax

2025-09-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 21 September 2025 at 20:33:11 UTC, user1234 wrote: On Saturday, 20 September 2025 at 02:36:47 UTC, Steven Schveighoffer wrote: What is a function type? It's the internal type that the compiler has for a function, which you actually cannot express in syntax. Actually D has a syntax

Re: Explain function syntax

2025-09-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 19 September 2025 at 16:58:38 UTC, Ali Çehreli wrote: On 9/18/25 10:18 PM, Steven Schveighoffer wrote: > On Thursday, 18 September 2025 at 18:10:13 UTC, Ali Çehreli wrote: >> // Not a delegate: >> static assert(is (typeof(twice) == function)); > You are mistaking the is expre

Re: Explain function syntax

2025-09-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 18 September 2025 at 18:10:13 UTC, Ali Çehreli wrote: As stated by multiple people, most nested functions will be 'delegates'. However, a nested function is a 'function' if it does not touch local scope: ```d void main() { int twice(int i) { return i * 2; } //

Re: Debug help - opDispatch - unknown member function

2025-09-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 9 September 2025 at 20:08:06 UTC, monkyyy wrote: On Tuesday, 9 September 2025 at 19:17:11 UTC, Steven Schveighoffer wrote: In short `opDispatch` only is valid if it compiles. If it doesn't compile, it's as if it doesn't exist. Yours still thinking declaratively, that cant be true

Re: Debug help - opDispatch - unknown member function

2025-09-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 9 September 2025 at 00:40:31 UTC, Brother Bill wrote: ``` c:\dev\D\D_templates_tutorial\toy1\source\app.d(8): Error: no property `callHome` for `l` of type `app.CallLogger!(C)` l.callHome("foo", "bar"); ^ ``` You might be expecting `opDispatch` inside `CallLogger` to try

Re: Debug help - delegate from dlang Tour

2025-09-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 8 September 2025 at 16:23:23 UTC, Brother Bill wrote: On Monday, 8 September 2025 at 14:42:01 UTC, evilrat wrote: probably because you have declared nested function `add` inside `main`, this creates a delegate closure capturing `main` scope, if you don't want that just mark `add` s

Re: GC BlkAttr clarification. Programming in D pages 671, 672. About GC

2025-09-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wednesday, 3 September 2025 at 23:05:45 UTC, H. S. Teoh wrote: On Wed, Sep 03, 2025 at 07:56:03PM +, Brother Bill via Digitalmars-d-learn wrote: [...] C, C++ and D can play shenanigans with pointers, such as casting them to size_t, which hides them from the GC. D's current GC is conser

Re: Alternatives to OOP in D

2025-09-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 1 September 2025 at 13:58:23 UTC, Brother Bill wrote: I have heard that there are better or at least alternative ways to have encapsulation, polymorphism and inheritance outside of OOP. With OOP in D, we have full support for Single Inheritance, including for Design by Contract (ex

Re: Debug help - Ranges - Programming in D page 598

2025-09-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 29 August 2025 at 01:51:27 UTC, Steven Schveighoffer wrote: On Friday, 29 August 2025 at 01:24:40 UTC, Steven Schveighoffer wrote: Will file an issue, and we should get this fixed. https://github.com/dlang/phobos/issues/10852 Fixed! https://github.com/dlang/phobos/pull/10854 Wi

Re: Debug help - ! in data sharing concurrency

2025-08-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 31 August 2025 at 12:44:33 UTC, Brother Bill wrote: On Sunday, 31 August 2025 at 01:27:57 UTC, Steven Schveighoffer wrote: Why would your second iteration make a difference? Purely by chance! In fact, on my machine, it does not exit in either case. Welcome to the wonderful world of

Re: How to have multiple synchronized shared types. Programming in D, page 647

2025-08-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 31 August 2025 at 03:45:07 UTC, Ali Çehreli wrote: On 8/30/25 6:34 PM, Steven Schveighoffer wrote: > The original feature never worked as intended. That section of the book > should be removed. > > The correct way to do this is a nested synchronized statement: > > ```d > synchronized(

Re: is vs ==

2025-08-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 30 August 2025 at 22:15:26 UTC, Brother Bill wrote: For the modern D developer, which is the more preferred choice, to use 'is' or '=='? `is` will do a direct bitwise comparison of the two sides, and cannot be hooked with an operator overload. This tests for *identity* (are the t

Re: How to have multiple synchronized shared types. Programming in D, page 647

2025-08-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 31 August 2025 at 00:46:50 UTC, Brother Bill wrote: The idea is that multiple shared objects use a common lock. ```d import std.stdio; void main() { } class BankAccount { } void transferMoney(shared BankAccount from, shared BankAccount to) { synchronized (from, to)← FAILS

Re: Debug help - ! in data sharing concurrency

2025-08-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 30 August 2025 at 22:05:49 UTC, Brother Bill wrote: A predicate (!*isDone) vs. (*isDone == false) seems to have different behavior, where I would expect identical behavior. What am I missing? This program runs forever, even though isDone changes from false to true. ```d import

Re: Debug help - Programming in D page 633 - concurrency shared(Exception) warnings

2025-08-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 30 August 2025 at 11:43:27 UTC, Brother Bill wrote: I tried various code changes, none of which worked. Kindly provide code changes to fix warnings that reflect modern D programming. This worked for me: ```d import std.stdio; import std.concurrency; import std.conv; struct Calc

Re: Debug help - Programming in D page 633 - concurrency shared(Exception) warnings

2025-08-29 Thread Steven Schveighoffer via Digitalmars-d-learn
A note on your references here: I'm assuming you are working from a physical book. But the online book is here: https://ddili.org/ders/d.en/index.html When you have questions, if you could link to the content, that would be really helpful. Especially since you are not including the entire ma

Re: Is D painted into a corner?

2025-08-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 28 August 2025 at 18:47:19 UTC, Brother Bill wrote: It seems like 'templates' are the 'Achilles heel' of D. Without starting a flame war, has D gotten to the point where ordinary mortals have difficulty coding in D with 'templates' such as 'cycle' requiring rewrites into 'myCycle'

Re: Debug help - Ranges - Programming in D page 598

2025-08-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 29 August 2025 at 01:24:40 UTC, Steven Schveighoffer wrote: Will file an issue, and we should get this fixed. https://github.com/dlang/phobos/issues/10852 -Steve

Re: Debug help - Ranges - Programming in D page 598

2025-08-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 28 August 2025 at 11:54:10 UTC, Brother Bill wrote: If line 9 of the program is commented out, it runs fine. Otherwise lots of error messages which don't pan out for me. I tried changing Negative.front to be const, which didn't help. I am not quite sure what the error messages are te

Re: foreach vs static foreach on compile time tuples

2025-08-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 26 August 2025 at 18:48:47 UTC, monkyyy wrote: ```d #!opend -unittest -main -run app.d bool isEvenImpl(int I)()=>! I%2; enum cases=1; import std.range; bool isEven(int i){ switch(i){ static foreach(I;0..cases){ //foreach(I;enumlist!(iota(cas

Re: Confirm: D escapes auto ref similar to Go language

2025-08-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 25 August 2025 at 08:36:05 UTC, Nick Treleaven wrote: On Monday, 25 August 2025 at 00:42:33 UTC, Steven Schveighoffer wrote: On Sunday, 24 August 2025 at 20:43:15 UTC, Ali Çehreli wrote: I think you went a little further in that section and made the return 'auto ref', which does not

Re: Confirm: D escapes auto ref similar to Go language

2025-08-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 24 August 2025 at 20:43:15 UTC, Ali Çehreli wrote: I think you went a little further in that section and made the return 'auto ref', which does not (and should not) fail compilation. No. auto ref is only for templates. This is a bug and should not compile. -Steve

Re: Confirm: D escapes auto ref similar to Go language

2025-08-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 24 August 2025 at 15:47:28 UTC, Brother Bill wrote: On Sunday, 24 August 2025 at 15:29:01 UTC, Steven Schveighoffer wrote: I don't know what's happening here, but it seems like a bug. This should not compile (it does for me, despite the comment above). It does compile. I didn't

Re: Confirm: D escapes auto ref similar to Go language

2025-08-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 24 August 2025 at 15:03:12 UTC, Brother Bill wrote: On page 549 of Programming in D, it appears that D supports 'escaping' local variables to the heap, when returning their address. This is similar to Go. Is this what is actually going on? Is this 'safe' to do? ``` &result: AC067AF

Re: What's the use of 'typeof','typeid','__traits','is' ?

2025-08-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 24 August 2025 at 03:13:38 UTC, David T. Oxygen wrote: The `is_int_or_float()` function has also simplified. Then I need to use another function to get the type of the result of `is_int_or_float()`, so I may write another piece of code like: ```d import std.stdio; string inputing="

Re: Pointers - Is it safe to point to invalid memory?

2025-08-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 18 August 2025 at 15:26:21 UTC, monkyyy wrote: On Monday, 18 August 2025 at 07:32:13 UTC, Steven Schveighoffer wrote: 2. You can store data in the lower bits of an aligned pointer (after all, this is just an interior pointer). Will the gc count this as a reference while scaning in a

Re: Pointers - Is it safe to point to invalid memory?

2025-08-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 16 August 2025 at 22:00:25 UTC, monkyyy wrote: Its over in the gc that has any relivence: https://dlang.org/spec/garbage.html#pointers_and_gc This list is really mostly based on a hope that at some point D will have a moving GC. This is never going to happen. Not only that, but

Re: How can one close issues fransferred from Bugzilla

2025-07-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 24 July 2025 at 18:31:58 UTC, Quirin Schroll wrote: For example, I originally filed [DMD#19271](https://github.com/dlang/dmd/issues/19271), but as far as GitHub is concerned, I’m not the author of that issue so I can’t close it. What’s the process for that? I can comment on that

Re: stdInputRange

2025-07-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 20 July 2025 at 20:26:02 UTC, Salih Dincer wrote: On Sunday, 20 July 2025 at 12:32:17 UTC, user1234 wrote: No problem here either. Where are you running the program from (embedded terminal in an editor ? a terminal emulator ?). Are you on Windows or Linux ? I want the program to en

Re: Is there some kind of Blocking Queue for D?

2025-07-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 12 July 2025 at 23:55:39 UTC, Ali Çehreli wrote: On 7/11/25 11:36 PM, Bienlein wrote: > Unhappily class MessageBox is private and therefore cannot be reused. Ah! :) That's one more data point against 'private', that little feature that helps with nothing. I don't know what langua

Re: Exception when creating a Thread with Windows

2025-07-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 5 July 2025 at 10:39:13 UTC, stef wrote: Hello, I'm totally new using D. I'm trying to create a thread using this code: ```d … extern (Windows) int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) … ``` I'm testing this program using

Re: How can I signal a master object that a resource handle is no longer used, from within the resource class's destructor?

2025-06-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 24 June 2025 at 08:48:16 UTC, realhet wrote: This is working in a normal use case: I create a Texture class insance, I store it's pointer and later when I press a key, I release the class pointer. But when I do not store the class pointer: `new Texture(...);` It just enters into

Re: Pointer vs Ref

2025-06-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 9 June 2025 at 07:24:41 UTC, confuzzled wrote: Hello community, Is it possible to accomplish the following using ref instead of pointers? If so, please share an example. ```d // Represents our Backtester engine struct Engine { // It STORES a pointer to its data source. This is

Re: Mixin template parameter overloading bug?

2025-06-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 14 June 2025 at 00:02:32 UTC, Andrey Zherikov wrote: The simplest code that shows the issue: ```d struct S{} template f(void function(S) F) {} template f(int function(S) F) {} mixin f!((_) {}); mixin f!((_) => 0); // Error: cannot return non-void from `void` function

Re: undefined reference to

2025-06-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 14 June 2025 at 00:25:13 UTC, mitgedanken wrote: I use ``dmd package.d -verrors=3 -debug -I"../.."``. I get ```sh Error: undefined reference to `std.container.array.Array!(minimal.token.token.Token).Array.empty() const` referenced from `const bool std.container.array.Array!

Re: Sanity check: pithiest test for static if: "is an array of ubyte"

2025-05-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 24 May 2025 at 20:29:52 UTC, Andy Valencia wrote: The best I"ve come up with for a "static if" to see if something's an array of ubyte: ```d (isArray!(typeof(arg))) && is(typeof(arg).init[0] == ubyte) ``` Which doesn't seem to work, but it's the closest I've come by poring over t

Re: Why is my image not rendering in a simple HTML page served with D?

2025-05-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 18 May 2025 at 21:40:17 UTC, Damjan wrote: Do I need to explicitly configure vibe.d to serve static files from the public folder? Yes https://vibed.org/api/vibe.http.fileserver/serveStaticFiles -Steve

Re: CTFE and RTFE results differ (aliasing)

2025-05-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 5 May 2025 at 17:15:57 UTC, kdevel wrote: ```d // // bs3.d // 2025-05-05 stvo // // $ dmd -g -checkaction=context -unittest -main -run bs3.d // bs3.d(25): [unittest] [4, 3, 3, 4] != [4, 3, 2, 1] ``` This is a bug, please report it. -Steve

Re: Subclass TcpSocket?

2025-03-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 18 March 2025 at 07:42:37 UTC, Jonathan M Davis wrote: The base class constructors are not nothrow, so WrappedTCP's constructor cannot be nothrow. There really isn't a way out of that, because if a constructor throws, the object's state is destroyed. So, catching and handling the Ex

Re: Noob ImportC questions

2025-02-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 27 February 2025 at 08:16:33 UTC, John C. wrote: On Thursday, 27 February 2025 at 08:10:04 UTC, John C. wrote: would removing some "hard to parse" constructs in header file help this situation? I tried to change ``` #define LIGHTGRAY CLITERAL(Color){ 200, 200, 200, 255 }

Re: What does a cast really do?

2025-02-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 21 February 2025 at 13:07:38 UTC, Paul Backus wrote: On Friday, 21 February 2025 at 07:44:54 UTC, Jonathan M Davis wrote: I think that what it basically comes down to is that because -1 fits in int, and int implicitly converts to uint, VRP is fine with converting the long with a valu

Re: template struct question

2025-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wednesday, 12 February 2025 at 20:55:14 UTC, WhatMeWorry wrote: ```d void main() { struct HexBoard(F,I) { this(F d, I r, I c) {} //void displayHexBoard(HexBoard!(F,I) h) {} // this compiles fine! } void displayHexBoard(HexBoard!(F,I) h) {} // error undefined identifier F and I

Re: core.simd and dynamic arrays

2025-01-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 26 January 2025 at 12:56:55 UTC, ryuukk_ wrote: common sense would be to make sure you are up to date before wondering why it's broken This is the learn forum. People are learning here. Try to be nicer, there is no need for this. -Steve

Re: Obtaining an address given a (run time) variable name

2025-01-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 20 January 2025 at 19:03:09 UTC, DLearner wrote: // In the code below, what fn needs to go in the commented-out line, // to make the program print 7, 11 rather than 7, 7? You can't I don't think get a list of local variables at this point, but you can get a list of struct member n

Re: Template declaration of std.typecons.isTuple in -X JSON file.

2025-01-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wednesday, 15 January 2025 at 12:01:21 UTC, realhet wrote: Hello, I'm working on understanding and automating the contents of an X Json file generated by LDC2. I'm testing it by processing the whole Phobos lib. The weirdest thing that I've found is this: X Json: ``` ``` Is there somethi

Re: Selective import seems to be importing more than just specified symbol

2025-01-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wednesday, 8 January 2025 at 02:07:46 UTC, WhatMeWorry wrote: I thought that the line import honeycomb : Location; would only import the symbol struct Location? So imagine a `honeycomb.d` file that looks like this: ```d module honeycomb; import std.stdio; struct Location { int r;

Re: Why 'in' works only for assoc arrays?

2024-12-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 27 December 2024 at 19:17:13 UTC, JN wrote: Why not make 'in' work for arrays (and strings also)? ``` int[string] phonebook; if ("John" in phonebook) // works int[] numbers; if (3 in numbers) // doesn't work, compiler recommends std.algorithm.find string buildLog; if ("build error

Re: Cross Compilation Guide for New Users

2024-12-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 20 December 2024 at 09:03:22 UTC, Dan wrote: Hi Dlang forums. I ran into some problems when trying to cross compile. Hope this clarifies the set-up for anyone with the same problems. Additionally, perhaps these more explicit instructions / pitfalls could be put into the official [

Re: Virtual opBinary in interface

2024-12-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 19 December 2024 at 18:49:28 UTC, sfp wrote: Subject lines says it all, I think... The choice to make binary operators implementable only via this `opBinary` template means it's unclear how to get virtual operators on an interface. I am very new to D, and my goal is to learn how

Re: raylib-d how to program a simple moving circle.

2024-11-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 30 November 2024 at 02:16:35 UTC, Alain De Vos wrote: After installing raylib library on Debian , https://github.com/raysan5/raylib/releases Running "dub run" i get now the error : ``` dub run Fetching raylib-d 5.5.1 (getting selected version)... Performing "debug" build using /us

Re: raylib-d how to program a simple moving circle.

2024-11-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 30 November 2024 at 01:28:44 UTC, Alain De Vos wrote: vscode no longer complains. But "dub run" gives, ``` dub run Starting Performing "debug" build using /usr/bin/dmd for x86_64. Up-to-date raylib-d 5.5.1: target for configuration [library] is up to date. Building my

Re: raylib-d how to program a simple moving circle.

2024-11-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 29 November 2024 at 22:02:23 UTC, Alain De Vos wrote: On Friday, 29 November 2024 at 21:37:48 UTC, Alain De Vos wrote: I can do "dub add raylib-d" but i have no clue to program a simple moving circle. Following program has an import error ```d import std.stdio: writeln; import ra

Re: only parameters or stack-based variables can be `inout`

2024-11-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 25 November 2024 at 14:24:44 UTC, Bastiaan Veelo wrote: // Fishy: inout(E) gun(inout(E) e) { //writeln(e.to!string); // only parameters or stack-based variables can be `inout` writeln((cast(Unqual!E)e).to!string); // OK return e; } Longstanding issue. When inout was fi

Re: Is there a way to make a struct without a distinction between constant, immutable, and mutable?

2024-11-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 18 November 2024 at 23:43:46 UTC, Liam McGillivray wrote: Is there a way to make it so that this struct has only one qualifier? No distinction? Can you give an example of a problem and list the error messages? -Steve

Re: Capturing by value in the thread

2024-10-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 18 October 2024 at 12:07:24 UTC, Kadir Erdem Demir wrote: It seems [=] functionality C++ does not exist in D. No, D does not have this functionality. By using a helper function I made that example work. ```d import std.stdio; auto localFoo(int x) { return (){ return x;}; }

Re: Why is this not allowed?

2024-10-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 8 October 2024 at 15:10:54 UTC, ryuukk_ wrote: Nonono, you overthink it Store last anonamous struct When you see a field without a type, you assign it with that anonymous struct It doesn't work this way. The parser would have to lookahead to see if the next 2 tokens are an iden

Re: Why is this not allowed?

2024-10-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 6 October 2024 at 05:41:10 UTC, ryuukk_ wrote: There is no new syntax to invent instead of writing this error: ``` onlineapp.d(8): Error: no identifier for declarator `stats` ``` you generate a random identifier and assign it ```D extern(D) static Identifier generateAnonymousId

Re: Why is this not allowed?

2024-10-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 5 October 2024 at 06:35:57 UTC, ryuukk_ wrote: Why is this allowed ```D struct EntityDef { struct { int hp; } } ``` But not this fucking thing? ```D struct EntityDef { struct { int hp; } stats; } ``` Let me name my shit No, i don't wan

Re: vibe-d linker error: undefined reference to deimos openssl

2024-09-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 10 September 2024 at 20:41:12 UTC, Curtis Spencer wrote: I'm attempting to upgrade the vibe-d dependencies of a project. The project compiles fine using `dub`, but the linker fails with: … I'm at a loss for how to fix this linker error. Any help would be appreciated. You may

Re: How to Humanize Numerical Input|Output

2024-09-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 9 September 2024 at 20:02:48 UTC, Jabari Zakiya wrote: Also for output, I do this: ``` writeln("total twins = ", twinscnt, "; last twin = ", last_twin - 1, "+/-1"); ``` I'd also like to output data as: 123,987 or 123_987 You can use separators using writefln: ```d writefln("%,

Re: How to Humanize Numerical Input|Output

2024-09-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 9 September 2024 at 20:02:48 UTC, Jabari Zakiya wrote: I have this code to input integer values: ``` ulong[] x; foreach (_; 0 .. 2) { ulong a; readf!" %d"(a); x ~= a; } end_num = max(x[0], 3); start_num = max(x[1], 3); if (start_num > end_num) swap(start_num, end_num); sta

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-08-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 31 August 2024 at 12:47:25 UTC, ryuukk_ wrote: ```D void main() { int[string] test; test["hello"] = 42; if (auto it = "hello" in test) { } } ``` Is there a way to get the value instead of a pointer? while keeping the conciseness (one line) Maybe if(auto it

Re: importC error: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach/vm_types.h(168): Error: variable `lib_test.mach_vm_range_recipe_v1_

2024-08-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 8 August 2024 at 06:34:43 UTC, Dakota wrote: ```sh /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach/vm_types.h(168): Error: variable `lib_test.mach_vm_range_recipe_v1_t.range` - no definition of struct `mach_vm_range` /

Re: How to find the right function in the Phobos library?

2024-08-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 17 August 2024 at 05:28:37 UTC, Bruce wrote: What is the best way to search for a function in the Phobos library? Go to dlang.org, select dicumentation, then library reference. Pick any module, click on it In the upper right, switch the docs from stable to ddox Now you can use

Re: Performance O(??) for associative array lookup

2024-08-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wednesday, 14 August 2024 at 07:48:58 UTC, Cecil Ward wrote: Does D give any guarantees for performance order-something ? What’s the current lib implementation like? It is amortized O(1), like most hash implementations. -Steve

Re: Get compile time string of dmd command line options "-os" & "-target"

2024-08-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 3 August 2024 at 12:15:46 UTC, Dennis wrote: On Thursday, 1 August 2024 at 04:00:08 UTC, An Pham wrote: pragma(msg, os.stringof...?); pragma(msg, target.stringof...?); There's no built-in way, but you can define it yourself in a helper module: ```D version(Windows) enum os

Re: importC error: can not find the #define ERR_INVALID -1

2024-08-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 3 August 2024 at 05:07:55 UTC, Dakota wrote: ```c #define ERR_SUCCESS 0 #define ERR_INVALID -1 // invalid argument ``` If the number >=0, it work. < 0 will not work. DMD64 D Compiler v2.110.0-beta.1 https://issues.dlang.org/show_bug.cgi?id=24639 -Steve

Re: std.container.rbtree has no search method?! e.g. `contains`, `canFind`

2024-07-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 13 July 2024 at 17:41:42 UTC, mw wrote: Hi, on doc: https://dlang.org/phobos/std_container_rbtree.html#.RedBlackTree I cannot find any search method?! e.g. `contains`, `canFind`. Is this a over look? Or there are such functions else where? The functions are called `equalRange`

Re: Wrapper around a recursive data type

2024-07-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 8 July 2024 at 08:56:51 UTC, drug007 wrote: How can I "break" this recursion or some other work around to fix it? A few ideas: 1. If it's immediately recursive (that is, contains a pointer to itself), just use the type itself somehow. You may not be able to do this with recursive

Re: Wrapper around a recursive data type

2024-07-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 8 July 2024 at 13:29:05 UTC, user1234 wrote: On Monday, 8 July 2024 at 08:56:51 UTC, drug007 wrote: I need to generate some meta info of my data types. I do it this [...] How can I "break" this recursion or some other work around to fix it? Use `Node*[]` for the children type. That

Re: Wrapper around a recursive data type

2024-07-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 9 July 2024 at 03:04:50 UTC, Steven Schveighoffer wrote: Can you post the error and the exact code that fails? I tried building this (with the children uncommented out) and it works fine. Ignore this, I didn't really read the whole message. -Steve

Re: Wrapper around a recursive data type

2024-07-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 8 July 2024 at 08:56:51 UTC, drug007 wrote: I need to generate some meta info of my data types. I do it this [way](https://gist.github.com/drug007/b0a00dada6c6ecbf46b4f6988401d4e2): ```D import std.range, std.format, std.stdio, std.traits; struct NestedType { string s; doubl

Re: Vibe.d v0.9.0, v0.10.0: ` dub init hello -t vibe.d` fails to build on MacOS

2024-07-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 7 July 2024 at 14:15:02 UTC, Ki Rill wrote: On Sunday, 7 July 2024 at 11:33:47 UTC, Sergey wrote: On Sunday, 7 July 2024 at 10:55:21 UTC, Ki Rill wrote: Machine: ``` MacBook Pro (Retina, 15-inch, Late 2013), macOS Big Sur version 11.7.10 ``` How should I solve this? It mentions un

Re: Why does this mixin fail to compile?

2024-07-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wednesday, 3 July 2024 at 11:57:58 UTC, Lance Bachmeier wrote: On Wednesday, 3 July 2024 at 03:52:41 UTC, Steven Schveighoffer wrote: And yes, it is faster to do this than appending. But you have to do a *lot* of it to make a huge difference. What about creating an array of strings and th

Re: Why does this mixin fail to compile?

2024-07-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 2 July 2024 at 07:23:42 UTC, ryuukk_ wrote: I said it 2 times already, i don't want string concatenation, i'll benchmark later, but not right now, right now i'm looking for a functioning code without string concatenation Your buffer solution works, but you need to put it inside a

Re: Default struct constructors if a struct member is a union

2024-07-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 29 June 2024 at 23:33:41 UTC, solidstate1991 wrote: My usecase scenario doesn't really allow constructors for the struct, since it's a binding to an external library via C API. BTW, this is not true. A constructor does not change the struct layout or anything about it from the C

Re: Default struct constructors if a struct member is a union

2024-07-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 29 June 2024 at 23:33:41 UTC, solidstate1991 wrote: ```d union U { int i32; long i64; float f32; double f64; } struct S { TypeEnum type; U data; } S foo0 = S(TypeEnum.Integer32, S(20)); //Ugly, but works S foo1 = S(TypeEnum.Integer64, S(20L)); //Error: cann

Re: aligned struct field weirdness

2024-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 18 June 2024 at 09:10:28 UTC, realhet wrote: I tried to narrow the problem, but I wasn't able, but I guess I've found another solution: There is a part in my framework which works with LDC2 1.28, but that's 'illegal' with later versions. Oh yeah. That is many versions ago! Release

Re: aligned struct field weirdness

2024-06-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 17 June 2024 at 19:45:18 UTC, realhet wrote: Hello, I'm having a weird case of access violation. Often times, you are focused on something that isn't the problem, but *triggers* the problem. Not saying it's not a compiler error, it could be. But chances are pretty low. If you c

Re: How to assign and compare arrays to SumType?

2024-06-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 11 June 2024 at 22:54:50 UTC, Steven Schveighoffer wrote: Let's see how it works if you want to both check that the value is a `double[]` and that it matches your value: ```d SumType!(double[], int) s = [1.7, 2.7, 3.7, 4.7, 5.7]; assert(s.data.match!( ``` This should be `s.match

Re: How to assign and compare arrays to SumType?

2024-06-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 11 June 2024 at 16:41:46 UTC, confuzzled wrote: Comparison between a Variant and an array is straightforward. How does one accomplish the same between a SumType and an array? ```d import std.variant; import std.sumtype; import std.stdio; struct S { SumType!(double[]) data; //

Re: How to use D without the GC ?

2024-06-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 11 June 2024 at 13:00:50 UTC, Vinod K Chandran wrote: Hi all, I am planning to write some D code without GC. But I have no prior experience with it. I have experience using manual memory management languages. But D has so far been used with GC. So I want to know what pitfalls it ha

Re: How to generate a random number from system clock as seed

2024-06-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 8 June 2024 at 13:19:30 UTC, Eric P626 wrote: I managed to create a random number generator using the following code: ~~~ auto rng = Random(42); // uniform(0,10,rng); ~~~ Now I want to seed the generator using system time. I looked at Date & time functions/classes and systime

Re: Trying to call some C code using Extern(C) but got unexpected linker error

2024-06-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 8 June 2024 at 02:22:00 UTC, Xiaochao Yan wrote: Hi, I am new to D and is experimenting with game development using D and C. I had some problem when trying to recreate the https://dlang.org/spec/importc.html Environment: Windows 11 gcc.exe (i686-posix-dwarf-rev0, Built by MinGW-W6

Re: bool passed by ref, safe or not ?

2024-06-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 4 June 2024 at 16:58:50 UTC, Basile B. wrote: question in the header, code in the body, execute on a X86 or X86_64 CPU ```d module test; void setIt(ref bool b) @safe { b = false; } void main(string[] args) { ushort a = 0b; bool* b = cast(bool*)&a; s

Re: Get milliseconds from time and construct time based on milliseconds

2024-05-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 28 May 2024 at 18:41:02 UTC, bauss wrote: On Tuesday, 28 May 2024 at 18:29:17 UTC, Ferhat Kurtulmuş wrote: On Tuesday, 28 May 2024 at 17:37:42 UTC, bauss wrote: I have two questions that I can't seem to find a solution to after looking at std.datetime. First question is how do I g

Re: Hide console on Windows with app running SDL2

2024-05-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 28 May 2024 at 12:35:42 UTC, bauss wrote: Running into a couple of problems trying to hide the console that opens when running an app that uses sdl2. First of all I am trying to compile with this using dub: ``` "lflags": ["/SUBSYSTEM:windows"] ``` However that gives me the followi

Re: __gshared is "somewhat" transitive, isn't it ?

2024-05-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 16 May 2024 at 17:04:09 UTC, user1234 wrote: Given ```d struct S { int member; } __gshared S s; ``` It's clear that `s.member` is `__gshared` too, right ? What does happen for ```d struct S { int member; static int globalMember; } __gshared S s; ``` Is then `S.globa

Re: D doesn't have weak references. So how can I make a associative array of objects without preventing their destruction?

2024-05-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 10 May 2024 at 11:05:28 UTC, Dukc wrote: This also gets inferred as `pure` - meaning that if you use it twice for the same `WeakRef`, the compiler may reuse the result of the first dereference for the second call, without checking whether the referred value has changed! This wou

Re: "in" operator gives a pointer result from a test against an Associative Array?

2024-05-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 10 May 2024 at 01:00:09 UTC, Andy Valencia wrote: On Friday, 10 May 2024 at 00:40:01 UTC, Meta wrote: Yes. The reason for this is that it avoids having to essentially do the same check twice. If `in` returned a bool instead of a pointer, after checking for whether the element exists

Re: TIL: statically initializing an Associative Array

2024-05-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 7 May 2024 at 00:10:27 UTC, Andy Valencia wrote: I had a set of default error messages to go with error code numbers, and did something along the lines of: string[uint] error_text = [ 400: "A message", 401: "A different message" ]; and got "expression is not a constant

Re: How can I put the current value of a variable into a delegate?

2024-05-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 6 May 2024 at 06:29:49 UTC, Liam McGillivray wrote: Delegates can be a pain, as they often have results different from what one would intuitively expect. This can easily result in bugs. Here's a line that caused a bug that took me awhile to find: ``` foreach(card; unitCards) card.su

Re: Show dialog box for uncaught exception (Windows, lld-link)

2024-05-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 5 May 2024 at 14:55:20 UTC, SimonN wrote: My application is a graphical game. I close stdout and stderr by passing `-subsystem:windows` to `lld-link` to suppress the extra console window. For a few fatal errors (missing required resources, can't open display, ...), I throw exceptions

Re: Phobos function to remove all occurances from dynamic array?

2024-05-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wednesday, 1 May 2024 at 01:09:33 UTC, Liam McGillivray wrote: This is presumably such a common task that I'm surprised it isn't easy to find the answer by searching; Is there a standard library function that removes all elements from a dynamic array that matches an input argument? In `st

Re: Adapting foreign iterators to D ranges

2024-04-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 22 April 2024 at 11:36:43 UTC, Chloé wrote: The first implementation has the advantage is being simpler and empty being const, but has the downside that next is called even if the range ends up not being used. Is either approach used consistently across the D ecosystem? I always g

Re: Statically compiled binary with C interop crashes.

2024-04-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 18 April 2024 at 11:05:07 UTC, yabobay wrote: On Wednesday, 17 April 2024 at 15:24:07 UTC, Ferhat Kurtulmuş wrote: On Wednesday, 17 April 2024 at 11:03:22 UTC, yabobay wrote: I'm using [dray](https://code.dlang.org/packages/dray) in my project with dub, here's the relevant parts of

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 14 April 2024 at 22:36:18 UTC, Liam McGillivray wrote: On Friday, 12 April 2024 at 15:24:38 UTC, Steven Schveighoffer wrote: ```d void InitWindow(int width, int height, ref string title) { InitWindow(width, height, cast(const(char)*)title); } ``` This is invalid, a string may no

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 12 April 2024 at 00:04:48 UTC, Liam McGillivray wrote: Here's what I wanted to do. In the library I'm working on, there are various declarations for functions defined in an external C library following the line `extern (C) @nogc nothrow:`. Here are some examples of such declaration

Re: How can I tell D that function args are @nogc etc.

2024-04-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 12 April 2024 at 03:57:40 UTC, John Dougan wrote: What is the procedure for bug reporting? I'm looking at the issues tracker and have no clue how to drive the search to see if this is already there. https://issues.dlang.org While entering the bug title, it does a fuzzy search fo

Re: How can I tell D that function args are @nogc etc.

2024-04-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 11 April 2024 at 03:17:36 UTC, John Dougan wrote: Interesting. Thank you to both of you. On Wednesday, 10 April 2024 at 17:38:21 UTC, Steven Schveighoffer wrote: On Wednesday, 10 April 2024 at 11:34:06 UTC, Richard (Rikki) Andrew Cattermole wrote: Place your attributes on the righ

  1   2   3   4   5   6   7   8   9   10   >