Re: extern(C) on var decl is confusing

2025-07-28 Thread user1234 via Digitalmars-d-learn
On Monday, 28 July 2025 at 11:06:40 UTC, kinke wrote: On Sunday, 27 July 2025 at 23:23:40 UTC, user1234 wrote: That is confusing It affects the mangling of global vars, just like functions. ah indeed

extern(C) on var decl is confusing

2025-07-27 Thread user1234 via Digitalmars-d-learn
That is confusing, e.g ``` extern(C) int r; int main() { return r; } ``` works. But what is likely more intended here is ``` extern int r; int main() { return r; } ``` which leads, this time, to the expected linker error.

Re: Class-Inheritancing Error

2025-07-27 Thread user1234 via Digitalmars-d-learn
On Sunday, 27 July 2025 at 15:14:03 UTC, H. S. Teoh wrote: On Sun, Jul 27, 2025 at 11:08:33AM +, David T. Oxygen via Digitalmars-d-learn wrote: I wrote a piece of code like this: ```d class Person{ string name; this(string name){this.name=name;} } class Someone:Person{

Re: stdInputRange

2025-07-20 Thread user1234 via Digitalmars-d-learn
On Sunday, 20 July 2025 at 08:46:08 UTC, Salih Dincer wrote: Hello D Language Forum! I’m running the InputRange example below and it dutifully reads from stdin until it spots a tilde, printing each character in every loop iteration. I even tried to break out with F6 but couldn’t get it to sto

Re: scope parameter has effect only on pointers?

2025-06-23 Thread user1234 via Digitalmars-d-learn
On Monday, 23 June 2025 at 10:37:58 UTC, Dom DiSc wrote: I think scope should not be allowed on basic types, as it has no effect and is only confusing. I know, it would be needed to enable generic programming, but I find a function that can take both an int and an int* suspect anyway - this is

Re: alias vs enum for lambdas?

2025-04-28 Thread user1234 via Digitalmars-d-learn
On Monday, 28 April 2025 at 22:47:35 UTC, monkyyy wrote: On Monday, 28 April 2025 at 22:16:47 UTC, user1234 wrote: On Monday, 28 April 2025 at 20:05:34 UTC, monkyyy wrote: aliases for types, overload sets enum for litterals According to me that's a very bad advice. I'm more on "never enum"

Re: alias vs enum for lambdas?

2025-04-28 Thread user1234 via Digitalmars-d-learn
On Monday, 28 April 2025 at 20:05:34 UTC, monkyyy wrote: aliases for types, overload sets enum for litterals According to me that's a very bad advice. I'm more on "never enum". Do you have any example where enum is better ?

Re: alias vs enum for lambdas?

2025-04-28 Thread user1234 via Digitalmars-d-learn
On Monday, 28 April 2025 at 04:59:24 UTC, Orion wrote: In which programming scenarios should alias be used instead of enum? So far I have only found a simplified notation of a generic lambda: alias id = (x) => x; x; , which does not work in the case of enum. There is also a difference in ov

Re: aligned_alloc visibilty

2025-04-12 Thread user1234 via Digitalmars-d-learn
On Saturday, 12 April 2025 at 03:22:06 UTC, faceless wrote: What is the purpose of hiding the `aligned_alloc` declaration like this in `core.stdc.stdlib`? ```d 29version (CRuntime_Glibc) 30version = AlignedAllocSupported; 31else version (CRuntime_Newlib) 32version = A

Re: Guidance on how to contribute to D lang for GSOC 2025?

2025-04-05 Thread user1234 via Digitalmars-d-learn
On Saturday, 5 April 2025 at 07:48:27 UTC, Aditya Vir wrote: Hello everyone, I am Aditya, a computer science undergrad from India. I want to push my application to D lang for this year's Google summer of Code. I seek tips and advice regarding how should I frame my application. Here is my cur

Re: How to construct a struct that does not explicitly define a constructor

2025-02-28 Thread user1234 via Digitalmars-d-learn
On Saturday, 1 March 2025 at 02:19:55 UTC, Meta wrote: Thanks, I forgot about that syntax. Another question I have is if there's a way to do this inline: ```d struct Test { int n; float f; static Test opCall(int n, float f) { //return {n, f};Error

Re: Partially initialized structs?

