Re: How to build a static lib properly?

2023-03-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/5/23 9:09 PM, ryuukk_ wrote: On Monday, 6 March 2023 at 02:00:16 UTC, Mike Parker wrote: This is not dub's fault. When building a shared library, there's a link step, so any external dependencies are linked into the shared library just as they are with an executable. There is no link

Re: Use dub to create source lib and executables

2023-03-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/4/23 1:33 PM, Chris Piker wrote: Hi D I normally work in a *nix environment, typically on server-side code. For many projects I have gnu makefiles that build a small lib along with command line utilities. Up to now I've been creating a dub.json file for just the sourceLibrary, and

Re: dub.selections.json & optional dependencies: How's it work?

2023-02-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/24/23 2:01 PM, jmh530 wrote: I'm looking at the dub package format [1] about optional dependencies and it says: "With this set to true, the dependency will only be used if explicitly selected in dub.selections.json. If omitted, this attribute defaults to false." And it occurs to me

Re: Template alias parameter: error: need 'this' for ...

2023-02-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/24/23 7:00 AM, Elfstone wrote: Seems like the same bug is still there after ten years. `static` should not affect module-level functions, but also, this code should work without `static`. Reported, not sure if there's a previous bug, it was hard to come up with a good description:

Re: Lazy and GC Allocations

2023-02-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/20/23 1:50 PM, Etienne wrote: On Monday, 20 February 2023 at 02:50:20 UTC, Steven Schveighoffer wrote: See Adam's bug report: https://issues.dlang.org/show_bug.cgi?id=23627 So, according to this bug report, the implementation is allocating a closure on the GC even though the spec says

Re: Lazy and GC Allocations

2023-02-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/19/23 9:15 PM, Steven Schveighoffer wrote: Indeed, you can't really "save" the hidden delegate somewhere, so the calling function knows that the delgate can't escape. I stand corrected, you can save it (by taking the address of it). And it's explicitly allowed by the spec. But it

Re: Lazy and GC Allocations

2023-02-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/19/23 7:50 PM, Etienne wrote: Hello, I'm wondering at which moment the following would make an allocation of the scope variables on the GC. Should I assume that the second parameter of enforce being lazy, we would get a delegate/literal that saves the current scope on the GC even if

Re: Big struct/class and T.init

2023-02-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/19/23 1:26 PM, Steven Schveighoffer wrote: Testing with run.dlang.io, switching between `char` and `int` changes the ASM output to show whether it's stored or not. And BTW, you can override this by assigning a zero default: ```d struct S { char[16384] array = 0; // no .init storage

Re: Big struct/class and T.init

2023-02-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/19/23 1:11 PM, Guillaume Piolat wrote: If my understanding is correct, the mere fact of having a:     struct S     {     char[16384] array;     } And then using it anywhere, will necessarily lead to a S.init being created and linked, leading to a binary size inflation of 16kb.

Re: How can I easily determine the last charachter of a file?

2023-02-14 Thread Steven Schveighoffer via Digitalmars-d-learn
```d myFile.seek(-1, SEEK_END); ubyte c[1]; myFile.rawRead(c[]); if(c[0] == '\n') // ends in newline ``` -Steve

Re: Simplest way to convert an array into a set

2023-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/13/23 1:04 PM, Matt wrote: Obviously, there is no "set" object in D, but I was wondering what the quickest way to remove duplicates from an array would be. I was convinced I'd seen a "unique" method somewhere, but I've looked through the documentation for std.array, std.algorithm AND

Re: My vibe-d test app is crashing on Windows

2023-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/13/23 8:12 AM, Steve wrote: The app is just a test echo server. JSON sent in the body of a POST request is echoed back to the client. On Pop!_OS it works fine but on Windows it responds, there's a delay of about 10 seconds and then it crashes with the error: ``` Error Program exited

Re: ddbc with Vibe-d

2023-02-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/12/23 3:29 PM, Steve wrote: In my case args will just be the body of the HTTPServerRequest which is JSON. How can I get that JSON and pass it to async() in a manner that ensures I get a worker thread? I think it needs to be immutable if it's a reference. -Steve

Re: How does the function 'iota' get its name?

