Re: How get struct value by member name string ?

2023-06-02 Thread bauss via Digitalmars-d-learn
On Tuesday, 30 May 2023 at 15:43:12 UTC, Steven Schveighoffer wrote: On 5/30/23 4:46 AM, John Xu wrote: How to put above enum as a function parameter? Following code wouldn't work:     string getTMember(T t, enum string memberName) {     return __traits(getMember, t, memberName);     }

Re: How get struct value by member name string ?

2023-05-30 Thread bauss via Digitalmars-d-learn
On Tuesday, 30 May 2023 at 15:24:21 UTC, bauss wrote: On Tuesday, 30 May 2023 at 08:46:43 UTC, John Xu wrote: How to put above enum as a function parameter? Following code wouldn't work: string getTMember(T t, enum string memberName) { return __traits(getMember, t, memberName);

Re: How get struct value by member name string ?

2023-05-30 Thread bauss via Digitalmars-d-learn
On Tuesday, 30 May 2023 at 08:46:43 UTC, John Xu wrote: How to put above enum as a function parameter? Following code wouldn't work: string getTMember(T t, enum string memberName) { return __traits(getMember, t, memberName); } ... As simple as this: ``` string getTMember(T

Re: Is comparison of shared data thread-safe?

2023-03-17 Thread bauss via Digitalmars-d-learn
On Thursday, 16 March 2023 at 12:32:34 UTC, Nick Treleaven wrote: With -preview=nosharedaccess, I get: int y = 2; shared int x = y; // OK assert(x == 2); // no error y = x; // error So for the assignment to y, reading x is an error and atomicLoad should be used instead. But

Re: Mixin helper help

2023-01-16 Thread bauss via Digitalmars-d-learn
On Monday, 16 January 2023 at 08:17:24 UTC, Ali Çehreli wrote: On 1/13/23 18:51, bauss wrote: That's a good one! It looks like you liked it four years ago as well. :) I found where I remembered it from: https://forum.dlang.org/post/pvdoq2$1e7t$3...@digitalmars.com Ali Looks like my

Re: Mixin helper help

2023-01-13 Thread bauss via Digitalmars-d-learn
On Friday, 13 January 2023 at 16:54:34 UTC, Ali Çehreli wrote: On 1/13/23 00:48, bauss wrote: > 1. Change your mixin template to something like this: There was a technique as a workaround for this template mixin limitation but I can't find it right now. > 2. Change the place where you

Re: Mixin helper help