2025-02-26 Thread user1234 via Digitalmars-d-learn
On Wednesday, 26 February 2025 at 16:38:20 UTC, Salih Dincer wrote: On Wednesday, 26 February 2025 at 15:11:47 UTC, bkoie wrote: stuff like this is not even necessary if you dont need it now dont delcare an easy workaround is use some copy dictionary. It's not that simple. I found the followi

Re: help with prime pairs code

2025-02-01 Thread user1234 via Digitalmars-d-learn
On Sunday, 2 February 2025 at 01:12:59 UTC, user1234 wrote: On Saturday, 1 February 2025 at 21:56:23 UTC, Jabari Zakiya wrote: On Saturday, 1 February 2025 at 00:21:22 UTC, user1234 wrote: On Friday, 31 January 2025 at 20:05:54 UTC, Jabari Zakiya wrote: [...] A first draft of the translation

Re: help with prime pairs code

2025-02-01 Thread user1234 via Digitalmars-d-learn
On Saturday, 1 February 2025 at 21:56:23 UTC, Jabari Zakiya wrote: On Saturday, 1 February 2025 at 00:21:22 UTC, user1234 wrote: On Friday, 31 January 2025 at 20:05:54 UTC, Jabari Zakiya wrote: [...] A first draft of the translation, not very idiomatic D code: ```d module prime_pairs; import

Re: help with prime pairs code

2025-01-31 Thread user1234 via Digitalmars-d-learn
On Friday, 31 January 2025 at 20:05:54 UTC, Jabari Zakiya wrote: I'm converting Ruby code to D and am running into issues. Would appreciate what needs to be done to get it to compile/run correctly. Here's the Ruby code: [...] A first draft of the translation, not very idiomatic D code: ```

Re: Super easy struct construction question that I'm embarrassed to ask.

2025-01-13 Thread user1234 via Digitalmars-d-learn
On Thursday, 9 January 2025 at 23:44:52 UTC, WhatMeWorry wrote: You misspelled the parameter name 'locaction', so your assignment in the constructor is a no-op: ``` this.location = this.location ``` Thanks. I was starting to question my sanity. That error is so classic that eventually a we

Re: Simplify some C-style code

2024-12-25 Thread user1234 via Digitalmars-d-learn
On Wednesday, 25 December 2024 at 16:41:05 UTC, sfp wrote: On Wednesday, 25 December 2024 at 07:57:04 UTC, monkyyy wrote: static foreach, traits and mixin I was looking into this but I think I need some help getting off the ground... This doesn't compile: ``` enum Test { mixin("A, B, C") }

Re: Virtual opBinary in interface

2024-12-19 Thread user1234 via Digitalmars-d-learn
On Thursday, 19 December 2024 at 18:49:28 UTC, sfp wrote: Subject lines says it all, I think... The choice to make binary operators implementable only via this `opBinary` template means it's unclear how to get virtual operators on an interface. E.g., this toy example *does* compile: ``` interf

Re: unittest behaviour

2024-12-16 Thread user1234 via Digitalmars-d-learn
On Sunday, 15 December 2024 at 08:45:22 UTC, DLearner wrote: Please consider: ``` size_t foo() { static size_t var1 = 1; var1 = var1 + 1; return var1; } unittest { assert(foo() == 2); assert(foo() == 3); } ``` which works as expected. But ``` size_t foo1() { static size_

Re: MonoTime equivalent of `TickDuration.currSystemTick.msecs` ?

2024-12-10 Thread user1234 via Digitalmars-d-learn
On Wednesday, 11 December 2024 at 04:33:58 UTC, Salih Dincer wrote: On Wednesday, 11 December 2024 at 03:40:35 UTC, user1234 wrote: what's the `MonoTime` equivalent of the now deprecated `TickDuration.currSystemTick.msecs` ? ```d import core.time; // Get the current monotonic time auto curren

Re: Using a tuple as a function parameter

2024-11-22 Thread user1234 via Digitalmars-d-learn
On Friday, 22 November 2024 at 16:36:43 UTC, Andrew wrote: I'm getting started using D for some small personal projects and one thing I wanted to do was use a helper function for a tuple. I declared the function like this: string getOrZeroth(Tuple!(string, string, string) tup, int i) pure

Re: Threading with SDL

