Re: Is there such concept of a list in D?
On Sunday, 11 December 2022 at 03:13:17 UTC, zjh wrote: On Saturday, 10 December 2022 at 19:49:23 UTC, Salih Dincer wrote: SDB@79 Can the `range` be partially traversed? That is, suppose we only access the `[3,5)` elements? Certainly, there are many ways to do this. For example: ```d //... myList1.skipRange(3).rangePrint; /* 1: Sivrihisar 2: Shemseddin 3: Nasruddin 4: Nusrat */ myNames[3..5].rangePrint; /* 1: Sivrihisar 2: Shemseddin */ } auto skipRange(R)(R range, size_t value) { size_t loop = value; while(!range.empty && loop--) { range.popFront(); } return range; } void rangePrint(R)(R range) { import std.stdio; size_t i = 1; foreach(item; range) { writeln(i++, ": ", item); } writeln; } ``` SDB@79
Graphical progressive fill
I've been trying to fill in areas with a colour but can't work it out. I want something like the effect where it fills with diamonds. Not all at once but building up in the main program loop. # # # # # # # # # # # # # # # # # #### # # # # # ## # # #### # # # # ### # ## #
Re: arsd.jni
On Saturday, 10 December 2022 at 22:53:14 UTC, jni wrote: Friends, I have decided to use D lang to link with the Android NDK. I can make an app that can use the android platform's functions and the android site says they are available in C for linux and windows! Making apps in android studio or 2 other programs I have used before is easy but now I require D because of the advantages quality innovations I have written inside a D library, second I would use the D std library for using curl, and it needs to be in an apk for now and maybe in the years to come I will switch to using a binary executable. As you can see, linking with the NDK from D is the one possible outcome. I have succesfully linked with the NDK and learned valuable linux programming along the way, but before I get too over-enthusiastic and joyous and get ahead of myself to make an error in trying to use the optional Android Studio together with the arsd.jni, please, I wish to share with you my questions and concerns for the best way to move forward with this massive undertaking this thing, and how to go about calling android platform functions using arsd.jni and other D lang technologies from code.Dlang.org that may be useful to me. For starters I wish to call the wifi functions for checking internet availability. How can I achieve this most efficiently? Then there are the maven questions because Android Studio does many of these automatically, and from my experience does an annoyingly gross job at it, btw unless you use all of their official tools. How do I use the maven for using jars or an Apache repository for server communication? I am using gradle with all this and everything works fine. Any suggestions on how to start this thing is welcome. I will connect through SSL with a remote server and print a log on the server side. On the Android side only connect and wait for further data to be recieved and if the stream finishes then it should stop the app. That part will mean sleeping the app until when it is relaunched. The server is php code. I tried to add in correct place on forums. Thank you. Friends I am troubling you with too simple of a message. Please allow me to not be dissapointing myself here. Friends, mainly the focus of this very simple project is I will try to use the Android NDK "framework" API, as it is called, once I have linked succesfully, as I have already tested, next all that is left is to use the Android platform's NDK API from D lang code because I am trying my best not to use Java. I was wanting to include the JNI for good measure but was already planning to use the NDK API with extern(C). I thought it would be straight-forward since I knew that the Android platform used jni in the OS, but after doing some digging all I could find was the API reference over on android.com. There isn't much complication to be done only I was catching myself guessing how to go about it most efficiently for such a simple and small project. I would try to call the NDK API functions since it is the most low-level and C-like functional programming. I know much less of Java and will try to write the minimum I can. What I need is D lang because I have a D module to include into the app, there may be code.dlang.org packages that I may want to use, I will be using the std lib curl functions, there is the possibility of having to include functions from a seperate C library in the future if all goes well, the need to use maven for an Apache project's client and adding 2 other jars for it that are personal libraries, the possibility of using Android Studio if things get rocky. As you see there is no other way. I must use D or find something else to do. A small project as this that I would like only simplicity, any recommendations or suggestions on how would be the best way to go through with this?
Why can't rvalues be passed to a 'ref' parameter?
Hello, I am not really understanding why rvalues cannot be passed to a 'ref' parameter, the explanation in the book about D I am reading was not clear: "The main reason for this limitation is the fact that a function taking a ref parameter can hold on to that reference for later use, at a time when the rvalue would not be available." I didn't really understand what Ali meant by this statement, any help would be appreciated so this can be clarified. Regards, thebluepandabear
Re: Is there such concept of a list in D?
On Saturday, 10 December 2022 at 19:49:23 UTC, Salih Dincer wrote: SDB@79 Can the `range` be partially traversed? That is, suppose we only access the `[3,5)` elements?
Re: Advent of Code 2022
On Saturday, 10 December 2022 at 20:49:03 UTC, Christian Köstlin wrote: Is anybody participating with dlang in the advent of code 22? It would be interesting to discuss dlang specific things from the puzzles. Kind regards, Christian https://forum.dlang.org/thread/adkugbopvfbcycknx...@forum.dlang.org
Re: Advent of Code 2022
On Saturday, 10 December 2022 at 20:49:03 UTC, Christian Köstlin wrote: Is anybody participating with dlang in the advent of code 22? It would be interesting to discuss dlang specific things from the puzzles. Mine: https://github.com/schveiguy/adventofcode -Steve
Advent of Code 2022
Is anybody participating with dlang in the advent of code 22? It would be interesting to discuss dlang specific things from the puzzles. Kind regards, Christian
Re: Is there such concept of a list in D?
On Saturday, 10 December 2022 at 05:46:26 UTC, thebluepandabear wrote: In most languages there is some sort of `List` type, is that the same for D? The standard library has many possibilities, including linked lists. What about the news from the range... In D, the concept of range is very advanced. Now I'm going to show you 3 examples and two of them are from the standard library and the other is a nice wrap: ```d struct List(A) { A[] *arr; auto put(R)(R value) { (*arr) ~= value; } auto length() { return (*arr).length; } auto empty() { import std.range : empty; return (*arr).empty; } auto front() { import std.range : item = front;//back; return (*arr).item; } void popFront() { import std.range : next = popFront;//popBack (*arr).next; } } auto listHelper(A)(return ref A[] arr) { return List!A(); } alias immutable(char[]) [] strings; void main() { strings myNames = ["El-Mevla", "Hodja", "Nasreddin", "Sivrihisar", "Shemseddin", "Nasruddin", "Nusrat"]; strings list; auto myList1 = listHelper(list); import std.range; auto myList2 = appender!strings; import std.container.array; auto myList3 = Array!string(); foreach(name; myNames) { myList1.put(name); myList2.put(name); myList3.insert(name); } void rangePrint(R)(R range) { import std.stdio; size_t i = 1; foreach(item; range) { writeln(i++, ": ", item); } writeln; } rangePrint(myList1); rangePrint(myList2); rangePrint(myList3); } ``` SDB@79
Re: Is there such concept of a list in D?
On 12/9/22 22:11, thebluepandabear wrote: > I was wondering more if there is an object oriented way of creating > arrays, Every collection has its own special interface. Object orientation don't go well with collections. For example, you wouldn't want indexing operator for a linked list. > like in Java there is an `ArrayList`, in C++ there is > `std::vector`, etc. They are all dynamic arrays behind the scenes. Arrays are so much better than linked lists that linked lists don't have much use outside of interviews. - Arrays use less memory - Provide constant time element access - Amortized constant time element addition - Constant time element removal in some cases (move the last element in place of the removed one) - Ability to sort to find elements in logN time later on - Arrays get special help from the CPU (e.g. cache prefetches) There isn't a single point in favor of linked lists. Ali
Re: printf, writeln, writefln
On Thursday, 8 December 2022 at 17:39:58 UTC, Ali Çehreli wrote: On 12/8/22 08:21, Salih Dincer wrote: > void stringCopy(Chars)(string source, > ref Chars target) >sample.stringCopy = cTxt; // disappeared ? char Nothing disappeared on my system. (?) Going off-topic, I find the expression above extremely confusing. I am used to assignment expression changing the value of the left hand side, but that expression changes cTxt. Very confusing... Such obfuscations make it very hard for me to understand what the code is trying to demonstrate. Yes, with function call syntax it's more understandable if an argument is modified. It was bizarre and confusing that assignment syntax was implemented for functions and methods not explicitly marked with @property.