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

Re: how to install the new dmd on Mac M1?

2022-08-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/25/22 11:50 PM, MichaelBi wrote: you are right, the package install is OK. but after running dub build --compiler=dmd, the error of "ld: library not found for - lssl" is still there... I've not had problems since updating to the M1, but my system was upgraded through many years, so I

Re: how to install the new dmd on Mac M1?

2022-08-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/25/22 10:44 AM, MichaelBi wrote: On Thursday, 25 August 2022 at 14:37:01 UTC, Steven Schveighoffer wrote: On 8/25/22 10:19 AM, MichaelBi wrote: I downloaded the new dmd 2.1 on Mac, but with fail message of "unsupported Arch arm64". how can I do? thanks. DMD is x86 only. M1 macs can run

Re: how to install the new dmd on Mac M1?

2022-08-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/25/22 10:19 AM, MichaelBi wrote: I downloaded the new dmd 2.1 on Mac, but with fail message of "unsupported Arch arm64". how can I do? thanks. DMD is x86 only. M1 macs can run x86 via rosetta. I haven't had this specific problem. Can you list the actual commands you are running, and the

Re: How to escape control characters?

2022-08-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/23/22 6:09 AM, Bastiaan Veelo wrote: On Thursday, 31 March 2016 at 03:15:49 UTC, cy wrote: This might be a dumb question. How do I format a string so that all the newlines print as \n and all the tabs as \t and such? The easiest is this: ```d import std.conv; string str = `Hello "World"

Re: Is it possible to return mutable and const range from a single method?

2022-08-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/22/22 12:36 PM, realhet wrote: Hello, I managed to make a universal getParent() function which can preserve constness. I also had success with inout functions that work with this inout getParent method. Is it possible to do something like this but for the allParents input range producer

Re: typeof(func!0) != typeof(func!0())

2022-08-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/22/22 12:19 PM, Andrey Zherikov wrote: On Monday, 22 August 2022 at 15:20:46 UTC, Paul Backus wrote: On Monday, 22 August 2022 at 14:43:24 UTC, Andrey Zherikov wrote: But the question is still opened: why is `typeof(U().func!0)` not the same as `typeof(U().func!0())`? Probably because

Re: typeof(func!0) != typeof(func!0())

2022-08-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/22/22 8:04 AM, Paul Backus wrote: On Monday, 22 August 2022 at 11:24:59 UTC, Andrey Zherikov wrote: On Monday, 22 August 2022 at 06:01:11 UTC, JG wrote: Why not just change to: alias type = typeof(U().func!0()); This is user's code and `U().func!0` is legit syntax. Workaround: wrap it

Re: "Error: no property `offsetof` for type `char*`"

2022-08-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/19/22 12:36 PM, MyNameHere wrote: On Friday, 19 August 2022 at 14:30:50 UTC, kinke wrote: Oh and `DevicePath()` is a convenience member returning a pointer to the 'dynamic array' (as the array decays to a pointer in C too), so no need to fiddle with `.offsetof` and computing the pointer

Re: "Error: no property `offsetof` for type `char*`"

2022-08-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/19/22 9:49 AM, MyNameHere wrote: Thank you, that seems to have resolved the issue, though I wish these sorts of problems would stop cropping up, they are souring the experience with the language. Most likely that "member" is a macro in C. D doesn't have macros, so it uses properties.

Re: In-place extension of arrays only for certain alignment?

2022-08-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/18/22 1:16 AM, Ali Çehreli wrote: On 8/17/22 19:27, Steven Schveighoffer wrote: > On 8/17/22 10:09 PM, Ali Çehreli wrote: >>  > IIRC, your data does not need to be sequential in *physical memory*, >>  > which means you can use a ring buffer that is segmented instead of >>  > virtually

Re: In-place extension of arrays only for certain alignment?

2022-08-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/17/22 10:09 PM, Ali Çehreli wrote: > IIRC, your data does not need to be sequential in *physical memory*, > which means you can use a ring buffer that is segmented instead of > virtually mapped, and that can be of any size. I thought about that as well. But I would like the sizes of

Re: In-place extension of arrays only for certain alignment?