2023-02-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/12/23 2:17 PM, ccmywish wrote: Hi, everyone! I'm very new to D. I see a function called [iota](https://dlang.org/library/std/range/iota.html) `Iota` seems a [Greek letter](https://en.wikipedia.org/wiki/Iota). Why does it relate to range? It came from C++. See notes here:

Re: ddbc with Vibe-d

2023-02-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/12/23 1:01 PM, Steve wrote: On Sunday, 12 February 2023 at 15:24:14 UTC, Steven Schveighoffer wrote: Any synchronous calls will just be synchronous. They aren't going to participate in the async i/o that vibe uses. In other words, when you block on a call to sqlite, it will block

Re: ddbc with Vibe-d

2023-02-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/12/23 6:05 AM, Steve wrote: Hi, I'm trying D for the first time and so far I'm really impressed with both D and vibe-d. My test project is an application server and I want to use SQLite3 as its database. I understand Vibe.d uses an async model under the hood and so my question is are

Re: Gneric linkedList range adaptor

2023-02-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/10/23 5:10 PM, Ben Jones wrote: I'm trying to write a range adaptor for linked list types.  The range type seems to work OK, but my helper function to deduce the node type has a compiler error.  My hunch is that `nextField` loses its association with T when I'm trying to pass it as a

Re: How to write a library

2023-01-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/21/23 5:53 PM, Matt wrote: I am trying to write a graphics engine for my university capstone project, and really wanted to give it a try in D, as both a talking point, and because I love the language. I'm using dub to build the library, and the demo application that'll use it. However,

Re: Is there a way to get a template’s parameters and constraints?

2023-01-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/20/23 12:15 PM, Quirin Schroll wrote: Is there a trait (or a combination of traits) that gives me the constraints of a template? Example: ```D void f(T1 : long, T2 : const(char)[])(T x) { } template constraintsOf(alias templ) { /*Magic here*/ } alias constraints = constraintsOf!f; //

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/20/23 6:28 AM, thebluepandabear wrote: This type of semantics is not possible in D, which sucks. Well, static methods do exactly this. If you want to disable class creation, then use `@disable this();`, if you want to make all methods static, put `static:` at the top of the class.

Re: How to Add CSS and JS to vibe.d templates

2023-01-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/19/23 11:44 PM, seany wrote: Hi Howcan one add CSS and JS to vibe.d templates? Here is my setup (vibe.d project initiated with dub using dub init myproject vibe.d): ./public: main.css  main.js ./source: app.d ./views: auth2fa.dt  fail.dt  login.dt  pair.dt  passfail.dt  userfail.dt

Re: What is the 'Result' type even for?

2023-01-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/19/23 10:34 PM, Ruby The Roobster wrote: On Friday, 20 January 2023 at 03:30:56 UTC, Steven Schveighoffer wrote: On 1/19/23 10:11 PM, Ruby The Roobster wrote: ... The point is to be a range over the original input, evaluated lazily. Using this building block, you can create an array, or

Re: What is the 'Result' type even for?

2023-01-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/19/23 10:11 PM, Ruby The Roobster wrote: Take this example: ```d import std; void main() {     auto c = "a|b|c|d|e".splitter('|');     c.writeln;     string[] e = ["a", "b", "c", "d", "e"];     assert(c.equal(e));     typeof(c).stringof.writeln; } ``` The program prints: ["a", "b",

Re: Vibe.d Diet Templatesand Forms

2023-01-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/19/23 6:24 PM, seany wrote: Hello Please consider this diet template:     doctype html     html(lang="es", dir="ltr")     head     meta(name="viewport", content="width=device-width, user-scalable=no, initial-scale=1.0")    

Re: Nested sibling classes

2023-01-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/12/23 12:05 PM, seany wrote: How can I make it, that classes b and c can access each other, and create instances of each other freely? Thank you. So to just point out something that wasn't discussed by Salih: When you declare a field of a class with an initializer, *that initializer

Re: enum functions

2023-01-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/10/23 7:55 AM, Adam D Ruppe wrote: 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

Re: what wrong with this alias

2023-01-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/8/23 12:42 AM, Qusatlegadus wrote:     auto s = 1234.to!string.map!q{a - '0'}.sum; works fine. but if i do an alias     alias comb = to!string.map!q{a - '0'}     Error: unknown, please file report on issues.dlang.org What's wrong with this alias? Aside from the problem with the

Re: Address of a class object

2023-01-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/4/23 2:27 PM, Ali Çehreli wrote: On 1/4/23 10:48, H. S. Teoh wrote: > Allocations are not necessarily consecutive; the GC may have its own > strategy of allocation that doesn't follow a linear sequence. That was one of my guesses. So, I put the objects into a 2-length static array but

Re: Is there such a JSON parser?

2023-01-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/1/23 6:28 PM, torhu wrote: I need to parse some JSON data into various data structures, so I'm looking for a parser based on events or ranges. One that doesn't just load the file and build a data structure that represents the whole thing. So not std.json, at least. It's pretty

Re: Compile time vs run time -- what is the difference?

2022-12-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/27/22 9:31 PM, thebluepandabear wrote: I am reading through the free book on learning D by Ali Çehreli and I am having difficulties understanding the difference between compile time execution and run time execution in D language. Compile time execution is running your code being

Re: Can you simplify nested Indexed types?

2022-12-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/27/22 10:31 AM, Sergei Nosov wrote: On Tuesday, 27 December 2022 at 15:20:24 UTC, Salih Dincer wrote: On Tuesday, 27 December 2022 at 15:09:11 UTC, Sergei Nosov wrote: Consider, I have the following code: ```d     auto a = [3, 6, 2, 1, 5, 4, 0];     auto indicies = iota(3);     auto ai