2024-11-19 Thread user1234 via Digitalmars-d-learn
On Tuesday, 19 November 2024 at 09:08:46 UTC, Adrian Preuß wrote: Hey, I'm looking at **D** right now because I find it much easier to create native applications as opposed to C++. I have the following project structure: ``` - main.d (Booting) - client.d - Renderer.d - Man

Re: Avoid subtracting form .length

2024-11-14 Thread user1234 via Digitalmars-d-learn
On Friday, 8 November 2024 at 23:27:40 UTC, Dom DiSc wrote: I _very_ often use this pattern: ``` fun(ref int[] a) { assert(a.length && a.length<=100); int[100] b; b[0 .. a.length-1] = a[]; b[a.length .. 100] = 5; } ``` I consider this perfectly safe, but DScanner gives warnings for

Re: Avoid subtracting form .length

2024-11-14 Thread user1234 via Digitalmars-d-learn
On Thursday, 14 November 2024 at 06:53:01 UTC, Salih Dincer wrote: On Friday, 8 November 2024 at 23:27:40 UTC, Dom DiSc wrote: I _very_ often use this pattern: ```d fun(ref int[] a) { assert(a.length && a.length<=100); int[100] b; b[0 .. a.length-1] = a[]; b[a.length .. 100] = 5; }

Re: Float swap using bswap produces different values

2024-10-14 Thread user1234 via Digitalmars-d-learn
On Monday, 14 October 2024 at 20:38:38 UTC, user1234 wrote: On Monday, 14 October 2024 at 15:59:07 UTC, vinoB wrote: Hi All, Request your help in understanding why the below code is producing different outputs, code 1 output: 4294966806, code 2/3 output: 50331648, and which one is the correct

Re: Float swap using bswap produces different values

2024-10-14 Thread user1234 via Digitalmars-d-learn
On Monday, 14 October 2024 at 15:59:07 UTC, vinoB wrote: Hi All, Request your help in understanding why the below code is producing different outputs, code 1 output: 4294966806, code 2/3 output: 50331648, and which one is the correct output. [...] `cast(unint)` of a `float` does truncation

Re: What exactly the --allinst compiler flag does.

2024-09-28 Thread user1234 via Digitalmars-d-learn
On Saturday, 28 September 2024 at 12:20:43 UTC, realhet wrote: Hi, I have some statements in my mind about --allinst, but I'm not sure they are correct or not. 1. Normally the compiler analyzes the full code with all the modules, and it only compiles code for template things that are used i

Re: Integer precision of function return types

2024-09-26 Thread user1234 via Digitalmars-d-learn
On Thursday, 26 September 2024 at 06:53:12 UTC, Per Nordlöw wrote: Should a function like ```d uint parseHex(in char ch) pure nothrow @safe @nogc { switch (ch) { case '0': .. case '9': return ch - '0'; case 'a': .. case 'f': return 10 + ch

Re: Poor Carlos does not manage to find where to eat

2024-09-20 Thread user1234 via Digitalmars-d-learn
On Saturday, 21 September 2024 at 04:29:15 UTC, user1234 wrote: ```d module m; [...] Beside the childish example... D could use a system of "constraint matching score" to help Carlos. Three AndAndExps verified should have a better score than two and finally determine the selection.

Re: assert

2024-09-12 Thread user1234 via Digitalmars-d-learn
On Wednesday, 11 September 2024 at 10:08:29 UTC, ryuukk_ wrote: On Wednesday, 11 September 2024 at 09:14:39 UTC, Nick Treleaven wrote: On Wednesday, 11 September 2024 at 08:08:45 UTC, ryuukk_ wrote: [...] I again apologies for being wrong and i apologies again for trying to improve things, i d

Re: How to Humanize Numerical Input|Output

2024-09-09 Thread user1234 via Digitalmars-d-learn
On Monday, 9 September 2024 at 20:02:48 UTC, Jabari Zakiya wrote: I have this code to input integer values: ``` ulong[] x; foreach (_; 0 .. 2) { ulong a; readf!" %d"(a); x ~= a; } end_num = max(x[0], 3); start_num = max(x[1], 3); if (start_num > end_num) swap(start_num, end_num); sta

Re: D feature request

2024-08-05 Thread user1234 via Digitalmars-d-learn
On Monday, 5 August 2024 at 03:09:41 UTC, IchorDev wrote: On Sunday, 4 August 2024 at 10:32:38 UTC, Richard (Rikki) Andrew Cattermole wrote: Chuck it into the ideas forum. If it interests somebody, somebody else can work on it. Also sometimes if a feature is very minor you can submit a ‘feat

Re: Any way to automatically convert structs on return?

2024-08-01 Thread user1234 via Digitalmars-d-learn
On Thursday, 1 August 2024 at 10:59:03 UTC, IchorDev wrote: On Thursday, 1 August 2024 at 09:55:08 UTC, user1234 wrote: The problem would be that sorting the candidates of an overload set would be more complicated. Also in certain cases it would be less obvious to get which one is selected. P

Re: Any way to automatically convert structs on return?

2024-08-01 Thread user1234 via Digitalmars-d-learn
On Thursday, 1 August 2024 at 08:46:00 UTC, IchorDev wrote: [...] I’m pretty sure this is intentional to prevent ambiguity, but I can’t quite remember what the point of that is. The problem would be that sorting the candidates of an overload set would be more complicated. Also in certain case

Re: Weird std.path API?

2024-07-08 Thread user1234 via Digitalmars-d-learn
On Monday, 8 July 2024 at 07:29:27 UTC, aberba wrote: On Sunday, 7 July 2024 at 15:35:36 UTC, Andrey Zherikov wrote: On Sunday, 7 July 2024 at 14:49:52 UTC, Anonymouse wrote: On Sunday, 7 July 2024 at 14:41:31 UTC, Andrey Zherikov wrote: ```d import std.path; // Error: no property `asNormalie

Re: Wrapper around a recursive data type

2024-07-08 Thread user1234 via Digitalmars-d-learn
On Monday, 8 July 2024 at 08:56:51 UTC, drug007 wrote: I need to generate some meta info of my data types. I do it this [...] How can I "break" this recursion or some other work around to fix it? Use `Node*[]` for the children type. That way the compiler knows the size of the (previously) pro

Re: Weird std.path API?

2024-07-07 Thread user1234 via Digitalmars-d-learn
On Sunday, 7 July 2024 at 15:35:36 UTC, Andrey Zherikov wrote: On Sunday, 7 July 2024 at 14:49:52 UTC, Anonymouse wrote: On Sunday, 7 July 2024 at 14:41:31 UTC, Andrey Zherikov wrote: ```d import std.path; // Error: no property `asNormaliedPath` for `dirName("/sandbox/onlineapp.d")` of type `

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, yes

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: 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; vo

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 you'

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 p

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.

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 not

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 sco

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 (https://github.com/dlang/dlang.org/pull/3701/commits/4e8db30f0bf3c330c3431

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

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

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 foo

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 s

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 - https://issues.d

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: 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: 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 = cast(ubyte[])(appKey.dup[0..$]

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 wh

Re: Is a shorter statement possible in this case?

2023-11-05 Thread user1234 via Digitalmars-d-learn
On Sunday, 5 November 2023 at 18:36:40 UTC, Ctn-Dev wrote: I wrote this earlier: [...] if runs when both "One" and "Two" are in the given array as intended, but its conditional statement looks verbose. Is there a more concise way of getting the same result? Yes, assuming you accept to drop

Re: extern (c)

2023-10-11 Thread user1234 via Digitalmars-d-learn
On Wednesday, 11 October 2023 at 13:36:16 UTC, Paul wrote: On Wednesday, 11 October 2023 at 12:54:53 UTC, user1234 wrote: `extern(C)` on module level functions affect the mangling and the calling convention. - Mangling is used by the linker to link symbols between objects. - Calling convent

Re: extern (c)

2023-10-11 Thread user1234 via Digitalmars-d-learn
On Wednesday, 11 October 2023 at 12:36:58 UTC, Paul wrote: What does the extern (c) attribute(?) do? Does it tell the compiler/linker to build the function like a C compiler would build a C function? If so what does that mean? Does it tell the compiler/linker to let C functions know it exists?

Re: Getting all struct members and values with introspection avoiding string mixins

2023-10-05 Thread user1234 via Digitalmars-d-learn
On Thursday, 5 October 2023 at 22:24:06 UTC, mw wrote: On Thursday, 5 October 2023 at 21:41:38 UTC, cc wrote: If you have `T info`, T.tupleof[n] will always match up with info.tupleof[n]. You can think of `info.tupleof[n]` as being rewritten by the compiler in-place as info.whateverFieldTha

Re: How to get all modules in a package at CT?

2023-10-05 Thread user1234 via Digitalmars-d-learn
On Thursday, 5 October 2023 at 20:42:26 UTC, mw wrote: On Thursday, 5 October 2023 at 20:07:38 UTC, user1234 wrote: No. Sorry. Generally compile time code cannot interact with the system. To be evaluable at compile time code has to be strongly pure, that is not the case of the function you wo

Re: How to get all modules in a package at CT?

2023-10-05 Thread user1234 via Digitalmars-d-learn
On Thursday, 5 October 2023 at 18:40:36 UTC, mw wrote: On Saturday, 24 November 2018 at 15:21:57 UTC, Anonymouse wrote: On Saturday, 24 November 2018 at 08:44:19 UTC, Domain wrote: I have a package named command, and many modules inside it, such as command.build, command.pack, command.help... I

Re: parallelism with delegate

2023-09-21 Thread user1234 via Digitalmars-d-learn
On Friday, 22 September 2023 at 04:33:44 UTC, Vitaliy Fadeev wrote: On Friday, 22 September 2023 at 04:24:19 UTC, Vitaliy Fadeev wrote: ... Skip this thread. I see solution. How to delete missed posts on this forum ? It's there forever, you have to live with that error ;) See https://forum

Re: C to D: please help translate this weird macro

2023-09-21 Thread user1234 via Digitalmars-d-learn
On Thursday, 21 September 2023 at 16:28:25 UTC, Nick Treleaven wrote: (Untested) There might be a `need this` error

Re: Dinamyc arrays

2023-09-17 Thread user1234 via Digitalmars-d-learn
On Sunday, 17 September 2023 at 17:15:34 UTC, Timofey wrote: I`ve just started learning d and have a question. What should I write to set dinamyc rectangular array length in both dimentions? For example, I have declareted an array: ```d int[][] matrix; ``` and want set it as n*n matrix. Thank

Re: pipeProcess output to hash string

2023-09-12 Thread user1234 via Digitalmars-d-learn
On Monday, 11 September 2023 at 22:08:54 UTC, Christian Köstlin wrote: Just three remarks: First I would recommend to use `std.process : execute` instead of `pipeProcess` in this usecase, as this will wait properly for the process to exit and it also will collect its output. Second its alway

Re: pipeProcess output to hash string

2023-09-09 Thread user1234 via Digitalmars-d-learn
On Saturday, 9 September 2023 at 15:44:44 UTC, Vino wrote: Hi All, Request your help on how to convert the output of std.process.pipeProcess to hash string ``` auto test(in Redirect redirect=Redirect.stdout | Redirect.stderr) { import std.process; import std.digest.crc; import

Re: Is sizeof() available in D language?

2023-09-04 Thread user1234 via Digitalmars-d-learn
On Monday, 4 September 2023 at 09:41:54 UTC, BoQsc wrote: I've seen everyone using **datatype**`.sizeof` property. https://dlang.org/spec/property.html#sizeof It's great, but I wonder if it differ in any way from the standard C function `sizeof()`. https://www.geeksforgeeks.org/sizeof-operat

Re: Cool pattern or tragic?

2023-08-26 Thread user1234 via Digitalmars-d-learn
On Friday, 25 August 2023 at 21:00:08 UTC, Guillaume Piolat wrote: The idea is to deliberately mark @system functions that need special scrutiny to use, regardless of their memory-safety. Function that would typically be named `assumeXXX`. ```d class MyEncodedThing { Encoding encoding;

Re: Implicit type conversion depending on assignment

2023-03-23 Thread user1234 via Digitalmars-d-learn
On Thursday, 23 March 2023 at 14:17:25 UTC, user1234 wrote: not exactly thing goal yet. The doc example you have put a link for is different, the struct with alias this a redefinition of the "alias this"'ed thing, that just cant work in what you ask in the first post. omg, let's rewrite this.

Re: Implicit type conversion depending on assignment

2023-03-23 Thread user1234 via Digitalmars-d-learn
On Thursday, 23 March 2023 at 14:05:07 UTC, Alexander Zhirov wrote: On Thursday, 23 March 2023 at 13:38:51 UTC, Alexander Zhirov wrote: Is it possible to convert such records inside the structure to the assigned type? ```d struct MyVal { string value; // Here it would be possible to us

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 volati

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 m

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

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: _Symbols _with _leading _underscores

2022-12-16 Thread user1234 via Digitalmars-d-learn
On Saturday, 17 December 2022 at 02:42:22 UTC, Paul wrote: I see code like this from time to time. Are the leading underscores significant, in general, in the D language? Is it just programmer preference? Is it a coding practice, in general, that is common...even outside of D? Thanks for any

Re: How to pass noncopyable variadic arguments with ref?

2022-10-20 Thread user1234 via Digitalmars-d-learn
On Thursday, 20 October 2022 at 16:34:34 UTC, user1234 wrote: On Thursday, 20 October 2022 at 14:03:10 UTC, tchaloupka wrote: Hi, I've found strange behavior where: [...] Shouldn't it at least protest that objects can't be passed to the function as they aren't copyable? it's clearly a compile

Re: How to pass noncopyable variadic arguments with ref?

2022-10-20 Thread user1234 via Digitalmars-d-learn
On Thursday, 20 October 2022 at 14:03:10 UTC, tchaloupka wrote: Hi, I've found strange behavior where: [...] Shouldn't it at least protest that objects can't be passed to the function as they aren't copyable? it's clearly a compiler bug to me. Something is not checked when the call is verifie

Re: Generate a pointer to a method of a struct

2022-10-15 Thread user1234 via Digitalmars-d-learn
On Saturday, 15 October 2022 at 01:48:15 UTC, kdevel wrote: Is this consistent? I think all the compilers should error on expressions like `Type.nonStaticMethod` and instead there should be a new __traits dedicated to that, especially because `this` is not a formal parameter.

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

2022-10-12 Thread user1234 via Digitalmars-d-learn
On Wednesday, 12 October 2022 at 02:15:55 UTC, Steven Schveighoffer wrote: Porting some C code to D This results in an error: ```d int x; while(!(x = 5)) { break; } ``` Error is: assignment cannot be used as a condition, perhaps `==` was meant? ... I think D should relax the restriction and

Re: Example for multi level template composition

2022-10-10 Thread user1234 via Digitalmars-d-learn
On Monday, 10 October 2022 at 06:30:05 UTC, Arun wrote: Stumbled upon this question on HN https://news.ycombinator.com/item?id=33142751#33147401 Can I write template A and then apply it to itself to get template B and then apply that onto template C to get template D. Does anyone have an ex

Re: Explicit cast to @system?

2022-10-09 Thread user1234 via Digitalmars-d-learn
On Saturday, 8 October 2022 at 23:06:13 UTC, Anonymouse wrote: I have some nested templated code that takes function pointers. In many cases I pass it functions of identical signatures, except some are `@safe` and others are `@system`. In those cases the templates end up getting instantiated tw

Re: cannot gdb LDC build binary: Segmentation fault

2022-10-08 Thread user1234 via Digitalmars-d-learn
On Friday, 7 October 2022 at 04:40:34 UTC, mw wrote: Hi, I have a LDC (1.30.0) built binary on Ubuntu 18.04.5 LTS x86_64, the program core dumps somewhere, so I want to debug it. However under gdb, the program fails as soon as I start it: [...] Try the non-stop mode maybe : https://source

Re: to delete the '\0' characters

2022-09-22 Thread user1234 via Digitalmars-d-learn
On Thursday, 22 September 2022 at 10:53:32 UTC, Salih Dincer wrote: Is there a more accurate way to delete the '\0' characters at the end of the string? I tried functions in this module: https://dlang.org/phobos/std_string.html ```d auto foo(string s) { string r; foreach(c; s) { if(c

Re: Validate static asserts

2022-09-09 Thread user1234 via Digitalmars-d-learn
On Friday, 9 September 2022 at 17:35:44 UTC, Dennis wrote: On Friday, 9 September 2022 at 16:41:54 UTC, Andrey Zherikov wrote: What's about new `compileOutput` trait that returns compiler output? ```d static assert(__traits(compileOutput, { }) == "message"); ``` As a compiler dev, that sou

Re: Programs in D are huge

2022-08-16 Thread user1234 via Digitalmars-d-learn
On Tuesday, 16 August 2022 at 08:25:18 UTC, 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

Re: code review: splitIds from DConf '22 day 3: saving a sort and "getting performance"

2022-08-05 Thread user1234 via Digitalmars-d-learn
On Thursday, 4 August 2022 at 13:18:40 UTC, kdevel wrote: At DConf '22 day 3 Robert Schadek presented at around 07:22:00 in the YT video the function `splitIds`. Given an HTML page from bugzilla containing a list of issues `splitIds` aims at extracting all bug-ids referenced within a specific u

Re: Build for i586

2022-07-28 Thread user1234 via Digitalmars-d-learn
On Thursday, 28 July 2022 at 06:12:49 UTC, Alexander Zhirov wrote: On Thursday, 28 July 2022 at 06:01:17 UTC, Alexander Zhirov > x86- 32-bit X86: Pentium-Pro and above I also tried with `i586` and `pentium` - the result is the same. Pentium Pro and above means at least i686. i586 is Pentium

Re: Build for i586

2022-07-28 Thread user1234 via Digitalmars-d-learn
On Thursday, 28 July 2022 at 07:16:13 UTC, user1234 wrote: On Thursday, 28 July 2022 at 06:12:49 UTC, Alexander Zhirov wrote: [...] Pentium Pro and above means at least i686. i586 is Pentium1 which is less featured. That means that you cant do much, however you can try to tune the i686 targe

Re: null == "" is true?

2022-07-12 Thread user1234 via Digitalmars-d-learn
On Tuesday, 12 July 2022 at 19:55:46 UTC, ag0aep6g wrote: On Tuesday, 12 July 2022 at 19:02:01 UTC, user1234 wrote: On Tuesday, 12 July 2022 at 16:40:38 UTC, H. S. Teoh wrote: [...] Do not rely on this, however; Absolutely. I'd like to add: especially as default parameter value that's an ar

Re: null == "" is true?

2022-07-12 Thread user1234 via Digitalmars-d-learn
On Tuesday, 12 July 2022 at 16:40:38 UTC, H. S. Teoh wrote: On Tue, Jul 12, 2022 at 04:27:44PM +, Antonio via Digitalmars-d-learn wrote: It works ```d void main() { assert(null==""); } ``` why? Because an empty string is, by default, represented by an empty slice of the null pointer.

Re: How to check if something can be null

2022-07-01 Thread user1234 via Digitalmars-d-learn
On Friday, 1 July 2022 at 13:53:28 UTC, Antonio wrote: On Friday, 1 July 2022 at 13:48:25 UTC, Antonio wrote: -Why? I realized Json is an struct (not an object)... and I supose, it is managing null asignation manually (as a way to build Json(null)). -Whats the correct whay to test if some

Re: Bug in dmd?

2022-06-15 Thread user1234 via Digitalmars-d-learn
On Tuesday, 14 June 2022 at 13:39:12 UTC, Andrey Zherikov wrote: I have [pretty simple code in my library](https://github.com/andrey- [Line (2) produces](https://github.com/andrey-zherikov/argparse/runs/6880350900?check_suite_focus=true#step:5:12) `undefined reference to '_D3std7sumtype__T7SumTy

Re: Generating unique identifiers at compile time

2022-06-13 Thread user1234 via Digitalmars-d-learn
On Monday, 13 June 2022 at 07:38:54 UTC, user1234 wrote: On Thursday, 9 June 2022 at 23:50:10 UTC, user1234 wrote: On Thursday, 9 June 2022 at 21:20:27 UTC, JG wrote: [...] No, for now there if there are other ways they are as hacky as yours. The compiler usually uses a global counter to g

Re: Generating unique identifiers at compile time

2022-06-13 Thread user1234 via Digitalmars-d-learn
On Thursday, 9 June 2022 at 23:50:10 UTC, user1234 wrote: On Thursday, 9 June 2022 at 21:20:27 UTC, JG wrote: [...] No, for now there if there are other ways they are as hacky as yours. The compiler usually uses a global counter to generate temporaries. There's [been attempts] to expose it

Re: Generating unique identifiers at compile time

2022-06-09 Thread user1234 via Digitalmars-d-learn
On Thursday, 9 June 2022 at 21:20:27 UTC, JG wrote: Hi, As an experiment I have implemented the following kind of pattern matching (by parsing the part of the string before '='). ```d struct S { int x; int y; } struct T { int w; S s; } void main() { mixin(matchAssign(q{auto T(fir

  1   2   3   >