2022-08-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/17/22 2:40 PM, Ali Çehreli wrote: On 8/16/22 19:33, Steven Schveighoffer wrote: Using a 16-byte block sounds like a good strategy at first because nobody knows whether an array will get more than one element. However, if my guess is correct (i.e. the first element of size of 16-bytes

Re: Compile time int to string conversion in BetterC

2022-08-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/17/22 6:38 AM, Dennis wrote: On Wednesday, 17 August 2022 at 08:44:30 UTC, Ogi wrote: Maybe I’m missing something? I had the same problem, and came up with the following trick: ```D enum itoa(int i) = i.stringof; ``` I have the same thing in my code: ```d enum intStr(int x) =

Re: In-place extension of arrays only for certain alignment?

2022-08-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/16/22 4:53 PM, Ali Çehreli wrote: On 8/16/22 12:31, Steven Schveighoffer wrote: > > No, it's based on 2 factors: > > 1. Is it a page-size-or-greater block? I assume the length of the new block. No, the length of the *existing* block. Everything in the memory allocator is in terms of

Re: In-place extension of arrays only for certain alignment?

2022-08-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/16/22 2:11 PM, Ali Çehreli wrote: Related to my DConf 2022 lightning talk, I am noticing that D runtime's in-place array extension optimization is available only for array data that are at certain memory alignments. No, it's based on 2 factors: 1. Is it a page-size-or-greater block?

Re: How long will DUB update a package from github release?

2022-08-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/15/22 10:12 PM, Domain wrote: The project [Lumars](https://code.dlang.org/packages/lumars) has released a new version 10 days ago in [github](https://github.com/BradleyChatha/lumars). But still unavailable in DUB. It should be done automatically, but this has been an intermittent

Re: Programs in D are huge

2022-08-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/16/22 4:25 AM, Diego wrote: Hello everyone, I'm a Java programmer at work but i'm learning D for pleasure. I'm reading _The D Programming Language by Ali Çehreli_. I noticed that DMD creates very huge executable, for example an empty program: ``` empty.d: void main() { } ``` after

Re: Array Wierdness

2022-08-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/10/22 11:26 AM, Ruby The Roobster wrote: On Wednesday, 10 August 2022 at 15:19:41 UTC, Ruby The Roobster wrote: Take the following code: ```d void main() {     shared class C { bool opEquals(const(shared(C)) rhs) const shared { return true;}}     const(C) c = new C();     const(C)[] a

Re: Cast converts AA to rvalue?

2022-08-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/9/22 7:02 PM, Johan wrote: Testcase: ``` shared int[int] aa; void main () {     cast()aa[1] = 1; } ``` Up to dlang 2.097, this program runs and works fine. Since dlang 2.098, the program errors with: `core.exception.RangeError@/app/example.d(3): Range violation` I think the 2.098+

Re: Acess variable that was set by thread

2022-08-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/8/22 4:04 PM, ag0aep6g wrote: On Monday, 8 August 2022 at 19:33:14 UTC, Steven Schveighoffer wrote: There's nothing clever. If you want to access C globals, you should use `__gshared`, because that's what it is. Using `shared`, isn't going to save you at all. Yes, using `shared` does

Re: Acess variable that was set by thread

2022-08-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/8/22 10:54 AM, ag0aep6g wrote: On Monday, 8 August 2022 at 14:29:43 UTC, Steven Schveighoffer wrote: C has no notion of shared, so it's not the right type. Putting `shared` on it is kind of lying, and can lead to trouble. Better to be explicit about what it is. Nonsense. Putting

Re: Acess variable that was set by thread

2022-08-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/8/22 10:12 AM, ag0aep6g wrote: On Monday, 8 August 2022 at 13:31:04 UTC, Steven Schveighoffer wrote: On 8/8/22 6:17 AM, ag0aep6g wrote: [...] Never ever use `__gshared` ever. It's a glaring safety hole. Use `shared` instead. If you are interfacing with C, you need __gshared. But yeah,

Re: How do I initialize a templated constructor?

2022-08-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/8/22 9:36 AM, Steven Schveighoffer wrote: On 8/8/22 1:38 AM, rempas wrote: In the following struct (as an example, not real code): ``` struct TestArray(ulong element_n) {    int[element_n] elements;    this(string type)(ulong number) { pragma(msg, "The type is: " ~

Re: How do I initialize a templated constructor?

2022-08-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/8/22 1:38 AM, rempas wrote: In the following struct (as an example, not real code): ``` struct TestArray(ulong element_n) {   int[element_n] elements;   this(string type)(ulong number) {     pragma(msg, "The type is: " ~ typeof(type).stringof);   } } ``` I want to create it and be

Re: Fix template parameter

2022-08-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/8/22 8:02 AM, Dom Disc wrote: Hello. I found in the documentation functions declared like this: ```D pure @nogc @safe BigInt opAssign(T : BigInt)(T x); ``` What is the difference to declaring it like: ```D pure @nogc @safe BigInt opAssign(BigInt x); ``` To me the first declaration seems

Re: Acess variable that was set by thread

2022-08-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/8/22 6:17 AM, ag0aep6g wrote: On Monday, 8 August 2022 at 07:14:33 UTC, vc wrote: it seems change it to working is working ```d  __gshared bool zeus;  ``` but as I'm new in to D, i will like to hear thoughts even if it works for me Never ever use `__gshared` ever. It's a glaring

Re: Acess variable that was set by thread

2022-08-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/7/22 9:36 PM, vc wrote: Hello, i have the following code, the flora contains a boolean zeus in the DerivedThread the boolean zeus was set to true; but when i'm trying to access it outside the thread in main it returns me false; any thoughts ? is zeus declared just as: ```d bool zeus;

Re: Main foreach loop fails when another foreach is added

2022-08-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/7/22 10:11 PM, ikelaiah wrote: Hi, I'm writing a program that reads a text file and launch my work URLs in it. It worked fine, and very happy. Then I added another `foreach` loop to count total number of lines. After this, the main `foreach` won't work. Does anyone know as to why this

Re: Unittest Absurdity

2022-08-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/5/22 3:53 PM, frame wrote: On Friday, 5 August 2022 at 15:24:16 UTC, Steven Schveighoffer wrote: oof, I expected this to include the template parameters! I believe it normally does? This is a bug that should be filed. -Steve Sorry, I don't get what you takling about? The docs says:

Re: Unittest Absurdity

2022-08-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/5/22 11:24 AM, Steven Schveighoffer wrote: On 8/4/22 10:27 PM, jfondren wrote:  a.opOpAssign(b);  b.opOpAssign(a); oof, I expected this to include the template parameters! I believe it normally does? It does not! I'm genuinely shocked. ```d void foo(string s, T)(T t) {} void

Re: Unittest Absurdity

2022-08-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/4/22 10:27 PM, jfondren wrote: The output's not that useful... ```d import object; struct S { int n; void opOpAssign(string op)(S rhs) if (op == "/=") {     n++; } void opOpAssign(string op)(S rhs) if (op == "/") { } } unittest { S a = S(1);   

Re: Unittest Absurdity

2022-08-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/4/22 9:51 PM, Paul Backus wrote: On Friday, 5 August 2022 at 01:47:07 UTC, Ruby The Roobster wrote: I found the issue:  opOpAssign isn't getting called at all.  I have no idea why, though. Given that the example works, the problem must be in some other part of your code that you

Re: Converting JSONValue to AssociativeArray.

2022-08-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/1/22 2:00 PM, hype_editor wrote: I need to convert variable of type `JSONValue` to variable of type `string[string]` (AssociativeArray). ```d import std.json : JSONValue; import std.stdio : writefln; void main() {     JSONValue data = parseJSON(`{ "name": "Hype Editor", "hobby":

Re: Expanding CTFE code during compilation

2022-07-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/23/22 2:27 PM, Azi Hassan wrote: On Saturday, 23 July 2022 at 00:56:39 UTC, Steven Schveighoffer wrote: On 7/22/22 3:22 PM, Azi Hassan wrote: Oh, interesting syntax. I was thinking something along the lines of ```D template printEnum(...) { version(debug) { ... //

Re: OK to do bit-packing with GC pointers?

2022-07-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/22/22 2:34 PM, Ben Jones wrote: Can you elaborate on why it's probably OK in practice? Because the GC deals with interior pointers just fine. Blocks with the "no interior" bit set are very rare, and for only specialized use, so normally this should not be a problem. I have argued in

Re: Expanding CTFE code during compilation

2022-07-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/22/22 3:22 PM, Azi Hassan wrote: Oh, interesting syntax. I was thinking something along the lines of ```D template printEnum(...) {     version(debug) {     ... // everything we already did     } else {     enum printEnum(alias x) = x;     } } ``` But I like yours better.

Re: OK to do bit-packing with GC pointers?

2022-07-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/22/22 12:50 PM, Ben Jones wrote: I'm looking to store a pointer to one of 2 unrelated (no inheritance relationship) classes and use the LSb to track which type I have.  Is this going to cause any problems with the GC? For one of the classes I'll have a "pointer" to 1 byte past the start

Re: mixin template bug with opBinary?

2022-07-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/22/22 8:33 AM, Anthony Quizon wrote: Hello, I'm trying to create a mixin for quick binary operator overloads by passing in types with a corresponding associative array of strings to functions. However, the code I currently have: ``` module foo; mixin template opBi(     A, A

Re: Expanding CTFE code during compilation

2022-07-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/19/22 8:57 PM, Steven Schveighoffer wrote: There's a slight bloat in the compiler symbol table when  but other than that it should be effective. Obviously I didn't finish that thought... "when `-debug` isn't used on the command line" -Steve

Re: Expanding CTFE code during compilation

2022-07-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/19/22 8:33 PM, Azi Hassan wrote: Nice, a compile time console.log. Thanks a lot, this will come in handy. I wonder if it can be combined with version(debug) to only run the pragma line if compiled with -g, this way we can keep the printEnum! line as it is. Then again, the code would

Re: Expanding CTFE code during compilation

2022-07-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/19/22 5:43 PM, Azi Hassan wrote: Just in case this is a consequence of the XY problem, the reason why I'm looking for this is to make sure that the code I wrote did evaluate to what I'm expecting it to. Right now I do this with an enum assignment followed by static asserts, but I'd love

Re: File.write introduces \r regardless of presence

2022-07-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 16 July 2022 at 20:46:00 UTC, HuskyNator wrote: is raises 3 questions for me. 1. Are there any nasty pitfalls with this change that might force me to find a workaround? (eg. en/decoding issues or the like?) This is strictly a C mechanism, and only on Windows. So refer to the C

Re: null == "" is true?

2022-07-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 15 July 2022 at 06:38:58 UTC, Salih Dincer wrote: Consider null type array which is a related topic but it cannot get a null element! The first is ok, but the second is legal. So no effect, is it normal? ```d auto p = [ null, null ];//* assert( is(typeof(null)[] :

Re: null == "" is true?

2022-07-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/12/22 4:36 PM, Antonio wrote: On Tuesday, 12 July 2022 at 18:56:43 UTC, Paul Backus wrote: On Tuesday, 12 July 2022 at 16:40:38 UTC, H. S. Teoh wrote: Because an empty string is, by default, represented by an empty slice of the null pointer. Do not rely on this, however; it's possible

Re: null == "" is true?

2022-07-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/12/22 12:40 PM, H. S. Teoh wrote: Because an empty string is, by default, represented by an empty slice of the null pointer. No, it's not a null pointer. It's a pointer to a zero-character. But it is indeed an empty slice. -Steve

Re: null == "" is true?

2022-07-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/12/22 12:27 PM, Antonio wrote: It works ```d void main() {    assert(null==""); } ``` why? A string is not exactly a reference type. It's a length and a pointer. This can be confusing to newcomers, especially ones that come from languages that treat arrays and strings as object

Re: Is there any implementation of a 128bit integer?

2022-07-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/10/22 8:19 PM, Era Scarecrow wrote: On Friday, 8 July 2022 at 15:32:44 UTC, Rob T wrote: https://forum.dlang.org/post/mailman.10914.1566237225.29801.digitalmars-d-le...@puremagic.com In case someone comes across this old thread https://dlang.org/phobos/core_int128.html There was a

Re: Calling readln() after readf

2022-07-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/5/22 8:14 PM, Gary Chike wrote: On Monday, 20 June 2022 at 16:08:33 UTC, Ali Çehreli wrote: On 6/20/22 07:00, Gary Chike wrote: > Would it be appropriate to forego `readf` > and read input as a string using `readln` ,benefiting from the `strip` > function, then convert to their

Re: ePub/Mobi/AZW3/PDF of Phobos Runtime Library

2022-06-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/28/22 2:42 PM, Marcone wrote: I love programming in D. D is my favorite programming language. I'm not a professional programmer, but I love to program. I would like to learn D deeply. Most programming languages have a PDF/CHM/MOBI/ePub version of the standard library. But D still doesn't

Re: int | missing | absent

2022-06-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/27/22 9:03 AM, Antonio wrote: On Wednesday, 22 June 2022 at 01:09:22 UTC, Steven Schveighoffer wrote: On 6/2/22 9:24 AM, bauss wrote: I feel it's too loose to make a best effort, and leave the rest up to initial values, or just ignore possibly important information during parsing.

Re: int | missing | absent

2022-06-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/23/22 11:20 AM, Jesse Phillips wrote: On Wednesday, 22 June 2022 at 01:09:22 UTC, Steven Schveighoffer wrote: There are 3 situations: 1. field in json and struct. Obvious result. 2. field in json but not in struct. 3. field in struct but not in json. I do a lot of reading JSON data in

Re: nested function overloading

2022-06-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/22/22 2:05 AM, monkyyy wrote: On Monday, 20 June 2022 at 13:20:51 UTC, Steven Schveighoffer wrote: And you can also use an inner struct to define overloaded functions. I believe templates make a better bandaid ```d void main(){ template bar(){     void bar_(int){}     void

Re: int | missing | absent

2022-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/2/22 9:24 AM, bauss wrote: On Thursday, 2 June 2022 at 08:27:32 UTC, Antonio wrote: JSON properties can be - a value - null - absent What's the standard way to define a serialziable/deserializable structs supporting properties of any of this 4 kinds?: * int * int | null * int | absent

Re: destroy and @safe

2022-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/21/22 1:33 PM, H. S. Teoh wrote: On Tue, Jun 21, 2022 at 01:29:47PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: ```d void foo(void delegate() @system dg) @safe { int *bar; @system void corrupt() { bar = cast(int *)0xdeadbeef;} dg = // can I call dg now

Re: Better way to achieve the following

2022-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/21/22 1:19 PM, JG wrote: On Tuesday, 21 June 2022 at 17:15:02 UTC, Steven Schveighoffer wrote: On 6/21/22 1:09 PM, JG wrote: Thoughts? Use a pointer? Especially if you are using `.method` calls, this just works seamlessly. Thanks for the suggestion.  My immediate reaction is that

Re: destroy and @safe

2022-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/21/22 1:17 PM, H. S. Teoh wrote: On Tue, Jun 21, 2022 at 04:47:44PM +, Antonio via Digitalmars-d-learn wrote: On Tuesday, 21 June 2022 at 16:20:32 UTC, Antonio wrote: My code starts to be a @safe/@trusted mess (because external libraries). The only solution I have is to "wrap" them

Re: Better way to achieve the following

2022-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/21/22 1:09 PM, JG wrote: Thoughts? Use a pointer? Especially if you are using `.method` calls, this just works seamlessly. -Steve

Re: destroy and @safe

2022-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/21/22 12:33 PM, Antonio wrote: On Tuesday, 21 June 2022 at 15:14:43 UTC, Steven Schveighoffer wrote: You delegate doesn't seem to be marked @safe as well. Thanks a lot Steve, I didn't found a way (or example) to specify the delegate must be @safe until I have found

Re: destroy and @safe

2022-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/21/22 10:40 AM, Antonio wrote: I'm using explicitly destroy!false(obj) for a "deterministic" resources release. I replicate the c# "using" pattern, or the python "with" pattern with my own "use" template supposing object are RAII i.e.: ```d Item[] items = query("...").use( (Answer a)

Re: std.conv.to

2022-06-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/17/22 8:48 AM, harakim wrote: On Friday, 17 June 2022 at 12:31:45 UTC, harakim wrote: I can generically convert a string to a type using to!type. I have a read function that does that. I have simplified the example below: ```d int readNumber() {     return read!int(val =>

Re: nested function overloading

2022-06-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/17/22 8:09 AM, Chris Katko wrote: I don't need this functionality, but I wanted to be sure. Does function overloading not work with nested functions? I got a compiler error (something like "function already defined") when I tried it. Correct, it's not allowed. However, you can define a

Re: Comparing Exceptions and Errors

2022-06-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/16/22 6:07 AM, kdevel wrote: On Wednesday, 15 June 2022 at 20:46:56 UTC, Steven Schveighoffer wrote: [...] It has not harmed my code though. I tried throwing inside a scope guard, and it just works, I'm not sure why you can't throw in those? You can but that is not acceptable for

Re: Comparing Exceptions and Errors

2022-06-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/15/22 3:51 PM, kdevel wrote: On Wednesday, 15 June 2022 at 03:09:56 UTC, Steven Schveighoffer wrote: I don't see what you see wrong with the code I wrote. It's straightforward, obvious, and does the job I need it to do, in a way that's not prone to future mistakes. Sometimes it is not

Re: Comparing Exceptions and Errors

2022-06-14 Thread Steven Schveighoffer via Digitalmars-d-learn
I don't see what you see wrong with the code I wrote. It's straightforward, obvious, and does the job I need it to do, in a way that's not prone to future mistakes. I explained why, but you don't agree with the explanation. That's OK, we don't all have to write the same exact systems. D is a

Re: Bug?

2022-06-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/14/22 3:35 PM, JG wrote: Hi, Is this a bug? ```d import std; template test(alias f) {     auto test(I)(I i) { return f(i); } } void main() {     alias t = test!(x=>x+1);     1.t.writeln; //<--Doesn't compile     1.test!(x=>x+1).writeln;     t(1).writeln; } ``` Not a bug. Local

Re: Failure due to memcpy being called at compile time

2022-06-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/13/22 4:09 PM, JG wrote: Thanks. It seems to be something to do with the variadic template since this works: ```d import std; struct ParseError { string msg; } alias ParseErrorOr(T) = SumType!(ParseError,T); auto parseErrorOr(T)(T x) { return ParseErrorOr!T(x); } auto parserOr(I,alias

Re: Failure due to memcpy being called at compile time

2022-06-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/13/22 3:48 PM, JG wrote: Hi, I reduced my code to the following.  Could anyone help me to discover why the line marked with //THIS LINE causes memcpy to be called, and how can I avoid this? ```d import std; struct ParseError { string msg; } alias ParseErrorOr(T) =

Re: Dynamic chain for ranges?

2022-06-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/13/22 9:44 AM, Ola Fosheim Grøstad wrote: On Monday, 13 June 2022 at 13:22:52 UTC, Steven Schveighoffer wrote: I would think sort(joiner([arr1, arr2, arr3])) should work, but it's not a random access range. Yes, I got the error «must satisfy the following constraint:

Re: Comparing Exceptions and Errors

2022-06-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/13/22 9:15 AM, Steven Schveighoffer wrote: Yes. If you don't execute the rollback and start executing more DB calls, they all get included in the transaction (and might be expected to be). Should have said "might *not* be expected to be" -Steve

Re: Dynamic chain for ranges?

2022-06-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/13/22 4:51 AM, Ola Fosheim Grøstad wrote: Is there a dynamic chain primitive, so that you can add to the chain at runtime? Context: the following example on the front page is interesting. ```d void main() {     int[] arr1 = [4, 9, 7];     int[] arr2 = [5, 2, 1, 10];     int[] arr3 =

Re: Comparing Exceptions and Errors

2022-06-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/12/22 4:11 PM, kdevel wrote: On Tuesday, 7 June 2022 at 18:37:13 UTC, Steven Schveighoffer wrote: [...] My very common use of `scope(failure)` for my DB code: ```d conn.exec("START TRANSACTION"); scope(success) conn.exec("COMMIT"); scope(failure) conn.exec("ROLLBACK"); ``` Are there

Re: map! evaluates twice

2022-06-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/10/22 4:33 PM, Antonio wrote: When mapping and filtering, the last mapped element is evaluated twice... Is it the expected behaviour? ```d void main() {     import std.algorithm, std.stdio;     [1,2,3,4,5].     map!((x){     writeln("mapping ", x);     return x;

Re: Why allow initializers of non-static members that allocate?

2022-06-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/10/22 1:20 PM, Mike Parker wrote: On Friday, 10 June 2022 at 14:56:24 UTC, Steven Schveighoffer wrote: Discovered circa 2009: https://issues.dlang.org/show_bug.cgi?id=2947 It should be illegal to declare a field this way that has mutable references without being `shared`. End of story.

Re: Why allow initializers of non-static members that allocate?

2022-06-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/10/22 3:46 AM, Mike Parker wrote: On Friday, 10 June 2022 at 07:35:17 UTC, Bastiaan Veelo wrote: Is there a use case where this makes sense? I would have much appreciated the compiler slapping me on the fingers, but it doesn't. I understand that it is safe and that the compiler can allow

Re: C-like static array size inference - how?

2022-06-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/7/22 9:17 PM, forkit wrote: On Wednesday, 8 June 2022 at 01:11:45 UTC, Mike Parker wrote: ...The author withdrew the DIP .. That's a shame. Seems like a useful language feature. I'd be using it already if it existed. I agree, it's a pain to dig out an import and the verbose

Re: Comparing Exceptions and Errors

2022-06-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/7/22 3:58 PM, frame wrote: On Tuesday, 7 June 2022 at 18:37:13 UTC, Steven Schveighoffer wrote: My very common use of `scope(failure)` for my DB code: ```d conn.exec("START TRANSACTION"); scope(success) conn.exec("COMMIT"); scope(failure) conn.exec("ROLLBACK"); ``` This is hard to

Re: Comparing Exceptions and Errors

2022-06-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/7/22 12:28 PM, frame wrote: On Friday, 3 June 2022 at 23:40:50 UTC, Steven Schveighoffer wrote: During the last beerconf, I wrote a short blog post about how `Error` and `Exception` are different, and why you should never continue after catching `Error`s. I know the thematics but I

Re: want to confirm: gc will not free a non-gc-allocated field of a gc-allocated object?

2022-06-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/6/22 6:18 PM, mw wrote: Hi, Suppose I have this code: ``` class GCAllocated {   float[] data;   this() {     // non-gc-allocated field     this.data = cast(float[])(core.stdc.stdlib.malloc(nBytes)[0 .. nBytes]);   } } void foo() {   auto obj = new GCAllocated();  // gc-allocated

Re: What happened to Circular Studio?

2022-06-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/6/22 3:46 PM, Jack wrote: I just found out a game using D to develop games but later I see the last updates on the github, web site, twitter etc is from 2015. Does anyone knows what happend to the company? It appears to be just a playground for a bunch of friends at RIT, I'm not sure

Re: Comparing Exceptions and Errors

2022-06-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/6/22 12:15 PM, Ola Fosheim Grøstad wrote: On Monday, 6 June 2022 at 15:54:16 UTC, Steven Schveighoffer wrote: If it's an expected part of the sorting algorithm that it *may fail to sort*, then that's not an Error, that's an Exception. No, it is not expected. Let me rewrite my answer to

Re: Comparing Exceptions and Errors

2022-06-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/6/22 12:59 AM, Ola Fosheim Grøstad wrote: On Sunday, 5 June 2022 at 23:57:19 UTC, Steven Schveighoffer wrote: It basically says "If this condition is false, this entire program is invalid, and I don't know how to continue from here." No, it says: this function failed to uphold this

Re: Comparing Exceptions and Errors

2022-06-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/5/22 6:09 PM, kdevel wrote: On Sunday, 5 June 2022 at 20:53:32 UTC, Steven Schveighoffer wrote: [...] For this purpose nobody needs a separate subclass named `Error`. That works with `Exception`s. You can use Exceptions instead. But the difference is they are part of the program instead

Re: Comparing Exceptions and Errors

2022-06-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/5/22 12:27 PM, Ola Fosheim Grøstad wrote: Ok, so I am a bit confused about what is Error and what is not… According to core.exception there is wide array of runtime Errors: ``` RangeError ArrayIndexError ArraySliceError AssertError FinalizeError OutOfMemoryError

  1   2   3   4   5   6   7   8   9   10   >