Re: Preventing nested struct destructor accessing stack frame

2022-12-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/16/22 7:17 AM, Nick Treleaven wrote: This code segfaults when the GC calls the dtor after the unittest succeeds: ```d unittest {     int i;     struct S     {     ~this() { i++; }     }     (*new S).destroy; } ``` It seems destroy clears the context pointer. Is there a way to

Re: Confusion about `Random`

2022-12-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/23/22 10:07 AM, jwatson-CO-edu wrote: On Friday, 23 December 2022 at 00:58:01 UTC, Steven Schveighoffer wrote: Without the rest of the code, and how random is called, I have a hunch... Are you using threads by any chance? If, for instance, your calls to rand01 are done in a new thread,

Re: Confusion about `Random`

2022-12-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/22/22 11:23 AM, jwatson-CO-edu wrote: I am confused about why Program 1 produces random output but Program 2 does not. --- ### Program 1 ```d import std.stdio; import std.conv; import std.random; Mt19937 rnd; double rand01(){     // Uniform random sampling in [0,1)     return

Re: How to use version in dub?

2022-12-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/13/22 3:35 PM, ryuukk_ wrote: On Tuesday, 13 December 2022 at 20:01:40 UTC, torhu wrote: On Tuesday, 13 December 2022 at 19:50:15 UTC, torhu wrote: On Tuesday, 13 December 2022 at 19:28:44 UTC, Leonardo A wrote: Hello. How to use version in dub? https://dlang.org/spec/version.html "The

Re: How to compiler dlang code on Apple M1?

2022-12-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/13/22 10:20 AM, Steven Schveighoffer wrote: Yeah, that's a known issue: https://github.com/ldc-developers/ldc/issues/3864 Try building with `-b plain` to avoid the debug build Oh, also, I have MACOSX_DEPLOYMENT_TARGET=11 in my environment, that helps to avoid it as well. -Steve

Re: How to compiler dlang code on Apple M1?

2022-12-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/13/22 9:35 AM, zoujiaqing wrote: On Saturday, 3 December 2022 at 20:33:59 UTC, Steven Schveighoffer wrote: The issue is dub. Make sure you are using the dub built for ARM. What Apple does is if any program in the same process group is x86 specific, then all the executed programs that

Re: Is remove safe using foreach

2022-12-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/13/22 6:22 AM, Per Nordlöw wrote: On Monday, 12 December 2022 at 17:29:00 UTC, Steven Schveighoffer wrote: Removing keys while iterating is not supported. It will break, in confusing ways, and possibly include a null pointer dereference. IRC, the specs says that it's an error to modify

Re: Is remove safe using foreach

