Re: How to unpack a tuple into multiple variables?

2024-02-07 Thread Menjanahary R. R. via Digitalmars-d-learn
On Wednesday, 7 February 2024 at 05:03:09 UTC, Gary Chike wrote: ... But overall it's an elegant way to indirectly add names to tuples in D for ergonomic access. Nice find! --- Refactored it a bit to have a ready to run and easy to grasp code. Enjoy! ```d import std.stdio : writefln; import

Re: how can I load html files and not .dt or diet files in vibe.d

2024-02-01 Thread Menjanahary R. R. via Digitalmars-d-learn
On Thursday, 1 February 2024 at 03:20:31 UTC, dunkelheit wrote: this is my code, I'm a begginer on vibe, and I want to use html and not diet files `import vibe.vibe; void main() { auto settings = new HTTPServerSettings; settings.port = 8080; settings.bindAddresses =

Mutability issue

2024-03-23 Thread Menjanahary R. R. via Digitalmars-d-learn
The next code works as is but ... ``` import std.stdio; import std.traits; bool isPrime(T)(T n) if (isIntegral!T) { if (n <= T(3)) return n > T(1); if (n % T(2) == T(0) || n % T(3) == T(0)) return false; for (T candidate = T(5); candidate * candidate <= n; candidate += T(6)) {

Re: Mutability issue

2024-03-24 Thread Menjanahary R. R. via Digitalmars-d-learn
On Saturday, 23 March 2024 at 20:38:40 UTC, Jonathan M Davis wrote: On Saturday, March 23, 2024 1:30:29 PM MDT Menjanahary R. R. via Digitalmars- d-learn wrote: [...] Well, when nextPrime is instantiated, the type of T is inferred from the function argument. So, if num is int, then T is int

Re: Mutability issue

2024-03-24 Thread Menjanahary R. R. via Digitalmars-d-learn
On Saturday, 23 March 2024 at 20:49:14 UTC, Nick Treleaven wrote: On Saturday, 23 March 2024 at 19:30:29 UTC, Menjanahary R. R. wrote: for (T candidate = T(5); candidate * candidate <= n; candidate += T(6)) { When T is `const int`, the above code declares and initializes a constant

Re: Mutate immutable inside shared static constructor

2024-03-24 Thread Menjanahary R. R. via Digitalmars-d-learn
On Saturday, 23 March 2024 at 21:59:57 UTC, Nick Treleaven wrote: On Saturday, 23 March 2024 at 21:53:43 UTC, Jonathan M Davis wrote: Yes, it's a bug. It's a clear violation of the type system if a non-mutable variable is ever given a value more than once. It should be initialized, and then it

Re: Range handling difficulties

2024-04-24 Thread Menjanahary R. R. via Digitalmars-d-learn
On Wednesday, 24 April 2024 at 14:22:10 UTC, H. S. Teoh wrote: On Wed, Apr 24, 2024 at 08:08:06AM +, Menjanahary R. R. via Digitalmars-d-learn wrote: [...] evenfib.until!(n => n > 4_000_000).sum.writeln; T Thanks a lot! You've made my day 

Range handling difficulties

2024-04-24 Thread Menjanahary R. R. via Digitalmars-d-learn
I tried to solve Project Euler [problem #2](https://projecteuler.net/problem=2) using [Recurrence/recurrence](https://dlang.org/library/std/range/recurrence.html). Assuming `genEvenFibonacci` is the appropriate funtion in Explicit form, I got what I need like so: ``` auto evenfib =

Re: Setting field of struct object

2024-05-14 Thread Menjanahary R. R. via Digitalmars-d-learn
On Monday, 22 January 2024 at 08:54:21 UTC, Danilo wrote: On Monday, 22 January 2024 at 08:35:01 UTC, Joel wrote: [...] Nonetheless, this usually used with Objects (new class/struct instances), like so: ```d import std; [...] Fluent Interface 