Re: length's type.

2024-02-09 Thread Gary Chike via Digitalmars-d-learn
On Friday, 9 February 2024 at 16:49:37 UTC, Gary Chike wrote: The underlying architecture of the language will often times dictate how certain constructs or design decisions are made. For example in Ada, every array has a `Length` attribute and it returns an `integer` type. And since Ada is

Re: How to unpack a tuple into multiple variables?

2024-02-09 Thread Gary Chike via Digitalmars-d-learn
On Thursday, 8 February 2024 at 06:09:29 UTC, Menjanahary R. R. wrote: Refactored it a bit to have a ready to run and easy to grasp code. Enjoy! Thank you Menjanahary R.! I've saved the code to review and learn from! :>

Re: length's type.

2024-02-09 Thread Gary Chike via Digitalmars-d-learn
On Friday, 9 February 2024 at 12:15:29 UTC, Sergey wrote: On Friday, 9 February 2024 at 08:04:56 UTC, Danilo wrote: Rust, Nim, Zig, Odin…? Here is the Forum for D(lang). ;) But it is fine to see what others have.. Teach on their experience is useful This is how research is going Thank you

Re: length's type.

2024-02-08 Thread Gary Chike via Digitalmars-d-learn
On Friday, 9 February 2024 at 02:55:48 UTC, Gary Chike wrote: On Friday, 9 February 2024 at 02:13:04 UTC, Gary Chike wrote: I spoke too soon, it appears Zig's default return type for its `len()` function is: `usize' - similar to Rust. ```rust const std = @import("std"); pub fn main() !void

Re: length's type.

2024-02-08 Thread Gary Chike via Digitalmars-d-learn
On Friday, 9 February 2024 at 02:13:04 UTC, Gary Chike wrote: Reviewing the default return type in a couple more newer languages for the length function or equivalent. (`len()`, `length()`, `size()`): The Nim language appears to return an `int` type: ```python let something = @['a', 'b',

Re: length's type.

2024-02-08 Thread Gary Chike via Digitalmars-d-learn
On Thursday, 8 February 2024 at 16:54:36 UTC, Kevin Bailey wrote: Additionally, it doesn't address the issue. It still requires me to both realize the issue with comparing an int to length's mystery type, as well as to fix it for the compiler. (And it's beside the fact that the start value

Re: length's type.

2024-02-07 Thread Gary Chike via Digitalmars-d-learn
On Wednesday, 7 February 2024 at 20:08:24 UTC, Gary Chike wrote: On Wednesday, 7 February 2024 at 19:32:56 UTC, Gary Chike wrote: double c = (double)sumArray(a, aLength) / aLength; If I don't cast explicitly: `double c = sumArray(a, aLength) / aLength;` then I will get a similar

Re: length's type.

2024-02-07 Thread Gary Chike via Digitalmars-d-learn
On Wednesday, 7 February 2024 at 19:32:56 UTC, Gary Chike wrote: On Wednesday, 7 February 2024 at 19:20:12 UTC, Gary Chike wrote: The output wasn't quite right. So I tweaked it a bit: ```c long sumArray(long arr[], size_t size) { long total = 0; for (size_t i = 0; i < size; ++i) {

Re: length's type.

2024-02-07 Thread Gary Chike via Digitalmars-d-learn
On Wednesday, 7 February 2024 at 19:20:12 UTC, Gary Chike wrote: I just had to transcribe this to C just for grins :D ```c #include int sumArray(int arr[], size_t size) { int total = 0; for (size_t i = 0; i < size; ++i) { total += arr[i]; } return total; } int

Re: length's type.

2024-02-07 Thread Gary Chike via Digitalmars-d-learn
On Sunday, 28 January 2024 at 17:25:49 UTC, mw wrote: See the result here: https://forum.dlang.org/post/cagloplexjfzubncx...@forum.dlang.org I knew this outlandish output had to do with mixing of signed and unsigned types with resulting overflow. But I like the way Anthropic Claude2

Re: How to unpack a tuple into multiple variables?

2024-02-07 Thread Gary Chike via Digitalmars-d-learn
On Wednesday, 7 February 2024 at 13:18:00 UTC, ryuukk_ wrote: There was a DIP for native tuples in D, hopefully we'll get it soon I just wanted to define DIP for newbs since we're in a new users thread. If they look it up, they will see: Dependency Inversion Principle, Dip programming

Re: How to unpack a tuple into multiple variables?

2024-02-06 Thread Gary Chike via Digitalmars-d-learn
On Wednesday, 7 February 2024 at 01:17:33 UTC, zjh wrote: Officially, there should be an unpacking solution, like ```d //C++ auto[a,b,c]=tuple. ``` Wouldn't that be nice? I hope a clean and terse direct-implementation comes in the near future. :)

Re: How to unpack a tuple into multiple variables?

2024-02-06 Thread Gary Chike via Digitalmars-d-learn
On Tuesday, 6 February 2024 at 07:17:34 UTC, Profunctor wrote: On Monday, 5 February 2024 at 21:12:58 UTC, Gary Chike wrote: For either of these, one can "unpack" some or none of a Tuple's fields, and both can be modified to ignore any field to simulate `val (name, _, prof) = ("John Doe",

Re: How to unpack a tuple into multiple variables?

2024-02-05 Thread Gary Chike via Digitalmars-d-learn
On Monday, 5 February 2024 at 21:21:33 UTC, TTK Ciar wrote: My mnemonic: "put" is "tup" backwards, and undoes what tuple does. Very clever mnemonic TTK Ciar! :) After reviewing the various solutions, the one I seem to gravitate towards is based on the one you presented, well, at least for

Re: How to unpack a tuple into multiple variables?

2024-02-05 Thread Gary Chike via Digitalmars-d-learn
On Monday, 5 February 2024 at 21:30:15 UTC, Sergey wrote: In those posts you can find other "solutions", Tuple DIP description and other useful ideas. Thank you Sergey! Still reading through the different 'solutions' - very informative.

How to unpack a tuple into multiple variables?

2024-02-05 Thread Gary Chike via Digitalmars-d-learn
I hope all is well with everyone. I have come to an impasse. What is the best way to unpack a tuple into multiple variables in D similar to this Python code? Thank you! ```python # Example tuple my_tuple = (2010, 10, 2, 11, 4, 0, 2, 41, 0) # Unpack the tuple into separate variables year,

Re: macOS Sonoma Linker Issue

2023-10-18 Thread Gary Chike via Digitalmars-d-learn
On Wednesday, 4 October 2023 at 11:01:08 UTC, Johan wrote: Try passing `-ld_classic` to the linker. (`dmd -L-ld_classic`) This works for me as well, thank you! I'm running macOS Sonoma and XCode 15.0 (15A240d). It appears XCode 15's linker errors are wreaking havoc with quite a few other

Re: Traverse a DList and insert / remove in place?

2023-03-27 Thread Gary Chike via Digitalmars-d-learn
On Monday, 27 March 2023 at 15:05:16 UTC, Armando wrote: Wonderful, that works like a treat, thank you so much! For those who wonder, inserting after works too: Very cool! Thanks for asking and sharing! :)

Re: Calling readln() after readf

2022-07-06 Thread Gary Chike via Digitalmars-d-learn
Thanks for the extra info guys! D is one of my favorite languages I'm currently learning. :)

Re: Calling readln() after readf

2022-07-05 Thread Gary Chike via Digitalmars-d-learn
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 appropriate datatype Makes sense. The following

Re: Calling readln() after readf

2022-06-26 Thread Gary Chike via Digitalmars-d-learn
On Monday, 20 June 2022 at 16:08:33 UTC, Ali Çehreli wrote: Makes sense. The following are related as well: https://dlang.org/library/std/conv/parse.html https://dlang.org/library/std/format/read/formatted_read.html Ali Thank you so much for your input! Cheers! :)

Re: Calling readln() after readf

2022-06-20 Thread Gary Chike via Digitalmars-d-learn
I should have qualified the above with: _ and I will be performing operations on the numeric datatype, since just outputting simply strings, as in the above example, would require nothing more than string data types. :) ```d module hello_world; import std.stdio; import std.string; // strip()

Re: Calling readln() after readf

2022-06-20 Thread Gary Chike via Digitalmars-d-learn
On Monday, 20 June 2022 at 00:43:17 UTC, Ali Çehreli wrote: ... But when the program interacts with piped data, there may be multiple \n characters and all of those might have to be ignored before reading the next non-empty line. So you may want to do readln.strip multiple times? I don't

Re: Calling readln() after readf

2022-06-19 Thread Gary Chike via Digitalmars-d-learn
On Saturday, 24 April 2021 at 22:13:45 UTC, Ali Çehreli wrote: On 4/24/21 7:46 AM, PinDPlugga wrote: ... As a general solution, you can use a function like this: auto readLine(S = string)(File file = stdin) { while (!file.eof) { auto line = file.readln!S.strip; if (!line.empty) {