2023-01-13 Thread bauss via Digitalmars-d-learn
On Thursday, 12 January 2023 at 08:03:34 UTC, John Chapman wrote: I'm obviously doing something wrong, but don't quite understand. ```d mixin template helper() { mixin("writeln(12);"); } struct Foo { void opDispatch(string name)() { import std.stdio; mixin helper!();

Re: enum functions

2023-01-11 Thread bauss via Digitalmars-d-learn
On Tuesday, 10 January 2023 at 12:55:34 UTC, 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

Re: How to avoid variable capturing in `foreach` loop with lambdas?

2023-01-09 Thread bauss via Digitalmars-d-learn
On Monday, 9 January 2023 at 00:19:39 UTC, thebluepandabear wrote: Fixing this will improve the quality of the language for newcomers such as myself greatly. This not only confuses newcomers but it gave a false illusion of a bug within the code :/ It doesn't confuse newcomers only, also

Re: Is there a way to enforce UFCS?

2023-01-04 Thread bauss via Digitalmars-d-learn
On Wednesday, 4 January 2023 at 03:42:28 UTC, thebluepandabear wrote: ... My question is: is there a way to enforce UFCS-syntax? None of your code actually uses UFCS. This is UFCS: ``` class Foo { int bar; } void setBar(Foo foo, int value) { foo.bar = value; } void main() {

Re: How ptr arithmitic works??? It doesn't make any sense....

2022-12-05 Thread bauss via Digitalmars-d-learn
On Monday, 5 December 2022 at 06:12:44 UTC, rempas wrote: On Sunday, 4 December 2022 at 16:40:17 UTC, ag0aep6g wrote: Not quite. Adding 10 to a T* means adding 10 * T.sizeof. Oh! I thought it was addition. Is there a specific reasoning for that if you are aware of? Because it's much

Re: raylib-d Gamepad Detection Fails

2022-12-01 Thread bauss via Digitalmars-d-learn
On Thursday, 1 December 2022 at 15:35:37 UTC, Steven Schveighoffer wrote: 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

Re: raylib-d Gamepad Detection Fails

2022-12-01 Thread bauss via Digitalmars-d-learn
On Thursday, 1 December 2022 at 02:06:43 UTC, Steven Schveighoffer wrote: 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

Re: Get the class name without casting the type

2022-11-15 Thread bauss via Digitalmars-d-learn
On Tuesday, 15 November 2022 at 11:42:59 UTC, Alexander Zhirov wrote: Is there any way to get the name of class B? ```d interface A { string text(); } class B : A { override string text() { return ": It's ok!"; } } void main() { A[] a = cast(A[]) new B[3]; B b =

Re: Linking not working properly Windows 11

2022-11-06 Thread bauss via Digitalmars-d-learn
On Sunday, 6 November 2022 at 03:59:55 UTC, ryuukk_ wrote: Manually editing / moving files is not recommended for Visual Studio installs The manual editing was not for visual studio but for dmd to set a different linker.

Re: Linking not working properly Windows 11

2022-11-06 Thread bauss via Digitalmars-d-learn
On Saturday, 5 November 2022 at 22:53:33 UTC, Hipreme wrote: On Saturday, 5 November 2022 at 19:19:09 UTC, bauss wrote: On Saturday, 5 November 2022 at 14:54:52 UTC, Hipreme wrote: [...] I have both VS 2019 and 2022, but only 2019 has c++ build tools etc. I assume that should be fine?

Re: Linking not working properly Windows 11

2022-11-05 Thread bauss via Digitalmars-d-learn
On Saturday, 5 November 2022 at 19:24:54 UTC, Imperatorn wrote: On Saturday, 5 November 2022 at 13:30:43 UTC, bauss wrote: Fresh install of DMD and when trying to use ex. std.file from Phobos I get the following linking error: (I can trigger different ones depending on modules imported etc.)

Re: Linking not working properly Windows 11

2022-11-05 Thread bauss via Digitalmars-d-learn
On Saturday, 5 November 2022 at 14:54:52 UTC, Hipreme wrote: On Saturday, 5 November 2022 at 14:14:16 UTC, bauss wrote: On Saturday, 5 November 2022 at 13:42:08 UTC, rikki cattermole wrote: Try ldc, if that works then its just a missing library that needs to be linked against regarding MS CRT.

Re: Linking not working properly Windows 11

2022-11-05 Thread bauss via Digitalmars-d-learn
On Saturday, 5 November 2022 at 13:42:08 UTC, rikki cattermole wrote: Try ldc, if that works then its just a missing library that needs to be linked against regarding MS CRT. Using LDC doesn't seem to work either, it has similar linking problems. ``` lld-link: error: undefined symbol:

Re: Linking not working properly Windows 11

2022-11-05 Thread bauss via Digitalmars-d-learn
On Saturday, 5 November 2022 at 13:42:08 UTC, rikki cattermole wrote: Try ldc, if that works then its just a missing library that needs to be linked against regarding MS CRT. I will give it a try

Re: Linking not working properly Windows 11

2022-11-05 Thread bauss via Digitalmars-d-learn
On Saturday, 5 November 2022 at 13:30:43 UTC, bauss wrote: ``` lld-link: error: undefined symbol: tzset ``` I don't know if this is relevant, so I will just put it here just in case: ``` lld-link: error: undefined symbol: tzset referenced by

Linking not working properly Windows 11

2022-11-05 Thread bauss via Digitalmars-d-learn
Fresh install of DMD and when trying to use ex. std.file from Phobos I get the following linking error: (I can trigger different ones depending on modules imported etc.) ``` lld-link: error: undefined symbol: tzset ``` I assume it has something to do with the C runtime or something, but

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

2022-11-04 Thread bauss via Digitalmars-d-learn
On Friday, 4 November 2022 at 10:57:12 UTC, Hipreme wrote: ... I disagree completely with being against package.d. Having used D for like a decade at this point, I've never experienced any issues with it. Most issues seems to be for newcomers and people who aren't entirely familiar with

Re: is dmd a virus?

2022-10-22 Thread bauss via Digitalmars-d-learn
On Saturday, 22 October 2022 at 07:40:39 UTC, MGW wrote: is dmd a virus? https://www.virustotal.com report: Cybereason --> Malicious.779f29 VBA32 --> BScope.Trojan.DShell Yeah it's a virus. I would stay far away from it...

Re: Float rounding (in JSON)

2022-10-14 Thread bauss via Digitalmars-d-learn
On Friday, 14 October 2022 at 09:00:11 UTC, Patrick Schluter wrote: On Thursday, 13 October 2022 at 19:27:22 UTC, Steven Schveighoffer wrote: On 10/13/22 3:00 PM, Sergey wrote: [...] It doesn't look really that far off. You can't expect floating point parsing to be exact, as floating point

Re: Replacing tango.text.Ascii.isearch

2022-10-13 Thread bauss via Digitalmars-d-learn
On Thursday, 13 October 2022 at 08:48:49 UTC, rikki cattermole wrote: On 13/10/2022 9:42 PM, bauss wrote: Oh and to add onto this, IFF you have to do it the hacky way, then converting to uppercase instead of lowercase should be preferred, because not all lowercase characters can perform round

Re: Replacing tango.text.Ascii.isearch

2022-10-13 Thread bauss via Digitalmars-d-learn
On Thursday, 13 October 2022 at 08:35:50 UTC, bauss wrote: On Thursday, 13 October 2022 at 08:30:04 UTC, rikki cattermole wrote: On 13/10/2022 9:27 PM, bauss wrote: This doesn't actually work properly in all languages. It will probably work in most, but it's not entirely correct. Ex. Turkish

Re: Replacing tango.text.Ascii.isearch

2022-10-13 Thread bauss via Digitalmars-d-learn
On Thursday, 13 October 2022 at 08:30:04 UTC, rikki cattermole wrote: On 13/10/2022 9:27 PM, bauss wrote: This doesn't actually work properly in all languages. It will probably work in most, but it's not entirely correct. Ex. Turkish will not work with it properly. Very interesting article:

Re: Replacing tango.text.Ascii.isearch

2022-10-13 Thread bauss via Digitalmars-d-learn
On Wednesday, 5 October 2022 at 17:29:25 UTC, Steven Schveighoffer wrote: 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

Re: Doubt about char.min/max == typeid(char)

2022-10-06 Thread bauss via Digitalmars-d-learn
On Friday, 7 October 2022 at 04:40:26 UTC, matheus wrote: Hmm well I was thinking the min/max as a range/limits, in this case 0 to 255 or it could be -128 to 127 if signed char casts implicitly to int, so if you really need it as an integer type just type your variable as such. ```d int a

Re: Disk write in a "for" loop with RwMutex never happens

2022-08-29 Thread bauss via Digitalmars-d-learn
On Sunday, 28 August 2022 at 22:46:17 UTC, Gavin Ray wrote: I've put the code, stripped to a minimal example here: - https://ldc.godbolt.org/z/fzsx3Tnnn You can see that the single write + read version of the code works just fine: ``` pageData[0..4] = [1, 2, 3, 4] readData[0..4] = [1, 2, 3,

Re: How to build DMD/Phobos on Windows

2022-08-25 Thread bauss via Digitalmars-d-learn
On Wednesday, 24 August 2022 at 21:11:42 UTC, rikki cattermole wrote: For dmd you use build.d that is in the repository. For phobos win64.mak (used for 32bit by default as well): "# Makefile to build D runtime library phobos{64,32mscoff}.lib for Windows MSVC" So MSVC make. Beyond that idk,

Re: Compile time int to string conversion in BetterC

2022-08-19 Thread bauss via Digitalmars-d-learn
On Friday, 19 August 2022 at 13:47:41 UTC, Paul Backus wrote: On Friday, 19 August 2022 at 10:22:25 UTC, bauss wrote: Is there a reason why .stringof is implementation defined and not clearly defined in the spec how types and declarations should be treated when being "converted to a string"?

Re: Programs in D are huge

2022-08-19 Thread bauss via Digitalmars-d-learn
On Friday, 19 August 2022 at 06:34:19 UTC, Patrick Schluter wrote: On Thursday, 18 August 2022 at 17:15:12 UTC, rikki cattermole wrote: On 19/08/2022 4:56 AM, IGotD- wrote: BetterC means no arrays or strings library and usually in terminal tools you need to process text. Full D is wonderful

Re: Compile time int to string conversion in BetterC

2022-08-19 Thread bauss via Digitalmars-d-learn
On Thursday, 18 August 2022 at 22:00:06 UTC, Paul Backus wrote: On Wednesday, 17 August 2022 at 11:38:31 UTC, Steven Schveighoffer wrote: 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

Re: Acess variable that was set by thread

2022-08-08 Thread bauss via Digitalmars-d-learn
On Monday, 8 August 2022 at 13:55:02 UTC, ag0aep6g wrote: auto x = s.x; ``` Your problem is here and not because it was __gshared. You're copying the value and obviously it can be changed in the meantime, that's common sense. You shouldn't use it like that. You should access s.x

Re: Fix template parameter

2022-08-08 Thread bauss via Digitalmars-d-learn
On Monday, 8 August 2022 at 12:02:02 UTC, Dom Disc wrote: ```D pure @nogc @safe BigInt opAssign(T : BigInt)(T x); ``` This will only be included in the object file if used. What is the difference to declaring it like: ```D pure @nogc @safe BigInt opAssign(BigInt x); ``` This will

Re: Acess variable that was set by thread

2022-08-08 Thread bauss via Digitalmars-d-learn
On Monday, 8 August 2022 at 10:17:57 UTC, ag0aep6g wrote: Never ever use `__gshared` ever. I don't agree with this entirely, it just depends on how you use it. In general you should go with shared, but __gshared does have its places. It's only problematic when it can be changed from

Re: How do I initialize a templated constructor?

2022-08-08 Thread bauss via Digitalmars-d-learn
On Monday, 8 August 2022 at 07:37:16 UTC, rempas wrote: Thank you for all the great info! Unfortunately, while there is no problem in this example, this will not do for my real code as I need to have the argument in the constructor. Alternative, I have to change the design of the program

Re: Verbosity in D

2022-08-08 Thread bauss via Digitalmars-d-learn
On Monday, 8 August 2022 at 00:11:33 UTC, pascal111 wrote: I don't have specific code but it was a general notice. Take Python as in example, the same program in Python doesn't cost much code as D code, and of course by putting in accounts that that I assume that there are some special tasks

Re: How do I initialize a templated constructor?

2022-08-08 Thread bauss via Digitalmars-d-learn
On Monday, 8 August 2022 at 05:38:31 UTC, 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

Re: vectorization of a simple loop -- not in DMD?

2022-07-12 Thread bauss via Digitalmars-d-learn
On Tuesday, 12 July 2022 at 10:32:36 UTC, ryuukk_ wrote: How do i achieve fast compile speed (results above were on windows, on linux i get much faster results): I maintain healthy project management: This - Imports of std: i simply don't, and i copy/paste functions i need - I avoid

Re: vectorization of a simple loop -- not in DMD?

2022-07-12 Thread bauss via Digitalmars-d-learn
On Tuesday, 12 July 2022 at 07:06:37 UTC, Siarhei Siamashka wrote: ``` real0m34.371s user0m32.883s sys 0m1.488s ``` ``` real0m14.078s user0m12.941s sys 0m1.129s ``` Is there an open source DUB package, which can be used to reproduce a huge build time difference

Re: DIP1000

2022-06-28 Thread bauss via Digitalmars-d-learn
On Tuesday, 28 June 2022 at 21:58:48 UTC, Ola Fosheim Grøstad wrote: not-scoped variable (`a.next` is not `scope` since this attribute is not transitive) Well, that is a flaw, if the object is stack allocated then the fields are too. Not necessarily, especially if the fields aren't

Re: int | missing | absent

2022-06-24 Thread bauss via Digitalmars-d-learn
On Thursday, 23 June 2022 at 15:20:02 UTC, 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

Re: Any way to define variables from one scope in another scope?

2022-06-21 Thread bauss via Digitalmars-d-learn
On Monday, 20 June 2022 at 13:56:04 UTC, Ruby The Roobster wrote: Is there any way to define variables in an outer scope from an inner scope? I was thinking ```d void main() { int .y = 3; } ``` would work, but it doesn't. No and it would only lead to bugs. If you have access to an

Re: nested function overloading

2022-06-17 Thread bauss via Digitalmars-d-learn
On Friday, 17 June 2022 at 13:04:47 UTC, Chris Katko wrote: On Friday, 17 June 2022 at 12:19:33 UTC, bauss wrote: On Friday, 17 June 2022 at 12:09:33 UTC, Chris Katko wrote: I don't need this functionality, but I wanted to be sure. Does function overloading not work with nested functions? I

Re: std.conv.to

2022-06-17 Thread bauss via Digitalmars-d-learn
On Friday, 17 June 2022 at 12:48:56 UTC, 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() {

Re: nested function overloading

2022-06-17 Thread bauss via Digitalmars-d-learn
On Friday, 17 June 2022 at 12:09:33 UTC, 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. According to the spec then

Re: UFCS limit

2022-06-17 Thread bauss via Digitalmars-d-learn
On Friday, 17 June 2022 at 05:17:20 UTC, Tejas wrote: On Friday, 17 June 2022 at 01:04:28 UTC, Paul Backus wrote: Nope. The way UFCS works is that allows you to call free functions using member-function syntax, and member-function syntax is always `object.memberName`, so UFCS only works for

Re: Comparing Exceptions and Errors

2022-06-16 Thread bauss via Digitalmars-d-learn
On Thursday, 16 June 2022 at 11:38:40 UTC, kdevel wrote: On Thursday, 16 June 2022 at 11:28:32 UTC, bauss wrote: [...] https://dlang.org/spec/statement.html#scope-guard-statement Quote (again): "A [...] scope(success) statement may not exit with a throw [...]." [...] If the spec forbids it,

Re: Comparing Exceptions and Errors

2022-06-16 Thread bauss via Digitalmars-d-learn
On Thursday, 16 June 2022 at 10:07:23 UTC, 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

Re: Closures over temporary variables

2022-06-14 Thread bauss via Digitalmars-d-learn
On Tuesday, 14 June 2022 at 08:26:53 UTC, Anonymouse wrote: What is the correct way of making this output `0 1 2`? ```d void delegate()[] dgs; foreach (immutable i; 0..3) { dgs ~= () => writeln(i); } foreach (dg; dgs) { dg(); // outputs: `2 2 2` } ``` You have to do it like this:

Re: Generating unique identifiers at compile time

2022-06-10 Thread bauss via Digitalmars-d-learn
On Thursday, 9 June 2022 at 23:50:10 UTC, user1234 wrote: There's [been attempts] to expose it, exactly so that users can generate unique names, but that did not found its path in the compiler. [been attempts]: https://github.com/dlang/dmd/pull/10131 You can generate unique names actually

Re: Dynamic Arrays Capacity

2022-06-04 Thread bauss via Digitalmars-d-learn
On Friday, 3 June 2022 at 12:52:30 UTC, Adam D Ruppe wrote: On Friday, 3 June 2022 at 12:49:07 UTC, bauss wrote: I believe it's only true in unicode for utf-32 since all characters do fit in the 4 byte space they have Depends how you define "character". I guess that's true as well, unicode

Re: Dynamic Arrays Capacity

2022-06-03 Thread bauss via Digitalmars-d-learn
On Thursday, 2 June 2022 at 20:12:30 UTC, Steven Schveighoffer wrote: This statement suggests to me that you have an incorrect perception of a string. A string is a pointer paired with a length of how many characters after that pointer are valid. That's it. `str.ptr` is the pointer to the

Re: int | missing | absent

2022-06-02 Thread bauss via Digitalmars-d-learn
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 * int | null | absent Whats the

Re: static assert("nothing")

2022-05-31 Thread bauss via Digitalmars-d-learn
On Tuesday, 31 May 2022 at 09:11:41 UTC, JG wrote: On Tuesday, 31 May 2022 at 08:51:45 UTC, realhet wrote: Hi, In my framework I just found a dozen of compile time error handling like: ...else static assert("Invalid type"); This compiles without error. And it was useless for detecting

Re: static assert("nothing")

2022-05-31 Thread bauss via Digitalmars-d-learn
On Tuesday, 31 May 2022 at 08:51:45 UTC, realhet wrote: Hi, In my framework I just found a dozen of compile time error handling like: ...else static assert("Invalid type"); This compiles without error. And it was useless for detecting errors because I forgot the first "false" or "0"

Re: Compiler switch for integer comparison/promotion to catch a simple error

2022-05-30 Thread bauss via Digitalmars-d-learn
On Sunday, 29 May 2022 at 01:35:23 UTC, frame wrote: Is there a compiler switch to catch this kind of error? ```d ulong v = 1; writeln(v > -1); ``` IMHO the compiler should bail a warning if it sees a logic comparison between signed and unsigned / different integer sizes. There is 50% chance

Re: Allocate a string via the GC

2022-05-23 Thread bauss via Digitalmars-d-learn
On Monday, 23 May 2022 at 12:20:11 UTC, JG wrote: On Monday, 23 May 2022 at 11:39:22 UTC, Adam D Ruppe wrote: On Monday, 23 May 2022 at 09:38:07 UTC, JG wrote: Hi, Is there any more standard way to achieve something to the effect of: ```d import std.experimental.allocator; string* name

Re: Allocate a string via the GC

2022-05-23 Thread bauss via Digitalmars-d-learn
On Monday, 23 May 2022 at 12:17:56 UTC, bauss wrote: On Monday, 23 May 2022 at 11:39:22 UTC, Adam D Ruppe wrote: On Monday, 23 May 2022 at 09:38:07 UTC, JG wrote: Hi, Is there any more standard way to achieve something to the effect of: ```d import std.experimental.allocator; string*

Re: Allocate a string via the GC

2022-05-23 Thread bauss via Digitalmars-d-learn
On Monday, 23 May 2022 at 11:39:22 UTC, Adam D Ruppe wrote: On Monday, 23 May 2022 at 09:38:07 UTC, JG wrote: Hi, Is there any more standard way to achieve something to the effect of: ```d import std.experimental.allocator; string* name = theAllocator.make!string; ``` Why do you want

Re: vibe.d requestHTTP in static this causes infinite loop?

2022-05-20 Thread bauss via Digitalmars-d-learn
On Friday, 20 May 2022 at 01:41:59 UTC, Ali Çehreli wrote: On 5/19/22 16:44, Vijay Nayar wrote: > If I remove the call from `static this()`, then the web call works as > normal. Any idea why calling vibe.d's `requestHTTP` function inside of a > module's static construction would cause an

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

2022-05-19 Thread bauss via Digitalmars-d-learn
On Thursday, 19 May 2022 at 10:18:38 UTC, user1234 wrote: On Thursday, 19 May 2022 at 10:15:32 UTC, 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 = COLOR(0,0,1,1);

Re: class destructors must be @disabled?

2022-05-19 Thread bauss via Digitalmars-d-learn
On Wednesday, 18 May 2022 at 19:58:09 UTC, Ali Çehreli wrote: Hmm. Perhaps the guideline should be "all destructors must be @nogc". Ali It should probably just default to that and with no exception, since you will never end up in a situation where you don't want @nogc for a destructor.

Re: Unexplainable behaviour with direct struct assignment.

2022-05-19 Thread bauss via Digitalmars-d-learn
On Wednesday, 18 May 2022 at 21:52:18 UTC, HuskyNator wrote: On Wednesday, 18 May 2022 at 21:49:14 UTC, HuskyNator wrote: After updating to `DMD 2.100.0` & `DUB 1.29.0`, I still get this behavior. Only when I use `dub run --b=debug` however (default for me). `dub run --b=release` does return

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

2022-05-19 Thread bauss via Digitalmars-d-learn
On Wednesday, 18 May 2022 at 15:33:09 UTC, Steven Schveighoffer wrote: 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

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

2022-05-18 Thread bauss via Digitalmars-d-learn
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 url)

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

2022-05-17 Thread bauss via Digitalmars-d-learn
On Tuesday, 17 May 2022 at 11:53:40 UTC, zjh wrote: On Tuesday, 17 May 2022 at 11:50:30 UTC, zjh wrote: Right,GC is a bad idea! Endless use of memory without freeing. It's totally unreasonable waste. It's not really endless use of memory and it does free. Depending on the strategy then it

Re: Question on shapes

2022-05-17 Thread bauss via Digitalmars-d-learn
On Tuesday, 17 May 2022 at 00:10:55 UTC, Alain De Vos wrote: Let's say a shape is ,a circle with a radius ,or a square with a rectangular size. I want to pass shapes to functions, eg to draw them on the screen, draw(myshape) or myshape.draw(); But how do i implement best shapes ? In addition

Re: decimal type in d

2022-05-16 Thread bauss via Digitalmars-d-learn
On Monday, 16 May 2022 at 09:46:57 UTC, IGotD- wrote: On Sunday, 15 May 2022 at 13:26:30 UTC, 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

Re: Why are structs and classes so different?

2022-05-16 Thread bauss via Digitalmars-d-learn
On Sunday, 15 May 2022 at 15:59:17 UTC, Alain De Vos wrote: Can i summarize , structs are value-objects which live on the stack. class instances are reference objects which live on the heap. But that's not entirely true as you can allocate a struct on the heap as well. The real difference

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

2022-05-11 Thread bauss via Digitalmars-d-learn
On Wednesday, 11 May 2022 at 05:41:35 UTC, Ali Çehreli wrote: What are you stuck at? What was the most difficult features to understand? etc. To make it more meaningful, what is your experience with other languages? Ali dip1000

Re: Parameters declared as the alias of a template won't accept the arguments of the same type.

2022-05-04 Thread bauss via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 07:11:48 UTC, Ola Fosheim Grøstad wrote: As you see, someone will have to write a DIP to fix this bug, as the language authors don't consider it a bug, but an enhancement. I don't believe those two words are mutually exclusive. It can be a bug __and__ an

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread bauss via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 09:52:56 UTC, cc wrote: On Tuesday, 3 May 2022 at 09:42:45 UTC, cc wrote: Given a runtime typeid, how can I get the equivalent fullyQualifiedName without attempting to mangle the string myself manually? e.g. something I can pass to `Object.factory`. Actually,

Re: CTFE and BetterC compatibility

2022-04-28 Thread bauss via Digitalmars-d-learn
On Thursday, 28 April 2022 at 12:36:56 UTC, Dennis wrote: On Thursday, 28 April 2022 at 12:10:44 UTC, bauss wrote: On Wednesday, 27 April 2022 at 15:40:49 UTC, Adam D Ruppe wrote: but this got killed due to internal D politics. A pity. A tale as old as time itself In this case, it was

Re: CTFE and BetterC compatibility

2022-04-28 Thread bauss via Digitalmars-d-learn
On Wednesday, 27 April 2022 at 15:40:49 UTC, Adam D Ruppe wrote: but this got killed due to internal D politics. A pity. A tale as old as time itself

Re: How to implement private constructor

2022-04-25 Thread bauss via Digitalmars-d-learn
On Monday, 25 April 2022 at 07:18:44 UTC, bauss wrote: On Monday, 25 April 2022 at 00:18:03 UTC, Vinod K Chandran wrote: Hi all, Please take a look at this code. Is this the right way to use private constructors ? ```d class Foo { int p1 ; string p2 ; bool p3 ; private

Re: How to implement private constructor

2022-04-25 Thread bauss via Digitalmars-d-learn
On Monday, 25 April 2022 at 00:18:03 UTC, Vinod K Chandran wrote: Hi all, Please take a look at this code. Is this the right way to use private constructors ? ```d class Foo { int p1 ; string p2 ; bool p3 ; private this(int a, string b, bool c) { this.p1 = a

Re: stack frame & dangling pointer weirdness

2022-04-21 Thread bauss via Digitalmars-d-learn
On Thursday, 21 April 2022 at 05:49:12 UTC, Alain De Vos wrote: Following program: ``` import std.stdio; void main() @trusted { int *p=null; void myfun(){ int x=2; p= writeln(p); writeln(x); } myfun(); *p=16; writeln(p); writeln(*p); } ``` outputs :

Re: Beginner memory question.

2022-04-19 Thread bauss via Digitalmars-d-learn
On Saturday, 16 April 2022 at 20:48:15 UTC, Adam Ruppe wrote: On Saturday, 16 April 2022 at 20:41:25 UTC, WhatMeWorry wrote: Is virtual memory entering into the equation? Probably. Memory allocated doesn't physically exist until written to a lot of the time. You can also exceed your RAM in

Re: DUB issues

2022-04-19 Thread bauss via Digitalmars-d-learn
On Tuesday, 19 April 2022 at 09:37:49 UTC, Mike Parker wrote: On Tuesday, 19 April 2022 at 08:58:02 UTC, bauss wrote: On Monday, 18 April 2022 at 13:41:04 UTC, Mike Parker wrote: On Monday, 18 April 2022 at 05:27:32 UTC, Danny Arends wrote: Any ideas how to get into contact/fix this issue ?

Re: DUB issues

2022-04-19 Thread bauss via Digitalmars-d-learn
On Monday, 18 April 2022 at 13:41:04 UTC, Mike Parker wrote: On Monday, 18 April 2022 at 05:27:32 UTC, Danny Arends wrote: Any ideas how to get into contact/fix this issue ? I've emailed Sönke and pointed him to this thread. Wouldn't the appropriate thing to do be dub being officially a

Re: save and load a 2d array to a file

2022-04-19 Thread bauss via Digitalmars-d-learn
On Tuesday, 19 April 2022 at 06:05:27 UTC, Ali Çehreli wrote: int i = 42; file.rawWrite(*cast((int[1]*)())); // Casted to be an array of 1 I assume since we don't have a rawWriteValue, that it's rarely needed. However it should be fairly trivial like: void rawWriteValue(T)(T

Re: How to exclude function from being imported in D language?

2022-03-18 Thread bauss via Digitalmars-d-learn
On Friday, 18 March 2022 at 03:24:10 UTC, Era Scarecrow wrote: On Tuesday, 8 March 2022 at 22:28:27 UTC, bauss wrote: What D just needs is a way to specify the entry point, in which it just defaults to the first main function found, but could be any function given. Which is similar to what

Re: Make shared static this() encoding table compilable

2022-03-14 Thread bauss via Digitalmars-d-learn
On Monday, 14 March 2022 at 09:40:00 UTC, zhad3 wrote: Hey everyone, I am in need of some help. I have written this Windows CP949 encoding table https://github.com/zhad3/zencoding/blob/main/windows949/source/zencoding/windows949/table.d which is used to convert CP949 to UTF-16. After some

Re: Template with default parameter

2022-03-11 Thread bauss via Digitalmars-d-learn
On Friday, 11 March 2022 at 11:55:24 UTC, Andrey Zherikov wrote: On Friday, 11 March 2022 at 07:06:15 UTC, bauss wrote: Create an alias for T!() is the best you can do. Ex. ``` alias t = T!(); ``` There isn't really any better method as far as I know. I'd like to preserve the name (`t` !=

Re: Template with default parameter

2022-03-10 Thread bauss via Digitalmars-d-learn
On Friday, 11 March 2022 at 04:41:40 UTC, Andrey Zherikov wrote: I have simple template: ```d template T(int i=3) { mixin template M(int m) { enum t = i; } } { mixin T!1.M!1; pragma(msg, t); // 1 } { mixin T!().M!1; pragma(msg, t); //

Re: How to exclude function from being imported in D language?

2022-03-08 Thread bauss via Digitalmars-d-learn
On Tuesday, 8 March 2022 at 20:12:40 UTC, BoQsc wrote: I think D Language needs and lacks conditional compilation condition and attribute of "exclude". The exclude keyword or code block in the exclude, would be made sure to not be imported by any means. Now it seems all to be only workarounds.

Re: opCast in class prevents destroy

2022-03-01 Thread bauss via Digitalmars-d-learn
On Tuesday, 1 March 2022 at 08:16:13 UTC, Mike Parker wrote: On Tuesday, 1 March 2022 at 07:16:11 UTC, bauss wrote: Right now if you want to add an additional cast then you have to implement ALL the default behaviors and then add your custom cast. It's two template functions like the OP

Re: opCast in class prevents destroy

2022-02-28 Thread bauss via Digitalmars-d-learn
On Tuesday, 1 March 2022 at 04:59:49 UTC, Mike Parker wrote: It makes sense to me, and I would say the bug is that it's not documented. Personally it doesn't make sense to me. I don't think it should override default behaviors, but just add onto it, so you can add an additional cast.

Re: Odd behaviour of std.range

2022-02-22 Thread bauss via Digitalmars-d-learn
On Tuesday, 22 February 2022 at 12:48:21 UTC, frame wrote: What am I missing here? Is this some UTF conversion issue? ```d string a; char[] b; pragma(msg, typeof(a.take(1).front)); // dchar pragma(msg, typeof(b.take(1).front)); // dchar ``` Welcome to the world of auto decoding, D's million

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bauss via Digitalmars-d-learn
On Monday, 21 February 2022 at 15:13:52 UTC, Kagamin wrote: On Monday, 21 February 2022 at 09:04:06 UTC, bauss wrote: Why are we even escaping them by default, it should be the other way around, that slashes are only escaped if you ask for it; that's how it literally is in almost every JSON

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread bauss via Digitalmars-d-learn
On Monday, 21 February 2022 at 10:57:07 UTC, Basile B. wrote: On Monday, 21 February 2022 at 10:53:56 UTC, Basile B. wrote: On Monday, 21 February 2022 at 10:49:13 UTC, partypooper wrote: Do I completely not understand what is `nothrow` or why I can't make function nothrow with just catching

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bauss via Digitalmars-d-learn
On Monday, 21 February 2022 at 03:42:55 UTC, bachmeier wrote: I tried this ``` import std.json, std.stdio; void main() { writeln(parseJSON(`{"a": "path/file"}`, JSONOptions.doNotEscapeSlashes)); } ``` but the output is ``` {"a":"path\/file"} ``` Is there a way to avoid the escaping of

Re: How to update Associative Array?

2022-02-10 Thread bauss via Digitalmars-d-learn
On Thursday, 10 February 2022 at 10:59:17 UTC, tastyminerals wrote: Not sure if the `update` method got changed but I am having trouble with understanding it now. I assumed it would work as easy as in Python:) Just do `mydic.update(dic)` or `mydic["key"].update(anotherDic)`. The docs have the

Re: Filling an array at compile time

2022-02-09 Thread bauss via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 16:37:22 UTC, Ali Çehreli wrote: On 2/9/22 01:07, bauss wrote: > It will not run at compile-time because csvText is a runtime variable. > It should be enum to be accessible at compile-time. Yes. For the sake of completeness, any expression needed at compile

Re: how to handle very large array?

2022-02-09 Thread bauss via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 10:03:21 UTC, MichaelBi wrote: day6 of the advent of code 2021 needs to handle an array of 10^12 length, or even bigger... plus change elements and append elements. normal implementation such as length, appender and ref element etc, seems cannot handle that big

Re: Filling an array at compile time

2022-02-09 Thread bauss via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 10:01:15 UTC, Anonymouse wrote: On Wednesday, 9 February 2022 at 08:12:52 UTC, Vindex wrote: Will the loop (foreach) run at compile time? How can I make it work at compile time? ``` import std.csv, std.stdio; alias Record = Tuple!(string, string, string);

  1   2   3   4   5   6   >