Re: length's type.
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 a very strongly typed language, there is no choice but to explicitly cast both the numerator and denominator. Ada will not allow you to cast only the numerator and allow the compiler to implicitly cast the denominator as is the case in most C-based languages. This will not compile: `Avg := Float(Sum) / Len;` ``` with Ada.Text_IO; use Ada.Text_IO; with Ada.Float_Text_IO; use Ada.Float_Text_IO; procedure Main is type Int_Array is array (Positive range <>) of Integer; A : Int_Array := (-5000, 0); Len : Integer := A'Length; Sum : Integer := A(1) + A(2); Avg : Float; begin Avg := Float(Sum) / Float(Len); Put(Avg, 1, 2, 0); New_Line; end Main; ``` Output: -2500.00
Re: How to unpack a tuple into multiple variables?
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: Vibe D: Get access to files
In the files, dt specified the path to the files from the root `/style.css` and now, with any path from the root, files are loaded into the page, instead of `style.css`. My mistake.
Re: length's type.
On Friday, 9 February 2024 at 12:15:29 UTC, Sergey 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 Sorry, I probably got confused by the use of different languages in every posting.
Re: length's type.
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 Sergey! I definitely appreciate the wider perspective I've gained by peering into multiple languages. For example, Ada, being a Wirthian language, has an N-index based system, so indices can be negative which necessitates a return type of a signed type for the Length attribute. Pascal, Lua, and PL/I are other languages that are also N-index based vs just being either 0-index(most languages) or 1-index based (eg. Julia, Matlab, Fortran). :)
Re: length's type.
On Friday, 9 February 2024 at 11:00:09 UTC, thinkunix wrote: First off I, I am just a beginner with D. I joined this list to try to learn more about the language not to but heads with experts. I'm sorry if you took my response that way. Hi thinkunix, I did interpret your post as critical. Sorry if it wasn't intended to be and my reply had a little too much heat. I still think my reply was at least accurate, so replies below. My post was merely to show how, with my rudimentary knowledge, I could get the loop to execute 4 times, which appeared (to me) to be the intent of your code. Thank you for the exercise. I learned more about the D type system. I said I would not write code like that because: * why start at -1 if array indexes start at 0? The program that I was writing was most elegant doing that. Obviously I wasn't doing something as simple as the example. The post is simply to highlight the issue. Unfortunately I can't find the examples now. The code has been altered so grepping isn't finding it and, since AoC has 25 days, I'm not sure which ones it was. It /might/ have been this, where 'where_to_start' is signed and can be negative. It's a weird index of indexes thing, and quite unconventional. // Try it in the remaining groups. for (auto i = where_to_start; i < num_ss.length; ++i) * why use auto which made the type different than what .length is? Google "almost always auto" for why you should prefer it - don't miss Herb Sutter's post - but as someone else pointed out, it's no better with 'int' *or* 'ulong'. The "best" solution is to cast the returned length to long. This makes it work and, unless you're counting the atoms in the universe, should be sufficient on a reasonable machine. This is why I brought up the example. zjh was lamenting having to cast, as am I, much less think this hard about it. You provided no context, or comment indicated what you were trying to achieve by starting with -1. Clearly I didn't understand your intent. I wasn't asking a question. I know how to code this in D and I made it work. My post was to highlight the completely unnecessary need to cast. What happens when there's a more reasonable example? What happens when you need to compare 2 library function results when one is signed and the other not? Would you even know that you had to cast one? Or would you just get strange results and not know why? The issue exists completely outside of my example. Since you sound new, I'll mention that, yes, what I'm proposing can be a hair slower. But so what? 99 of a 100 programs won't notice and, if it does, your profiler will tell you where, you add the cast (or you add it ahead time, since that's what we have to do now), done. I understand that it is almost certainly too late for D but the world seems ready for an alternative to C++ and lots of languages are coming. This is just part of that discussion, right?
Re: length's type.
On Friday, 9 February 2024 at 11:00:09 UTC, thinkunix wrote: If your issue is that the compiler didn't catch this, shouldn't you raise the issue on a compiler internals list? Maybe I've misunderstood the purpose of d-learn "Questions about learning and using D". It's been discussed many, many times. The behavior is not going to change - there won't even be a compiler warning. (You'll have to check with the leadership for their reasons.) I think something like this, which is such an obviously bad design and hits so many new users, should be discussed in the learn forum so new users are aware of what's going on.
Re: std.uni CodepointSet toString
On 09/02/2024 9:04 PM, Danilo wrote: Instead of bug fixing and stabilization, people concentrate on getting new stuff like ˋ:blubˋ into the language. Umm, I take it that you didn't know that one of the reasons we spent the past year focusing on bug fixing and stabilization is because of my work trying to get shared library support resolved? My focus is upon making D's foundations stable, and that work comes in many forms and yes some of that is in new features which help resolve other problems in the ecosystem. Whether it be getting D's identifiers able to express recent C versions and hence interoperability, making sure how we represent and work with symbols actually work without error in common situations or just fixing random bugs where something minor was messed up some place. They are all stabilization and bug fixing tasks that I have some thing to do with. People are doing what they can to make D better, and we are all aware for those of us who actively contribute that D has a very large backlog of bugs that need resolving.
Re: length's type.
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
Re: length's type.
Kevin Bailey via Digitalmars-d-learn wrote: On Thursday, 8 February 2024 at 08:23:12 UTC, thinkunix wrote: I would never write code like this. By all means, please share with us how you would have written that just as elegantly but "correct". First off I, I am just a beginner with D. I joined this list to try to learn more about the language not to but heads with experts. I'm sorry if you took my response that way. My post was merely to show how, with my rudimentary knowledge, I could get the loop to execute 4 times, which appeared (to me) to be the intent of your code. Thank you for the exercise. I learned more about the D type system. I said I would not write code like that because: * why start at -1 if array indexes start at 0? * why use auto which made the type different than what .length is? You provided no context, or comment indicated what you were trying to achieve by starting with -1. Clearly I didn't understand your intent. It would also break if the array 'something' had more than int.max elements. Then don't cast it to an int. First of all, why didn't you cast it to a long? I only "cast(int)something.length" so the type would match the type that "auto i = -1" would get, which was int, and this was to prevent comparing incompatible types, which caused the conversion, and the loop not to execute at all. As a beginner, I would expect that if you mismatch types, you can expect bad things to happen, and this is probably true in any language. If your issue is that the compiler didn't catch this, shouldn't you raise the issue on a compiler internals list? Maybe I've misunderstood the purpose of d-learn "Questions about learning and using D". scot
Re: How to get the client's MAC address in Vibe
On Thursday, 8 February 2024 at 01:05:57 UTC, Mengu wrote: On Wednesday, 7 February 2024 at 22:16:54 UTC, Alexander Zhirov wrote: Is there a way to identify a client by MAC address when using the Vibe library? The `NetworkAddress` [structure](https://vibed.org/api/vibe.core.net/NetworkAddress) does not provide such features. Or did I miss something? That doesn't have anything to do with the server side if I am not mistaken as you should receive that via the browser that actually allows you to receive the mac address -via an extension- or some private API exposed by the browser. I don't know the use case but you may be better off with browser fingerprinting if you'd like to have a unique way of identifying the visitors. Or, if it's a local network, maybe you can use tcpdump/libpcap. It is at the packet level to monitor the address. Not at all what I would like. Thanks for the tip:)
Re: How to get the client's MAC address in Vibe
On Thursday, 8 February 2024 at 14:21:13 UTC, Steven Schveighoffer wrote: On Wednesday, 7 February 2024 at 22:16:54 UTC, Alexander Zhirov wrote: Is there a way to identify a client by MAC address when using the Vibe library? The `NetworkAddress` [structure](https://vibed.org/api/vibe.core.net/NetworkAddress) does not provide such features. Or did I miss something? Mac is a hardware address. By the time the packets get to your server, that info is long gone. Even if you could get it, it likely is the MAC address of your router, not the peer. -Steve You are right, information is lost at the packet level and nothing reaches the browser anymore. I will look for another way. Thanks!
Re: std.uni CodepointSet toString
On Thursday, 8 February 2024 at 18:43:09 UTC, H. S. Teoh wrote: 11 years and we still haven't fixed all the problems?! That's ... wow. Incredible! Seems like D is experiencing featuritis. Priorities may be wrong. Instead of bug fixing and stabilization, people concentrate on getting new stuff like ˋ:blubˋ into the language. It‘s interesting to see this. But it‘s not positive to watch this. The featuritis is just creating chaos, not a stable programming language you can count on.