Re: Preventing the Compiler from Optimizing Away Benchmarks

2023-03-13 Thread user1234 via Digitalmars-d-learn
On Monday, 13 March 2023 at 14:17:57 UTC, jmh530 wrote: I was looking at [1] for ways to prevent the compiler from optimizing away code when trying to benchmark. It has the following C++ code as a simpler version: ``` inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) { asm

Re: Can nice D code get a bit slow?

2023-03-09 Thread user1234 via Digitalmars-d-learn
On Wednesday, 8 March 2023 at 12:46:53 UTC, Hipreme wrote: On Wednesday, 8 March 2023 at 10:49:32 UTC, Markus wrote: Hi, sorry for the broad and vague question. I have read in some reddit post about benchmarks, that some code didn't use the final keyword on methods in a sense that final would

Re: ELIZA Chatbot Implementation From C to D Lang

2023-02-18 Thread user1234 via Digitalmars-d-learn
On Friday, 17 February 2023 at 17:03:34 UTC, ron77 wrote: Hello, I succeeded in converting an ELIZA code from C to D, and here are the results. although I'm sure there are better ways to code it or to convert it... [...] Among the things to do the first is to drop C-style strings, so that

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

2023-02-24 Thread user1234 via Digitalmars-d-learn
On Friday, 24 February 2023 at 12:00:41 UTC, Elfstone wrote: Seems like the same bug is still there after ten years. ```d struct Bar { @("hello") int t; } static bool hasAttribute(alias F, T)() { bool result = false;

Re: compile: link dynamic OR static library in Windows

2023-02-05 Thread user1234 via Digitalmars-d-learn
On Sunday, 5 February 2023 at 11:52:01 UTC, Alexander Zhirov wrote: On Saturday, 4 February 2023 at 15:56:41 UTC, Richard (Rikki) Andrew Cattermole wrote: [...] I don't understand why the compiler doesn't see the library. ```sh User@WIN-D3SHRBHN7F6 MINGW64 /home/user/pxe-restore/source # ls

Re: Function Composition

2024-01-24 Thread user1234 via Digitalmars-d-learn
On Wednesday, 24 January 2024 at 21:12:20 UTC, atzensepp wrote: [...] what a bummer! Have you tried https://dlang.org/phobos/std_functional.html#compose ?

Re: Function Composition

2024-01-24 Thread user1234 via Digitalmars-d-learn
On Wednesday, 24 January 2024 at 21:30:23 UTC, user1234 wrote: On Wednesday, 24 January 2024 at 21:12:20 UTC, atzensepp wrote: [...] what a bummer! Have you tried https://dlang.org/phobos/std_functional.html#compose ? Well this violates the second requirement: the composition itself

Re: Synchronisation help

2024-01-02 Thread user1234 via Digitalmars-d-learn
On Monday, 1 January 2024 at 15:48:16 UTC, Anonymouse wrote: I have a `shared string[int]` AA that I access from two different threads. The function I spawn to start the second thread takes the AA as an argument. [...] What is the common solution here? Do I add a module-level `Object thing`

Re: Synchronisation help

2024-01-02 Thread user1234 via Digitalmars-d-learn
On Tuesday, 2 January 2024 at 11:39:12 UTC, Anonymouse wrote: On Tuesday, 2 January 2024 at 11:05:33 UTC, user1234 wrote: Do not use `shared` AA. Use `__gshared` + sync primitives. `shared` AA will lead to all sort of bugs: - https://issues.dlang.org/show_bug.cgi?id=20484#c1 -

Re: Indirect access to variables.

2023-12-29 Thread user1234 via Digitalmars-d-learn
On Friday, 29 December 2023 at 17:11:49 UTC, DLearner wrote: Compile-time: [...] Is there a 'foo1' that yields 1 from the snippet below? [...] Similarly, execution-time, is there a foo2 that wields 2 from the snippet below: [...] **compile-tome** ```d void main() { import std.stdio;

Re: `static` function ... cannot access variable in frame of ...

2024-01-15 Thread user1234 via Digitalmars-d-learn
On Monday, 15 January 2024 at 18:34:58 UTC, H. S. Teoh wrote: On Mon, Jan 15, 2024 at 06:16:44PM +, Bastiaan Veelo via Digitalmars-d-learn wrote: Hey people, I can use some help understanding why the last line produces a compile error. ```d import std.stdio; struct S { static void

Re: `static` function ... cannot access variable in frame of ...

2024-01-15 Thread user1234 via Digitalmars-d-learn
On Monday, 15 January 2024 at 18:16:44 UTC, Bastiaan Veelo wrote: [...] It seems to me this should just work. Thanks! --Bastiaan. The two calls are not equivalent. To be equivalent you need to set `S_foo` static too, otherwise `S_Foo` is instanciated in `main` scope, proof: ```d import

Re: Understanding the Use of Nested Import and Selective Import in D

2024-01-16 Thread user1234 via Digitalmars-d-learn
On Tuesday, 16 January 2024 at 13:19:59 UTC, Orfeo wrote: I found myself a bit perplexed when it comes to the usage of "nested imports" and selective imports. It seems that prominent D programmers have varied opinions on the matter. I would love to hear your insights and experiences on this

Re: Understanding the Use of Nested Import and Selective Import in D

2024-01-16 Thread user1234 via Digitalmars-d-learn
On Tuesday, 16 January 2024 at 13:37:59 UTC, user1234 wrote: Implementation detail. D frontend resolves identifiers using associative arrays (that's called symtabs in the compiler IIRC), hence the only complexity is the scope (plus the import decls found while going back to the module scope).

Re: Inversion of conditional compilation statements

2023-12-02 Thread user1234 via Digitalmars-d-learn
On Saturday, 2 December 2023 at 13:16:26 UTC, Johannes Miesenhardt wrote: Hello, [...] I see the way why it doesn't work, but I think it should. Considering that `version (Test) {} else {` works without any issue but looks very ugly. Can somebody explain if this is an intended decision or

Re: How to hash SHA256 from string?

2023-12-02 Thread user1234 via Digitalmars-d-learn
On Saturday, 2 December 2023 at 16:17:08 UTC, user1234 wrote: On Saturday, 2 December 2023 at 15:30:39 UTC, zoujiaqing wrote: [...] sign is binary, you have to use the toHexString utility : ```d import std.stdio; import std.digest.sha; void main() { SHA256 sha256; sha256.start();

Re: How to hash SHA256 from string?

2023-12-02 Thread user1234 via Digitalmars-d-learn
On Saturday, 2 December 2023 at 15:30:39 UTC, zoujiaqing wrote: ```D import std.stdio; import std.digest.sha; void main() { SHA256 sha256; sha256.start(); string appKey = "1"; ubyte[1024] data =

Safety is not what you think

2024-01-29 Thread user1234 via Digitalmars-d-learn
I want to share a stupid program to show you that D safety is more complex than you might think: ```d module test; void test() @safe { int i; int b = (*&(*&++i))++; } void main() @safe { test(); } ``` I'm not showing a deficiency of D, that program is undeniably safe ;)

Re: New update fix

2024-03-02 Thread user1234 via Digitalmars-d-learn
On Saturday, 2 March 2024 at 08:41:40 UTC, Salih Dincer wrote: SLM, What exactly did this patch with the new update fix? Nothing, it looks like what happened is that the issue was wrongly referenced by a dlang.org PR

Re: static functions?

2024-03-11 Thread user1234 via Digitalmars-d-learn
On Monday, 11 March 2024 at 16:51:48 UTC, Andy Valencia wrote: On Monday, 11 March 2024 at 16:25:13 UTC, Jonathan M Davis wrote: ... But what exactly static means varies based on the context. Thank you for the list! But none of those appear to apply to a function defined in the outermost

Re: How to add a character literal to a string without ~ operator?

2024-04-04 Thread user1234 via Digitalmars-d-learn
On Thursday, 4 April 2024 at 19:56:50 UTC, Ferhat Kurtulmuş wrote: On Thursday, 4 April 2024 at 18:14:54 UTC, BoQsc wrote: I'm looking for more readable standard function to add a **character** literal to a **string**. The `~` operator is clearly not great while reading a source code. I'm

Re: Deprecation: foreach: loop index implicitly converted from size_t to int

2024-05-03 Thread user1234 via Digitalmars-d-learn
On Friday, 3 May 2024 at 10:50:03 UTC, BoQsc wrote: Why am I forced to visit this D Lang thread, why this deprecation warning still appears in my console window in the latest version of DMD. Does not make any sense from the developer's perspective to show this warning and pollute the already

Re: Deprecation: foreach: loop index implicitly converted from size_t to int

2024-05-03 Thread user1234 via Digitalmars-d-learn
On Friday, 3 May 2024 at 14:59:57 UTC, BoQsc wrote: On Friday, 3 May 2024 at 13:18:02 UTC, user1234 wrote: On Friday, 3 May 2024 at 10:50:03 UTC, BoQsc wrote: [...] **You can specify the index type, just choose the right one.** For now there's a deprecation message but after some while

Re: Deprecation: foreach: loop index implicitly converted from size_t to int

2024-05-03 Thread user1234 via Digitalmars-d-learn
On Friday, 3 May 2024 at 15:19:13 UTC, user1234 wrote: On Friday, 3 May 2024 at 14:59:57 UTC, BoQsc wrote: On Friday, 3 May 2024 at 13:18:02 UTC, user1234 wrote: [...] So how would you update this example, what is the right index type here to choose? ``` import std.stdio : writefln;

Why is Phobos `Flag` so overthought ?

2024-05-06 Thread user1234 via Digitalmars-d-learn
I think this just works: ```d enum Flag : bool { no, yes } alias AllowVancancy = Flag; // example usage ``` Also this is completion friendly whereas Phobos version does not permit DCD completion as it's based on opDispatch. Compare to phobos version: ```d template Flag(string name)

Re: Why is Phobos `Flag` so overthought ?

2024-05-06 Thread user1234 via Digitalmars-d-learn
On Monday, 6 May 2024 at 18:06:53 UTC, Julian Fondren wrote: On Monday, 6 May 2024 at 17:55:49 UTC, user1234 wrote: I think this just works: ```d enum Flag : bool { no, yes } alias AllowVancancy = Flag; // example usage ``` ```d import std.stdio : writeln; enum Flag : bool { no,

Re: aliasing private

2024-05-01 Thread user1234 via Digitalmars-d-learn
On Wednesday, 1 May 2024 at 12:07:26 UTC, NotYouAgain wrote: I want to do a C like #define on private, but I can't ie. #define private fileprivate // --- module m; alias fileprivate = private; // grr! class myClass { fileprivate int n; } // --- You cant. That is simply not supported.

<    1   2   3