2022-12-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/12/22 8:45 PM, Steven Schveighoffer wrote: for(auto r = aa.byKey, auto k = r.front; !r.empty; r.popFront) err... forgot the continual front assignment I think it's more like: for(auto r = aa.byKey; !r.empty; r.popFront) { auto k = r.front; // foreach body } -Steve

Re: Is remove safe using foreach

2022-12-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/12/22 7:54 PM, lili wrote: is foreach Syntactic sugar?, like for-range in C++, if it is, compiler how implement Yes it is syntax sugar. The lowering depends on what the item you're iterating is. For an associative array `byKey`, it is converting the AA into a range of keys, and

Re: Is remove safe using foreach

2022-12-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/12/22 12:23 PM, lili wrote: ``` int[string] aa = ["ok":1, "aaa":2, "ccc":3, "ddd":4]; foreach (k ; aa.byKey) {     if (k == "aaa") {     aa.remove(k);     aa["ww"] = 33;     }     if (k == "ww") {     aa.remove(k);     aa["vv"] = 33;     }

Re: Structure initializer VS lambda function

2022-12-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/12/22 3:54 AM, realhet wrote: Hi, I'm writing a DLang parser and got confused of this. What is a good way to distinguish lambda functions and structure initialization blocks. Both of them are {} blocks. I'm thinking of something like this: 1. checking inside (on the first hierarchy

Re: Advent of Code 2022

2022-12-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 10 December 2022 at 20:49:03 UTC, Christian Köstlin wrote: Is anybody participating with dlang in the advent of code 22? It would be interesting to discuss dlang specific things from the puzzles. Mine: https://github.com/schveiguy/adventofcode -Steve

Re: Is there such concept of a list in D?

2022-12-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/10/22 1:11 AM, thebluepandabear wrote: I was wondering more if there is an object oriented way of creating arrays, like in Java there is an `ArrayList`, in C++ there is `std::vector`, etc. In D, you just use `T[]` for an array, it's similar to `std::vector`. -Steve

Re: Is there such concept of a list in D?

2022-12-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/10/22 12:46 AM, thebluepandabear wrote: In most languages there is some sort of `List` type, is that the same for D? D doesn't focus on interfaces, we have concepts, like ranges. Sorry, it's hard to answer your question without asking more questions: are you looking for a linked list?

Re: How to compiler dlang code on Apple M1?

2022-12-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/3/22 1:59 PM, zoujiaqing wrote: ``` dub build --compiler=ldc2 --arch=arm64-apple-macos     Starting Performing "debug" build using ldc2 for aarch64, arm_hardfloat.     Building taggedalgebraic 0.11.22: building configuration [library]     Building eventcore 0.9.20+commit.4.g6744ae7:

Re: Why can't D store all UTF-8 code units in char type? (not really understanding explanation)

2022-12-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/2/22 4:18 PM, thebluepandabear wrote: Hello (noob question), I am reading a book about D by Ali, and he talks about the different char types: char, wchar, and dchar. He says that char stores a UTF-8 code unit, wchar stores a UTF-16 code unit, and dchar stores a UTF-32 code unit, this

Re: Is it just me, or does vibe.d's api doc look strange?

