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 `shared

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: " ~ t

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

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

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

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

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: isRandomAccessRange

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)

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("ROLL

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

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

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

Re: Comparing Exceptions and Errors

2022-06-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/5/22 8:45 AM, kdevel wrote: On Sunday, 5 June 2022 at 01:43:06 UTC, Steven Schveighoffer wrote: [...] But you aren't perfect, and so maybe you make a mistake, and trigger an Error. The compiler handles this unexpected condition by unwinding the stack back to the main function, printing

Re: Comparing Exceptions and Errors

2022-06-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/4/22 9:43 PM, Steven Schveighoffer wrote: But I think you are still not supposed to continue execution. I'm not sure what a compiler might assume at this point, and I unfortunately can't find in the language specification where it states this. It might not be in there at all, the spec

Re: Comparing Exceptions and Errors

2022-06-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/4/22 6:56 PM, kdevel wrote: On Saturday, 4 June 2022 at 16:55:31 UTC, Steven Schveighoffer wrote: [...] The point of an `Error` is that your code can assume it cannot happen. If it does happen, the code is invalid. According to my favorite dictionary "assume" means "take f

Re: Comparing Exceptions and Errors

2022-06-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/4/22 2:46 PM, Ola Fosheim Grøstad wrote: On Saturday, 4 June 2022 at 18:32:48 UTC, Sebastiaan Koppe wrote: Most wont throw a Error though. And typical services have canary releases and rollback. So you just fix it, which you have to do anyway. I take it you mean manual rollback, but

Re: Comparing Exceptions and Errors

2022-06-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/4/22 7:57 AM, kdevel 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. Feedback welcome, I didn't

Re: Comparing Exceptions and Errors

2022-06-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/3/22 8:44 PM, Ali Çehreli wrote: One feedback I have is about non-main threads. Although everybody agrees that Errors should not be caught, the main thread does so and prints the useful output that you show in the article. Yes, the one exception to the no-catch error rule is to print/log

Comparing Exceptions and Errors

2022-06-04 Thread Steven Schveighoffer via Digitalmars-d-learn
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. Feedback welcome, I didn't announce here when I wrote it because it's kind of small/insignificant, but maybe it can help newcomers to

Re: Dynamic Arrays Capacity

2022-06-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/2/22 1:04 AM, Salih Dincer wrote: Hi, Do I misunderstand? A dynamic array is allocated memory according to the `nextpow2()` algorithm(-1 lapse); strings, on the other hand, don't behave like this... ```d   string str = "0123456789ABCDEF";   char[] chr = str.dup;   assert(str.length

Re: gdc 12.1: undefined references when linking separately compiled files

2022-05-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/28/22 10:44 AM, Adam D Ruppe wrote: On Saturday, 28 May 2022 at 14:16:51 UTC, kdevel wrote: $ gdc -o ppinsta ppinsta.d parser.d Compiling together is faster anyway this is prolly what you want most the time. But I know what's going on now, it is the template emission thing, the

Re: Why is the compiled file size so huge?

2022-05-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/27/22 9:40 AM, Alexander Zhirov wrote: I'm trying to compile a file that weighs 3 kilobytes. I'm also linking a self-written dynamic library. I don't understand why the resulting executable file is so huge? After all, all libraries are present: ```sh -rwxr-xr-x 1 root root 6.3M May 27

Re: Cannot check function address

2022-05-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/25/22 6:55 AM, user1234 wrote: On Wednesday, 25 May 2022 at 06:04:10 UTC, frame wrote: On Wednesday, 25 May 2022 at 05:56:28 UTC, Steven Schveighoffer wrote: It's a case where the compiler can't divine what you were thinking when you wrote that code ;) I see not in all cases

Re: Cannot check function address

2022-05-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/25/22 1:40 AM, frame wrote: This would have been more visible if the compiler just says: "function cannot be compared against null, only function pointer". That function vs function pointer is too subtle. It's a case where the compiler can't divine what you were thinking when you

Re: Cannot check function address

2022-05-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/25/22 12:16 AM, frame wrote: On Wednesday, 25 May 2022 at 03:41:17 UTC, Steven Schveighoffer wrote: This is a compiler bug, at least I think so. Since the compiler is misbehaving, it's not clear how to make it behave. -Steve Well, ok, it's not my top priority and dustmite seems to run

Re: Cannot check function address

2022-05-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/24/22 11:14 PM, frame wrote: On Wednesday, 25 May 2022 at 02:42:26 UTC, Steven Schveighoffer wrote: try: pragma(msg, typeof(fun)); Outputs: ``` extern (C) void function(...) ``` OK, so it's a function pointer. But the compiler would complain if I call it as a type? And how could

Re: Cannot check function address

2022-05-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/24/22 10:06 PM, frame wrote: Sorry, this was not affront, it was meant as my POV that you may have problems to get my problem because I have (as usually) forgot to make this more visible that some code was truncated. OK, sorry to read into that ;) I tried your suggestion, as replied

Re: How to fix "typesafe variadic function parameter"?

2022-05-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/24/22 6:54 PM, Andrey Zherikov wrote: On Tuesday, 24 May 2022 at 22:51:50 UTC, Adam Ruppe wrote: On Tuesday, 24 May 2022 at 22:46:55 UTC, Andrey Zherikov wrote: return S(s); return S(s.dup); The variadic lives in a temporary array that expires at the end of the function. So

Re: Cannot check function address

2022-05-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/24/22 6:10 PM, frame wrote: On Tuesday, 24 May 2022 at 19:09:52 UTC, Steven Schveighoffer wrote: This doesn't seem valid for module-level code, assert is an instruction, not a declaration. ... Try `std.traits.fullyQualifiedName!fun` to see where it's coming from. expected 5 got 0

Re: Implicit integer conversions Before Preconditions

2022-05-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/24/22 4:46 PM, jmh530 wrote: In the code below, `x` and `y` are implicitly converted to `uint` and `ushort` before the function preconditions are run. Is there any way to change this behavior? It feels unintuitive and I can't find in the spec where it says when the conversions in this

Re: Cannot check function address

2022-05-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/24/22 3:09 PM, Steven Schveighoffer wrote: assert is an instruction, not a declaration. errr it's a *statement*, not a declaration. -Steve

Re: Cannot check function address

2022-05-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/24/22 2:54 PM, frame wrote: I have a function slot that may be loaded via a shared library. I want to check if that function has an address but compiler (DMD 2.100, Windows) instead tries to invocate the function? ```d // --- module a: alias F = extern (C) void function(string param); F

Re: How to call destroy() in @nogc?

2022-05-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/23/22 10:29 PM, cc wrote: ```d import core.memory; import core.stdc.stdlib : malloc, free; import core.lifetime : emplace; T NEW(T, Args...)(auto ref Args args) /*@nogc*/ if (is(T == class)) { enum size = __traits(classInstanceSize, T); void* mem = malloc(size);

Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/19/22 8:29 PM, Steven Schveighoffer wrote: Given a CTFE function it's very easy to wrap for ensuring compile-time usage: ```d enum ctGrey(float f) = grey(f); auto myColor = ctGrey!(0.5); ``` That being said, if it's calculatable at compile time, chances are the compiler is already

Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/19/22 8:12 PM, Chris Katko wrote: On Thursday, 19 May 2022 at 10:35:30 UTC, ag0aep6g wrote: On 19.05.22 12:15, Chris Katko wrote: given ```D struct COLOR { float r, g, b, a; // a is alpha (opposite of transparency) } auto red   = COLOR(1,0,0,1); auto green = COLOR(0,1,0,1); auto blue  =

Re: class destructors must be @disabled?

2022-05-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/18/22 3:58 PM, Ali Çehreli wrote: Hmm. Perhaps the guideline should be "all destructors must be @nogc". That one I agree with. -Steve

Re: class destructors must be @disabled?

2022-05-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/18/22 2:58 PM, H. S. Teoh wrote: On Wed, May 18, 2022 at 02:35:00PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] No. Class destructors are for cleaning up non-GC resources. As long as you stick to those, you can safely run them. Structs that get put into classes have

Re: class destructors must be @disabled?

2022-05-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/18/22 2:02 PM, Ali Çehreli wrote: Of course, we still should and do have the power to shape our programs any way we want but I think '@disable ~this();' should be added to classes as a general rule unless the programmer knows it will work otherwise. What do you think? No. Class

Re: I need to use delete as the method name. But now it's still a keyword, right?

2022-05-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/18/22 2:13 AM, bauss wrote: On Wednesday, 18 May 2022 at 02:12:42 UTC, zoujiaqing wrote: https://dlang.org/changelog/2.100.0.html#deprecation_delete My code: ```D import std.stdio; class HttpClient { string get(string url) {     return ""; } string delete(string

Re: decimal type in d

2022-05-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/15/22 9:26 AM, vit wrote: Hello, I want read decimal type from sql db, do some arithmetic operations inside D program and write it back to DB. Result need to be close to result as if this operations was performed in sql DB. Something like C# decimal. Exists this kind of library ind D?

Re: Error: variable `impl` cannot be modified at compile time

2022-05-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/13/22 3:46 PM, Steven Schveighoffer wrote: What writeln? Your compile trace is missing the original call line, and I would say probably more. Looking at your last commit, I figured it out: https://github.com/kerisy/archttp/blob/545b3eb738261e92c88b4e4bb664b4fdfb206398/source/archttp

Re: Error: variable `impl` cannot be modified at compile time

2022-05-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/13/22 3:39 PM, zoujiaqing wrote: ```bash % git clone https://github.com/kerisy/archttp.git % cd archttp/ % dub build --compiler=dmd Performing "debug" build using dmd for x86_64. archttp 0.0.1+commit.3.g70d44ef: building configuration "library"...

Re: What are (were) the most difficult parts of D?

2022-05-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/13/22 2:29 PM, Adam D Ruppe wrote: On Friday, 13 May 2022 at 18:23:58 UTC, H. S. Teoh wrote: On Thu, May 12, 2022 at 11:45:47PM +, Guillaume Piolat via It's a problem because it goes from solving "no accidental race condition" and you get "people forget to add shared or __gshared and

Re: What are (were) the most difficult parts of D?

2022-05-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/12/22 11:18 AM, jmh530 wrote: On Thursday, 12 May 2022 at 12:13:32 UTC, Basile B. wrote: [snip] ``` is ( Type : TypeSpecialization , TemplateParameterList ) is ( Type == TypeSpecialization , TemplateParameterList ) is ( Type Identifier : TypeSpecialization , TemplateParameterList ) is (

Re: What are (were) the most difficult parts of D?

2022-05-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/11/22 9:06 PM, Christopher Katko wrote: I just realized foreach copies by value by default. Maybe. Sometimes. When? I don't even know anymore. Because I "thought" I had to use foreach(ref) to be able to affect the original data structure (because by value means its a copy, right?).

Re: Why isn't my dynamic array method doesn't work for this type?

2022-05-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/5/22 4:27 PM, rempas wrote: On Thursday, 5 May 2022 at 14:20:49 UTC, Steven Schveighoffer wrote: Your assignment operator does nothing. Thanks! That was indeed the problem! In the other data structures, it worked without needing explicitly provide one so I didn't thought about

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