2022-12-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/2/22 3:46 PM, 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. And Sonke is aware (there's a conversation on the dlang slack). -Steve

Re: raylib-d Gamepad Detection Fails

2022-12-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/1/22 5:50 PM, jwatson-CO-edu wrote: On Thursday, 1 December 2022 at 22:16:30 UTC, jwatson-CO-edu wrote: That was the trick, [inside the loop it detects the gamepad](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInput/source/app.d#L35).  No other changes needed. I

Re: raylib-d Gamepad Detection Fails

2022-12-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/1/22 11:10 AM, ryuukk_ wrote: Can you try with this page: https://www.raylib.com/examples/core/loader.html?name=core_input_gamepad Does it detect your gamepad? It should work because the `IsGamepadAvailable` function call is inside the loop. That's most certainly the problem with the

Re: raylib-d Gamepad Detection Fails

2022-12-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/1/22 3:24 AM, bauss wrote: But probably not on every frame, have a delay between checks. It's not anything controllable by the user. The library does the check every frame regardless of whether you use it or not. When you call the raylib function, you are not actually querying the

Re: raylib-d Gamepad Detection Fails

2022-11-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/30/22 8:49 PM, jwatson-CO-edu wrote: Yes, following your instructions I have raylib 4.2.0 and raylib-d 4.2.4 in the project directory.  I am now using the latest version of raylib-d, but this did not resolve the gamepad issue. I can ask around on the raylib channels. Oh, I think I

Re: raylib-d Create Light Sources

2022-11-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/30/22 7:56 PM, jwatson-CO-edu wrote: uint MAX_LIGHTS = 4; This needs to be an `enum`. //... Light[MAX_LIGHTS] lights; // Error: undefined identifier `Light` The rlights header file is not part of the raylib library, but is in the examples directory, you will need to port it. It's

Re: raylib-d Gamepad Detection Fails

2022-11-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/30/22 7:28 PM, jwatson-CO-edu wrote: On Wednesday, 30 November 2022 at 23:18:33 UTC, ryuukk_ wrote: On Wednesday, 30 November 2022 at 22:46:52 UTC, jwatson-CO-edu wrote: Hello, I have this small [gamepad input test

Re: How do I _really_ implement opApply?

2022-11-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/29/22 7:50 PM, WebFreak001 wrote: (note: I don't want to use a template, this way of writing it has the advantage that the compiler checks all different code paths for errors, so the errors aren't delayed until someone actually tries to iterate over my data structure) 1. use the

Re: How do you return a subclass instance from a base class method?

2022-11-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/16/22 11:25 PM, Daniel Donnelly wrote: I have SubclassOf derived from PosetRelation.  For any poset relation, the transitivity law applies, however, I'd like to return the correct type: ```    PosetRelation transitivity(PosetRelation R, PosetRelation S)    {   if (R.op == S.op)   

Re: Makefiles and dub

2022-11-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/4/22 7:19 PM, Anonymouse wrote: [#20699](https://issues.dlang.org/show_bug.cgi?id=20699) must be non-trivial to fix, so I'm exploring makefiles. If possible I'd like to keep dub for dependency management though, just not for actual compilation. Is it at all possible (or even desireable)

Re: Hipreme's #4 Tip of the day - Don't use package.d

2022-11-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/4/22 3:49 PM, Adam D Ruppe wrote: On Friday, 4 November 2022 at 19:34:58 UTC, jmh530 wrote: Oh really, then what's the point of package.d? It was originally added because Phobos had `std.algorithm` and `std.datetime` and some people wanted to break them up into pieces, but not break

Re: What's the correct way of creating an instance of class in D?

2022-11-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/3/22 1:46 PM, Tejas wrote: Check my post, `A& a;` refuses to compile in C++20 atleast, asking to be explicitly initialized, thus averting the problem altogether That's different, `A&` cannot be rebound in C++, whereas a class reference can. Try `A* a;` and see if it compiles -Steve

Re: druntime thread (from foreach parallel?) cleanup bug

2022-11-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 1 November 2022 at 18:18:45 UTC, Steven Schveighoffer wrote: Oh yeah, isDaemon detaches the thread from the GC. Don't do that unless you know what you are doing. As discussed on discord, this isn't actually true. All it does is prevent the thread from being joined before exiting

Re: druntime thread (from foreach parallel?) cleanup bug

2022-11-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 1 November 2022 at 18:18:45 UTC, Steven Schveighoffer wrote: Oh yeah, isDaemon detaches the thread from the GC. Don't do that unless you know what you are doing. As discussed on discord, this isn't true actually. All it does is prevent the thread from being joined before exiting

Re: druntime thread (from foreach parallel?) cleanup bug

2022-11-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/1/22 1:47 PM, mw wrote: Can you show a code snippet that includes the parallel foreach? (It's just a very straight forward foreach on an array; as I said it may not be relevant.) And I just noticed, one of the thread trace points to here:

Re: A strange DMD error

2022-11-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/1/22 11:40 AM, Keivan Shah wrote: Hello, Today I came across a strange bug while using D with `dmd`. I have still not been able to figure out under what conditions does it happen but it seems to be a DMD related bug to me. Here is a reproducible snippet of the code ```D import std;

Re: ImportC in a Dub project

2022-10-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/28/22 2:43 PM, Carsten Schlote wrote: On Friday, 28 October 2022 at 18:31:25 UTC, Steven Schveighoffer wrote: Are you passing the c file to the compiler? Also, you must be using dmd for ImportC currently. What is your build line? ``` $ cat dub.json { "authors": [    

Re: ImportC in a Dub project

2022-10-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/28/22 1:45 PM, Carsten Schlote wrote: Hi, I created a Dub project containing two files: app.d and zstd_binding.c ``` $ cat source/zstd_binding.c #include #include #include void relatedCode(void) { printf("Hallo! This is some output from C code!\n"); } ``` and ``` $ cat

Re: auto scope question?

2022-10-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/25/22 6:07 PM, WhatMeWorry wrote: I'm naturally getting a undefined identifier `s` error in the return. Is there some way to refactor my code?  I tried to declare s outside of the else brackets like: auto screen = executeShell(cmdLine); auto s; ... {     s =

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/25/22 2:03 PM, Ali Çehreli wrote: On 10/25/22 11:01, Ali Çehreli wrote: > static arrays don't have .ptr to point > to any member. Why do I say incorrect things like that? :) Of course static arrays have .ptr as well but that always point to their own body of N elements. They own

Re: Real simple question... for good programmers

2022-10-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/22/22 5:53 PM, WhatMeWorry wrote: string[] tokens = userSID.output.split!isWhite; writeln("tokens = ", tokens); tokens = ["SID", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",

Re: Find in assoc array then iterate

2022-10-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/22/22 12:53 AM, Kevin Bailey wrote: Steven, Just because you don't see the value doesn't mean I don't. You should try to be more helpful, or don't bother. I just mean that I don't understand what iterating from a random position in the AA is. Why not iterate from the beginning? It

Re: Find in assoc array then iterate

2022-10-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/21/22 6:03 PM, Kevin Bailey wrote: I'm trying to do this equivalent C++:     unordered_map map;     for (auto i = map.find(something); i != map.end(); ++i)     ...do something with i... in D, but obviously with an associative array. It seems that it's quite easy to iterate

Re: Compiler Error while using Validation in the hunt-framework

2022-10-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/19/22 3:00 PM, Roman Funk wrote: Hello, I started playing with D and the hunt-framework. But I bumped into an error using Validation. ```d module app.forms.LoginForm; import hunt.validation; import hunt.framework.http.Form; class LoginForm : Form {     mixin MakeForm;     @Email    

Re: Float rounding (in JSON)

2022-10-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/13/22 3:00 PM, Sergey wrote: I'm not a professional of IEEE 754, but just found this behavior at rounding in comparison with other languages. I supose it happened because in D float numbers parsed as double and have a full length of double while rounding. But this is just doesn't match

Re: How to workaround assignment not allowed in a condition?

2022-10-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/12/22 7:46 AM, Dennis wrote: On Wednesday, 12 October 2022 at 10:09:31 UTC, Steven Schveighoffer wrote: I'm actually very surprised that just wrapping the statement in an == expression doesn't do the trick, what is the possible logic behind outlawing that? I looked into it, there are

Re: How to workaround assignment not allowed in a condition?

2022-10-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/12/22 9:17 AM, Rene Zwanenburg wrote: On Wednesday, 12 October 2022 at 02:15:55 UTC, Steven Schveighoffer wrote: Am I missing something? Perhaps I am, but why not turn it into a numeric comparison, like: ``` while((i = 5) == 0) ``` Yes, that is the answer, that was eluding me. What

Re: How to workaround assignment not allowed in a condition?

2022-10-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/12/22 5:24 AM, Dennis wrote: On Wednesday, 12 October 2022 at 02:15:55 UTC, Steven Schveighoffer wrote: Porting some C code to D This results in an error: I had the same issue, where the pattern was this: ```C void f() {     int err;     if (err = some_api_call()) {    

How to workaround assignment not allowed in a condition?

2022-10-11 Thread Steven Schveighoffer via Digitalmars-d-learn
Porting some C code to D This results in an error: ```d int x; while(!(x = 5)) { break; } ``` Error is: assignment cannot be used as a condition, perhaps `==` was meant? OK, fine, I'll use `==`: ```d int x; while(!(x = 5) == true) { break; } ``` Nope, same error. I tried reversing the

Re: Replacing tango.text.Ascii.isearch

2022-10-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/5/22 12:59 PM, torhu wrote: I need a case-insensitive check to see if a string contains another string for a "quick filter" feature. It should preferrably be perceived as instant by the user, and needs to check a few thousand strings in typical cases. Is a regex the best option, or what

Re: Convert int to dchar

2022-10-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/5/22 12:57 PM, Paul wrote:    I'm sure I'm making this more difficult than it needs to be. I'm trying to convert an integer to a dchar.  The solution below works but seems like overkill.     dstring dstrValue = to!dstring(5);     dchar dcharValue = to!dchar(dstrValue); ... this,   

Re: Remove elements without losing capacity

2022-10-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/4/22 11:22 AM, Riccardo M wrote: Is it possible to remove elements from a range without losing its capacity? ``` void main() {     import std.algorithm.mutation : remove, SwapStrategy;     import std.stdio : writeln;     int[] arr = [1, 2, 3, 2, 4, 2, 5, 2];     assert(arr.length ==

Re: Stop writeln from calling object destructor

2022-10-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/2/22 12:21 PM, data pulverizer wrote: I've noticed that `writeln` calls the destructor of a struct multiple times and would like to know how to stop this from happening. It has become a very serious problem when working with objects that have memory management external to D. I know you

Re: How to do alligned allocation?

2022-10-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/1/22 12:57 AM, tsbockman wrote: On Saturday, 1 October 2022 at 01:37:00 UTC, Steven Schveighoffer wrote: The list of bit sizes is currently here: I'm pretty sure those are in **bytes** not **bits**. Yes, I meant bytes, sorry. That's not a list of alignments, it is block sizes for

Re: How to do alligned allocation?

2022-09-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/30/22 11:57 AM, Quirin Schroll wrote: When I do `new void[](n)`, is that buffer allocated with an alignment of 1 or what are the guarantees? How can I set an alignment? Also, is the alignment of any type guaranteed to be a power of 2? In practice, it's not necessarily a power of 2, but

Re: Is there a way to mark a dub package as linux only?

2022-09-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/26/22 4:57 PM, Christian Köstlin wrote: Or posix only? Or not windows? Kind regards, Christian We have specific directives based on os, I had an idea that you could say something like: ```json "dependencies-windows": { "not-available" : "*" } ``` But it still tries to find this

Re: Is this a new bug ?

2022-09-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 24 September 2022 at 06:13:55 UTC, test123 wrote: If so please report it for me to bugs platform. I can not register one. ```d package { version(TEST) { static: } else { __gshared: } uint test = 0; } ``` ldmd2 -betterC -vtls -c ./test.d

Re: how to use dub to run all / chosen dependency lib's unittests

2022-09-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/19/22 7:48 PM, mw wrote: Hi, I'm using dub.json to specify the dependencies libs for my project. I'm just wondering how I can use dub to run all the tests of those dependencies libs (of the transitive closure of *all* the libs) to make sure my project is built on a very solid

Re: Setting import paths - project (dub) and also rdmd or dmd

2022-09-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/19/22 10:24 AM, David wrote: TLDR: How do I automatically specify the -I to the compilers so I don't need to specify it manually each time ? For dmd, dmd.conf: https://dlang.org/dmd-osx.html#dmd-conf I believe for all compilers, there's an equivalent config file. -Steve

Re: Does the GC prioritize same-class when looking for things to free?

2022-09-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/15/22 1:12 PM, cc wrote: Why is Foo never deallocated here? (`DMD32 D Compiler v2.099.0-dirty` win64) In answer to your title question, no. It does not prioritize anything. If it thinks something is ready to be freed, it is freed. If it thinks something is not ready to be freed, it is

Re: Building Example Project with `raylib-d`

2022-09-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/14/22 4:17 PM, jwatson-CO-edu wrote: Hello, I used the following steps to build the example `raylib-d` program. (https://github.com/schveiguy/raylib-d#example) ### Install Raylib (Ubuntu/Debian) 1. `sudo apt install libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev

Re: can not take const struct member address at CTFE , is this a bug?

2022-09-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/14/22 12:53 AM, test123 wrote: On Wednesday, 14 September 2022 at 00:40:38 UTC, Ruby The Roobster wrote: The addresses of items stored in memory are by definition not constant.  This isn't a bug. If so why this can work ? ```d struct c { uint a, b;} __gshared const c d = { 3, 4};

Re: Function attribute best practices

2022-09-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/12/22 1:08 PM, Ali Çehreli wrote: On 9/12/22 09:48, H. S. Teoh wrote: >> @nogc nothrow pure @safe >> unittest >> { >>  // ... >> } >> >> No, it isn't because unless my unittest code is impure, I can't catch >> my incorrect 'pure' etc. on my member functions. > [...] > > Sure

Re: Function attribute best practices

2022-09-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/12/22 12:14 PM, Ali Çehreli wrote: What are best practices here? attributes such as `pure`, `@nogc`, `nothrow`, `@safe` should all be left to inference. Either the function can do those attributes, or it cannot. attributes such as `const` or `inout` are different -- these are *not*

Re: Using .require for struct types

2022-09-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/10/22 12:33 PM, Erdem Demir wrote: Can you please suggest alternatives? Use a pointer. ```d DListOfA *returnVal = (...); returnVal.insert(a); ``` -Steve

Re: Validate static asserts

2022-09-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/9/22 10:35 AM, Andrey Zherikov wrote: I have bunch of `static assert(, )` in my code and would like to validate that specific code triggers specific assert by checking what `` is thrown. Right now I do `static assert(!__traits(compiles, { }));` but since `` might not compile due to

Re: How include header file?

2022-09-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/7/22 4:23 PM, Injeckt wrote: On Wednesday, 7 September 2022 at 19:38:52 UTC, H. S. Teoh wrote: On Wed, Sep 07, 2022 at 06:11:14PM +, Injeckt via Digitalmars-d-learn wrote: I need to include this Ws2tcpip.h header file to my project. How can I do this? It's all because I need inet_ntop

Re: Forked GC explained

2022-09-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/6/22 6:31 PM, frame wrote: Well, of course it would be the fault of the programmer. I did ask this because I just want to know if there is any catch of this (probably not intended/yet noticed) violation of some third party lib. I don't want do debug this :D You can be confident that if

Re: Forked GC explained

2022-09-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/5/22 7:12 AM, frame wrote: And what if the programmer has no actual reference but wrongly forced a `free()` through a pointer cast? https://dlang.org/spec/garbage.html#pointers_and_gc * Do not store pointers into non-pointer variables using casts and other tricks. ```d void* p; ... int

Re: synchronized/shared associative array .require error

2022-09-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/4/22 11:24 PM, cc wrote: On Saturday, 3 September 2022 at 14:37:16 UTC, Steven Schveighoffer wrote: On 9/2/22 3:15 PM, cc wrote: Tried casting away shared as a workaround but I assume that will cause some kind of TLS catastrophe. I think it will be fine, but you may have an issue.

Re: synchronized/shared associative array .require error

2022-09-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/2/22 3:15 PM, cc wrote: Tried casting away shared as a workaround but I assume that will cause some kind of TLS catastrophe. I think it will be fine, but you may have an issue. You are returning a non-shared `VAL`, but your class is `shared`, which means `table`, and all the `VAL`

Re: Forked GC explained

2022-09-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/3/22 9:35 AM, frame wrote: I'm not sure I fully understand how it works. I know that the OS creates read only memory pages for both and if a memory section is about to be written, the OS will issue a copy of the pages so any write operation will be done in it's own copy and cannot mess up

Re: Error while generate DNA with uniform()

2022-09-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/3/22 8:09 AM, Salih Dincer wrote: Hi All, We discovered a bug yesterday and reported it: https://forum.dlang.org/thread/mailman.1386.1662137084.31357.digitalmars-d-b...@puremagic.com You know, there is `generate()` depend to `std.range`. It created the error when we use it with the

<    1   2   3   4   5   6   7   8   9   10   >