Re: Finding position of a value in an array
On Tuesday, 31 December 2019 at 04:38:53 UTC, Daren Scot Wilson wrote: I'm needing to see more examples. It might have something to do with the array I'm working with being inside a foreach loop. My code looks like this, with the problematic line duplicated to show some of the variations I tried: import std.algorithm; alias doo = ubyte; struct Info { int x; doo[NDOOS] doos; // NDOOS = 10 } immutable int INFO = 10; Info[NINFOS] infos;// global array, used heavily. float foo_function(doo important_d){ ... foreach (info; infos){ int i = info.doos.index(important_d); // #1 int i = info.doos.countUntil(d => d == important_d); // #2 int i = info.doos.countUntil!(d => d == important_d); // #3 int i = countUntil(d => d == important_d, info.doos); // #4 int i = countUntil!(d => d == important_d)(info.doos); // #5 if (i>=0) { // assuming -1 represents value not found ... do stuff with i ... } } ... } All the lines shown give me "template ... cannot deduce function from argument types..." but one time I got, but cannot reproduce now, the error "Error: template instance countUntil!((d) => d == important_d, doos) has no value" countUntil operates on ranges, and static arrays aren't ranges. To get a range from a static array, you have to slice it with the `[]` operator: int i = info.doos[].countUntil(important_d); (Why can't static arrays be ranges? Because ranges can shrink, via popFront, but a static array can never change its length.)
Re: Finding position of a value in an array
On Monday, 30 December 2019 at 23:15:48 UTC, JN wrote: On Sunday, 29 December 2019 at 08:31:13 UTC, mipri wrote: int i = a.countUntil!(v => v == 55); assert(i == 2); I also had to ask because I couldn't find it. In other languages it's named "index()", "indexOf()" or "find()". D is the only language I know which uses the "countUntil" scheme. And even so it's not obvious from the name if it's the index of the element or number of preceding elements. I had first tried myarray.index(myvalue) because I coulda sworn I wrote exactly that syntax a only a few days ago. But I've been hopping between languages, some D, some Crystal, some C++, some Javascript, and with only two cerebral hemispheres, maybe I got confused. So, D doesn't have index()? Is it called find()? Something else? It was hard to find the right stuff in the documentation. So now I know about countUntil, and I'm glad the question has gotten some traction for others to make progress with their code. I'm needing to see more examples. It might have something to do with the array I'm working with being inside a foreach loop. My code looks like this, with the problematic line duplicated to show some of the variations I tried: import std.algorithm; alias doo = ubyte; struct Info { int x; doo[NDOOS] doos; // NDOOS = 10 } immutable int INFO = 10; Info[NINFOS] infos;// global array, used heavily. float foo_function(doo important_d){ ... foreach (info; infos){ int i = info.doos.index(important_d); // #1 int i = info.doos.countUntil(d => d == important_d); // #2 int i = info.doos.countUntil!(d => d == important_d); // #3 int i = countUntil(d => d == important_d, info.doos); // #4 int i = countUntil!(d => d == important_d)(info.doos); // #5 if (i>=0) { // assuming -1 represents value not found ... do stuff with i ... } } ... } All the lines shown give me "template ... cannot deduce function from argument types..." but one time I got, but cannot reproduce now, the error "Error: template instance countUntil!((d) => d == important_d, doos) has no value"
Re: Some code that compiles but shouldn't
On Monday, 30 December 2019 at 18:18:49 UTC, uranuz wrote: I have created library/ framework to handle JSON-RPC requests using D methods. I use some *template magic* to translate JSON-RPC parameters and return values from/ and to JSON. And I have encountered funny bug that at first was hard to find. My programme just segfaulted when call to this method occured: void getCompiledTemplate(HTTPContext ctx) { import std.exception: enforce; enforce(ctx, `ctx is null`); enforce(ctx.request, `ctx.request is null`); enforce(ctx.request.form, `ctx.request is null`); enforce(ivyEngine !is null, `ivyEngine is null`); string moduleName = ctx.request.form[`moduleName`]; auto mod = ivyEngine.getByModuleName(moduleName); return ctx.response.write(mod.toStdJSON().toString()); } So as you see I have added a lot of enforce to test if all variables are not null. But nothing was null and the reason of segfault were unclear. Today I just went home. Opened a bottle of beer. And have noticed that function is marked as returning `void`, but in fact it doesn't. When I fixed this segfault have gone. But why this even compiled?! Interesting... We also have a piece of code, see here https://github.com/huntlabs/hunt-examples/blob/master/website-basic/source/app/controller/IndexController.d#L133. It's a wrong function declaration. There is no error message when compiling it. However, the showString() can't be called via the browser, because the router mapping fails. What happened for this is that the IndexController is not used directly by others. It's used in `mixin MakeController;`, see https://github.com/huntlabs/hunt-framework/blob/master/source/hunt/framework/application/Controller.d#L153. So the conclusion is the mixin needs to do more works to check the validation in mixined code.
Re: What type does byGrapheme() return?
On Mon, Dec 30, 2019 at 03:31:31PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: > On Mon, Dec 30, 2019 at 03:09:58PM -0800, H. S. Teoh via Digitalmars-d-learn > wrote: > [...] > > I suspect the cause is that whatever Grapheme.opSlice returns is > > going out-of-scope when used with .map, that's why it's > > malfunctioning. > [...] > > Haha, it's actually right there in the Grapheme docs for the opSlice > overloads: > > Random-access range over Grapheme's $(CHARACTERS). > > Warning: Invalidates when this Grapheme leaves the scope, > attempts to use it then would lead to memory corruption. > > Looks like when you use .map over the Grapheme, it gets copied into a > temporary, which gets invalidated when map.front returns. Somewhere > we're missing a 'scope' qualifier... [...] Indeed, compiling with dmd -dip1000 produces this error message: test.d(15): Error: returning g.opSlice() escapes a reference to parameter g, perhaps annotate with return /usr/src/d/phobos/std/algorithm/iteration.d(499):instantiated from here: MapResult!(__lambda1, Grapheme[]) test.d(15):instantiated from here: map!(Grapheme[]) Not the most helpful message (the annotation has to go in Phobos code, not in user code), but it does at least point to the cause of the problem. T -- What doesn't kill me makes me stranger.
How to use ResizerWidget in Dlangui app..?
Hi, I suspect I'm missing something obvious, but ResizerWidget is not working for me on Windows - it shows the 'dragging'-cursor when hovering the mouse on the ResizerWidget, but dragging with the left mouse button does nothing. Reduced very simple example: ///app.d import dlangui; import gui; mixin APP_ENTRY_POINT; /// entry point for dlangui based application extern (C) int UIAppMain(string[] args) { // create window Window window = Platform.instance.createWindow("DlangUI example", null); //Make main layout auto mainGui = new GuiHandler(); window.mainWidget = mainGui.makeGui(window); // show window window.show(); // run message loop return Platform.instance.enterMessageLoop(); } /// gui.d import dlangui; class GuiHandler : ResizeHandler { Widget makeGui(Window w) { //Make main layout auto vlayout = new VerticalLayout(); vlayout.margins = 20; vlayout.padding = 10;ets vlayout.backgroundColor = 0xC0; vlayout.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); // Layout for editors auto editorsLayout = new LinearLayout(); editorsLayout.orientation = Orientation.Vertical; //Make edit + trace windows auto editor = new EditBox(); editorsLayout.addChild(editor); auto resizer = new ResizerWidget(); // resizer.resizeEvent.connect(this); //Connect for handling events in onResize. editorsLayout.addChild(resizer); auto tracer = new LogWidget(); editorsLayout.addChild(tracer); editorsLayout.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); vlayout.addChild(editorsLayout); return vlayout; } override void onResize(ResizerWidget source, ResizerEventType event, int currentPosition) { //Not shown... } } I searched through all the dlangui examples where ResizerWidget is used, and none of them provides any onResize event handler as shown above. But, since none of them work (symptoms exactly the same as mine), I am wondering if this is required? Also checking in DlanguiIDE - nowhere does it implements the onResize event handler for ResizerWidget either. I find this a bit odd - in none of the projects where ResizerWidget are used does it work, but none of these projects provide the onResize event handler either. Which makes me suspect it is supposed to work 'out of the box' and does not require the event handler for the basic dragging functionality - similar how resizing the whole window works without requiring that you implement it yourself in the OnResize event handler for the main Widget. Also - I can hardly believe that Vadim would have kept putting it in examples, but without it working, so I suspect some regression here if I am not doing something stupid myself (which is always possible!). There are plenty of 'deprecated' warnings when building dlangui and, since dlangui has not been updated since 2018, I'm concerned it may be breaking with new versions of the compiler. Alternatively I'm missing something elementary here..? Has anyone used ResizerWidget successfully with a recent version of the compiler on Windows? win 7 DMD32 D Compiler v2.089.1 dlangui-0.9.182
Re: What type does byGrapheme() return?
On Mon, Dec 30, 2019 at 03:09:58PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > I suspect the cause is that whatever Grapheme.opSlice returns is going > out-of-scope when used with .map, that's why it's malfunctioning. [...] Haha, it's actually right there in the Grapheme docs for the opSlice overloads: Random-access range over Grapheme's $(CHARACTERS). Warning: Invalidates when this Grapheme leaves the scope, attempts to use it then would lead to memory corruption. Looks like when you use .map over the Grapheme, it gets copied into a temporary, which gets invalidated when map.front returns. Somewhere we're missing a 'scope' qualifier... T -- War doesn't prove who's right, just who's left. -- BSD Games' Fortune
Re: Finding position of a value in an array
On Sunday, 29 December 2019 at 08:31:13 UTC, mipri wrote: int i = a.countUntil!(v => v == 55); assert(i == 2); I also had to ask because I couldn't find it. In other languages it's named "index()", "indexOf()" or "find()". D is the only language I know which uses the "countUntil" scheme. And even so it's not obvious from the name if it's the index of the element or number of preceding elements.
Re: What type does byGrapheme() return?
On Sun, Dec 29, 2019 at 01:19:09PM +0100, Robert M. Münch via Digitalmars-d-learn wrote: > On 2019-12-27 19:44:59 +, H. S. Teoh said: [...] > > If you want to add/delete/change graphemes, what you *really* want > > is to use an array of Graphemes: > > > > Grapheme[] editableGraphs; > > > > You can then splice it, insert stuff, delete stuff, whatever. > > > > When you're done with it, convert it back to string with something > > like this: > > > > string result = editableGraphs.map!(g => g[]).joiner.to!string; > > I played around with this approach... > > string r1 = "Robert M. Münch"; > // Code-Units = 16 > // Code-Points = 15 > // Graphemes = 15 > > Grapheme[] gr1 = r1.byGrapheme.array; > writeln(" Text = ", gr1.map!(g => g[]).joiner.to!string); > // Text = obert M. Münch > writeln("wText = ", gr1.map!(g => g[]).joiner.to!wstring); > // wText = obert M. Münch > writeln("dText = ", gr1.map!(g => g[]).joiner.to!dstring); > // dText = obert M. Münch > > Why is the first letter missing? Is this a bug? [...] I suspect there's a scope-related bug/issue somewhere here. I did some experiments and discovered that using foreach to iterate over a Grapheme[] is OK, but somehow when using Grapheme[] with .map to slice over each one, I get random UTF-8 encoding errors and missing characters. I suspect the cause is that whatever Grapheme.opSlice returns is going out-of-scope when used with .map, that's why it's malfunctioning. The last time I looked at the Grapheme code, there's a bunch of memory-related stuff involving dtors that's *probably* the cause of this problem. Please file a bug for this. T -- Life is complex. It consists of real and imaginary parts. -- YHL
Re: Finding position of a value in an array
On Monday, 30 December 2019 at 19:46:50 UTC, Ron Tarrant wrote: Thanks, mipri. Got it sorted. Here's a working proof... ``` import std.stdio; import std.algorithm; import std.conv; void main(string[] args) { MyObject[] objectArray; MyObject newObject; MyObject findPointer; long index; int lastObjectID = 7; int foundObjectIndex; for(int i; i < 12; i++) { lastObjectID++; newObject = new MyObject(lastObjectID); objectArray ~= newObject; if(i is 5) { findPointer = newObject; } } for(int i; i < objectArray.length; i++) { writeln("object: ", cast(MyObject*)objectArray[i], ", ID: ", objectArray[i].objectID); } index = objectArray.countUntil(findPointer); writeln("findPointer: ", findPointer, ", at address: ", cast(MyObject*)findPointer, " is a MyObject pointer in the objectArray with an index of ", index, ", address: ", cast(MyObject*)objectArray[index], ", ID: ", objectArray[index].objectID); } // main() class MyObject { int objectID; this(int ordinal) { objectID = ordinal; } // this() } // class MyObject ``` Compare: import std.stdio; import std.algorithm; import std.conv; void main(string[] args) { MyObject[] objectArray; MyObject newObject; MyObject findPointer; long index; int foundObjectIndex; for(int i; i < 12; i++) { newObject = new MyObject(); objectArray ~= newObject; if(i is 5) { findPointer = newObject; } } for(int i; i < objectArray.length; i++) { writeln("object: ", cast(MyObject*)objectArray[i]); } index = objectArray.countUntil(findPointer); writeln("findPointer: ", findPointer, ", at address: ", cast(MyObject*)findPointer, " is a MyObject pointer in the objectArray with an index of ", index, ", address: ", cast(MyObject*)objectArray[index]); } // main() class MyObject {} With output: object: 7F2DC37C3000 object: 7F2DC37C3020 object: 7F2DC37C3030 object: 7F2DC37C3040 object: 7F2DC37C3050 object: 7F2DC37C3060 object: 7F2DC37C3070 object: 7F2DC37C3080 object: 7F2DC37C3090 object: 7F2DC37C30A0 object: 7F2DC37C30B0 object: 7F2DC37C30C0 findPointer: x297.MyObject, at address: 7F2DC37C3060 is a MyObject pointer in the objectArray with an index of 5, address: 7F2DC37C3060
Re: Some code that compiles but shouldn't
On Monday, 30 December 2019 at 19:09:13 UTC, MoonlightSentinel wrote: On Monday, 30 December 2019 at 18:18:49 UTC, uranuz wrote: So as you see I have added a lot of enforce to test if all variables are not null. But nothing was null and the reason of segfault were unclear. What about moduleName, mod and the return value of mod.toStdJSON()? And whats the return type of ctx.response.write? (Returning a void expression is allowed and avoids some special casing in generic code) OK. This example compiles... void bar() {} void main() { return bar(); }
Re: Some code that compiles but shouldn't
On Monday, 30 December 2019 at 19:09:13 UTC, MoonlightSentinel wrote: On Monday, 30 December 2019 at 18:18:49 UTC, uranuz wrote: So as you see I have added a lot of enforce to test if all variables are not null. But nothing was null and the reason of segfault were unclear. What about moduleName, mod and the return value of mod.toStdJSON()? And whats the return type of ctx.response.write? (Returning a void expression is allowed and avoids some special casing in generic code) I have reviewed this code and ctx.response.write(...) returns void too.. ;-) So I don't even know if this is correct or no? Could I use `return void;`?
Re: Finding position of a value in an array
On Monday, 30 December 2019 at 19:39:04 UTC, mipri wrote: You can definitely do it: $ rdmd --eval 'int a, b, c; [, , ].countUntil().writeln' 2 But you need to have an array of pointers. Thanks, mipri. Got it sorted. Here's a working proof... ``` import std.stdio; import std.algorithm; import std.conv; void main(string[] args) { MyObject[] objectArray; MyObject newObject; MyObject findPointer; long index; int lastObjectID = 7; int foundObjectIndex; for(int i; i < 12; i++) { lastObjectID++; newObject = new MyObject(lastObjectID); objectArray ~= newObject; if(i is 5) { findPointer = newObject; } } for(int i; i < objectArray.length; i++) { writeln("object: ", cast(MyObject*)objectArray[i], ", ID: ", objectArray[i].objectID); } index = objectArray.countUntil(findPointer); writeln("findPointer: ", findPointer, ", at address: ", cast(MyObject*)findPointer, " is a MyObject pointer in the objectArray with an index of ", index, ", address: ", cast(MyObject*)objectArray[index], ", ID: ", objectArray[index].objectID); } // main() class MyObject { int objectID; this(int ordinal) { objectID = ordinal; } // this() } // class MyObject ```
Re: Finding position of a value in an array
On Monday, 30 December 2019 at 19:46:50 UTC, Ron Tarrant wrote: Thanks, mipri. Got it sorted. Here's a working proof... Forgot to show the output: object: 17B0A831000, ID: 8 object: 17B0A831020, ID: 9 object: 17B0A831060, ID: 10 object: 17B0A831080, ID: 11 object: 17B0A8310A0, ID: 12 object: 17B0A8310C0, ID: 13 object: 17B0A8310E0, ID: 14 object: 17B0A831100, ID: 15 object: 17B0A831120, ID: 16 object: 17B0A831140, ID: 17 object: 17B0A831160, ID: 18 object: 17B0A831180, ID: 19 findPointer: find_in_array_object.MyObject, at address: 17B0A8310C0 is a MyObject pointer in the objectArray with an index of 5, address: 17B0A8310C0, ID: 13
Re: Finding position of a value in an array
On Monday, 30 December 2019 at 19:08:27 UTC, Ron Tarrant wrote: On Monday, 30 December 2019 at 17:12:26 UTC, MoonlightSentinel wrote: D disallows implicit conversion from integers to pointers and hence they cannot be compared. You would need to explicitly cast your ulong to an appropriate pointer type I'm not trying to convert, just wade through an array of pointers to find a specific pointer using searchUntil(). I mean, it's not a big deal if I can't do it. You can definitely do it: $ rdmd --eval 'int a, b, c; [, , ].countUntil().writeln' 2 But you need to have an array of pointers.
Re: Finding position of a value in an array
On Monday, 30 December 2019 at 19:08:27 UTC, Ron Tarrant wrote: I'm not trying to convert, just wade through an array of pointers to find a specific pointer using searchUntil(). ** that should read: countUntil(), not searchUntil() * Turns out I was getting too complicated. countUntil() works on object references as well, even if printing object references to a shell doesn't seem to differentiate between them.
Re: Finding position of a value in an array
On Monday, 30 December 2019 at 17:12:26 UTC, MoonlightSentinel wrote: D disallows implicit conversion from integers to pointers and hence they cannot be compared. You would need to explicitly cast your ulong to an appropriate pointer type I'm not trying to convert, just wade through an array of pointers to find a specific pointer using searchUntil(). I mean, it's not a big deal if I can't do it. Adding an ID property and searching on that is just as effective and likely just as efficient.
Re: Some code that compiles but shouldn't
On Monday, 30 December 2019 at 18:18:49 UTC, uranuz wrote: So as you see I have added a lot of enforce to test if all variables are not null. But nothing was null and the reason of segfault were unclear. What about moduleName, mod and the return value of mod.toStdJSON()? And whats the return type of ctx.response.write? (Returning a void expression is allowed and avoids some special casing in generic code)
Re: Finding position of a value in an array
On Monday, 30 December 2019 at 14:41:55 UTC, mipri wrote: What's your code? 'find_in_array_object.MyObject' doesn't look like a pointer. It's an array of objects... or, what it's trying to be, an array of object pointers.
Re: Some code that compiles but shouldn't
On Mon, Dec 30, 2019 at 06:18:49PM +, uranuz via Digitalmars-d-learn wrote: [...] > void getCompiledTemplate(HTTPContext ctx) > { > import std.exception: enforce; > enforce(ctx, `ctx is null`); > enforce(ctx.request, `ctx.request is null`); > enforce(ctx.request.form, `ctx.request is null`); > enforce(ivyEngine !is null, `ivyEngine is null`); > string moduleName = ctx.request.form[`moduleName`]; > auto mod = ivyEngine.getByModuleName(moduleName); > return ctx.response.write(mod.toStdJSON().toString()); > } > > > So as you see I have added a lot of enforce to test if all variables > are not null. But nothing was null and the reason of segfault were > unclear. Today I just went home. Opened a bottle of beer. And have > noticed that function is marked as returning `void`, but in fact it > doesn't. When I fixed this segfault have gone. But why this even > compiled?! Interesting... That's weird indeed. Do you have a minimal case that reproduces this problem? I tried to return the result of a non-void function call from a void function, and it wouldn't compile, as expected. It would be interesting to see when exactly this compiler check is wrongly skipped. T -- Ignorance is bliss... until you suffer the consequences!
Some code that compiles but shouldn't
I have created library/ framework to handle JSON-RPC requests using D methods. I use some *template magic* to translate JSON-RPC parameters and return values from/ and to JSON. And I have encountered funny bug that at first was hard to find. My programme just segfaulted when call to this method occured: void getCompiledTemplate(HTTPContext ctx) { import std.exception: enforce; enforce(ctx, `ctx is null`); enforce(ctx.request, `ctx.request is null`); enforce(ctx.request.form, `ctx.request is null`); enforce(ivyEngine !is null, `ivyEngine is null`); string moduleName = ctx.request.form[`moduleName`]; auto mod = ivyEngine.getByModuleName(moduleName); return ctx.response.write(mod.toStdJSON().toString()); } So as you see I have added a lot of enforce to test if all variables are not null. But nothing was null and the reason of segfault were unclear. Today I just went home. Opened a bottle of beer. And have noticed that function is marked as returning `void`, but in fact it doesn't. When I fixed this segfault have gone. But why this even compiled?! Interesting...
Re: What kind of Editor, IDE you are using and which one do you like for D language?
On 12/30/19 1:43 AM, H. S. Teoh wrote: On Mon, Dec 30, 2019 at 01:26:11AM +, bachmeier via Digitalmars-d-learn wrote: [...] I have trouble seeing how an IDE is going to make anyone a better programmer. [...] Yeah, I call BS on that statement. OTOH, it's certainly a valid point that IDE support needs to be good in order to appeal to that subset of programmers who prefer to work in an IDE. I don't use an IDE for D programming, just vim + cmdline. However, I DO use one for php (Netbeans) and Swift (xcode). In both cases, I'm not as familiar with the standard library. In the case of PHP, my IDE tells me types, so it can auto-complete member names (I need this for that project). And especially in the case of Swift, the long verbose names of everything are hard to guess and hard to remember. Not to mention the visual editing of the UI for iOS apps. If I wrote more code in those languages, I might get to the point where I could remember all the proper names. But I still probably would use the code completion for it to avoid spelling errors -- something like iota is not readily descriptive of what it does, but it's a lot easier to spell correctly than didFinishSettingUpViewController or whatever the hell the real name is. IMO, the two killer IDE features are code completion and syntax highlighting. Almost every editor (not IDE) already does syntax highlighting and many support code completion. Most of the other stuff is not critical for success. I can read the compiler outputs and figure out the locations of stuff. Yeah, it's nice to have the editor show me there is an error. But I can deal with it otherwise. -Steve
Re: What kind of Editor, IDE you are using and which one do you like for D language?
On Mon, Dec 30, 2019 at 04:13:03PM +, Patrick Schluter via Digitalmars-d-learn wrote: [...] > Good point. It also trains people to not be able to work without IDE. > I see it at work with some of the Java devs who aren't even able to > invoke javac in a command line and setting javapath correctly. Why? > Because IDE shielded them from these easy things. It has also a > corrolary that they're not capable to implement sometimes simple > protocols or file processings without resorting to external libraries. > A little bit like people needing even and odd library in Javascript. This is the natural consequence of pursuing popularity by making things accessible to the lowest common denominator. You can't say it's wrong -- because without it, the programming industry wouldn't be anywhere near where it is today. But OTOH, some aspects of programming are inherently hard, and no matter what you do, you simply cannot remove the necessity of thought about your programming problem. T -- I've been around long enough to have seen an endless parade of magic new techniques du jour, most of which purport to remove the necessity of thought about your programming problem. In the end they wind up contributing one or two pieces to the collective wisdom, and fade away in the rearview mirror. -- Walter Bright
Re: What kind of Editor, IDE you are using and which one do you like for D language?
On Mon, Dec 30, 2019 at 02:59:22PM +, bachmeier via Digitalmars-d-learn wrote: [...] > An IDE adds a crapload to the learning curve. It's terrible, because > they need to memorize a bunch of steps when they use a GUI (click here > -> type this thing in this box -> click here -> ...) [...] To me, that's not necessarily the failure of the principle of using an IDE, but of the way in which existing IDEs are designed. Modern IDEs suffer from the same wrong design principles as modern browsers: too much accumulated technical debt and cruft accumulated from decades of legacy code, old habits that die hard, inertia in the name of backwards compatibility, and stagnation. Somebody should seriously rethink the whole design of the IDE experience. I, for one, in spite of currently preferring to work with vim + CLI tools, would love to see an IDE which does its job in a minimalistic, on-demand way, in which you only pay for what you use, and it does not take 5 minutes grinding your harddisk to next week and back again just to start up. What about an IDE that starts at lightning speed where you can immediately start typing code? Where you can just run the code immediately -- with the compilation steps *shown* and saved in a clear-text script that you can edit, as opposed to some mysterious black magic welded shut under the hood? Where advanced features are loaded on demand and unloaded when no longer used, as opposed to requiring GBs of RAM just to start up? The technology to do all this is already there, it just takes someone to think outside of the box and design something that doesn't look, run, and feel like an overweight elephant with an obesity problem. (OTOH, I may have just described Vim and the modern Linux shell. Oops. :-D) T -- BREAKFAST.COM halted...Cereal Port Not Responding. -- YHL
Re: Finding position of a value in an array
On Monday, 30 December 2019 at 14:30:12 UTC, Ron Tarrant wrote: I was trying to do this with an array of pointers, but I get an error (which suggests to me that I don't know what data type a pointer is): It's not a ulong? Have I forgotten so much? D disallows implicit conversion from integers to pointers and hence they cannot be compared. You would need to explicitly cast your ulong to an appropriate pointer type
Re: What kind of Editor, IDE you are using and which one do you like for D language?
On Monday, 30 December 2019 at 14:59:22 UTC, bachmeier wrote: On Monday, 30 December 2019 at 06:43:03 UTC, H. S. Teoh wrote: [...] Another way in which the IDE is "heavy" is the amount of overhead for beginning/occasional users. I like that I can get someone started using D like this: 1. Open text editor 2. Type simple program 3. Compile by typing a few characters into a terminal/command prompt. An IDE adds a crapload to the learning curve. It's terrible, because they need to memorize a bunch of steps when they use a GUI (click here -> type this thing in this box -> click here -> ...) Back when I was teaching intro econ courses, which are taken by nearly all students here, I'd sometimes be talking with students taking Java or C++ courses. One of the things that really sucked (beyond using Java for an intro programming class) was that they'd have to learn the IDE first. Not only were they hit with this as the simplest possible program: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } } but before they even got there, the instructor went through an entire lecture teaching them about the IDE. That's an effective way to make students think programming is a mind-numbingly stupid task on par with reading the phone book. Contrast that with students opening a text editor, typing `print "Hello World"` and then running the program. IDE support should obviously be made available. I think it would be a mistake, however, to move away from the simplicity of being able to open a text editor, type in a few lines, and then compile and run in a terminal. It's not just beginners. This is quite handy for those who will occasionally work with D code. For someone in my position (academic research), beginners and occasional programmers represents most of the user base. Good point. It also trains people to not be able to work without IDE. I see it at work with some of the Java devs who aren't even able to invoke javac in a command line and setting javapath correctly. Why? Because IDE shielded them from these easy things. It has also a corrolary that they're not capable to implement sometimes simple protocols or file processings without resorting to external libraries. A little bit like people needing even and odd library in Javascript.
Re: What kind of Editor, IDE you are using and which one do you like for D language?
On Monday, 30 December 2019 at 06:43:03 UTC, H. S. Teoh wrote: Generally, I find myself *much* more productive with CLI-based tools; IDEs are generally much heavier in terms of memory and CPU usage, and worst of all, require a GUI, which for me is a deal-breaker because I do a lot of work over SSH connections on not necessarily reliable networks. The amount of network traffic needed to operate a GUI over a remote desktop is just so much more than the much lighter weight of a few keystrokes that for me it's a very unproductive choice. That, plus the amount of RAM + CPU + disk investment needed just to get an IDE to even start, to me cannot even begin to compare to how few resources are needed to be highly productive with a bare-bones Vim installation. I just have a hard time justifying such an investment when what I get in return is so undesirable within my operational parameters. Another way in which the IDE is "heavy" is the amount of overhead for beginning/occasional users. I like that I can get someone started using D like this: 1. Open text editor 2. Type simple program 3. Compile by typing a few characters into a terminal/command prompt. An IDE adds a crapload to the learning curve. It's terrible, because they need to memorize a bunch of steps when they use a GUI (click here -> type this thing in this box -> click here -> ...) Back when I was teaching intro econ courses, which are taken by nearly all students here, I'd sometimes be talking with students taking Java or C++ courses. One of the things that really sucked (beyond using Java for an intro programming class) was that they'd have to learn the IDE first. Not only were they hit with this as the simplest possible program: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } } but before they even got there, the instructor went through an entire lecture teaching them about the IDE. That's an effective way to make students think programming is a mind-numbingly stupid task on par with reading the phone book. Contrast that with students opening a text editor, typing `print "Hello World"` and then running the program. IDE support should obviously be made available. I think it would be a mistake, however, to move away from the simplicity of being able to open a text editor, type in a few lines, and then compile and run in a terminal. It's not just beginners. This is quite handy for those who will occasionally work with D code. For someone in my position (academic research), beginners and occasional programmers represents most of the user base.
Re: Concatenation/joining strings together in a more readable way
On Monday, 30 December 2019 at 10:23:14 UTC, Marcone wrote: On Monday, 30 December 2019 at 09:41:55 UTC, mipri wrote: This leaks too much. writeln("Helo {} {}".format("xx", "name")); // Helo xx name writeln("Helo {} {}".format("{}", "name")); // Helo name {} This function replace {} for arguments received. You just need don't send {} as arguments. I tested native function format() in Python: print("Helo {} {}".format("{}", "name")) # Helo {} name Nothing wrong, working same way. It doesn't work the same way. These are not the same: Helo name {} Helo {} name Python's implementation doesn't get confused if your format() arguments include a {}.
Re: Finding position of a value in an array
On Monday, 30 December 2019 at 14:30:12 UTC, Ron Tarrant wrote: On Sunday, 29 December 2019 at 09:44:18 UTC, MoonlightSentinel wrote: int i = a.countUntil(55); I was trying to do this with an array of pointers, but I get an error (which suggests to me that I don't know what data type a pointer is): find_in_array_object.d(25): Error: cannot cast expression newObject of type find_in_array_object.MyObject to ulong What's your code? 'find_in_array_object.MyObject' doesn't look like a pointer.
Re: Finding position of a value in an array
On Sunday, 29 December 2019 at 09:44:18 UTC, MoonlightSentinel wrote: int i = a.countUntil(55); I was trying to do this with an array of pointers, but I get an error (which suggests to me that I don't know what data type a pointer is): find_in_array_object.d(25): Error: cannot cast expression newObject of type find_in_array_object.MyObject to ulong find_in_array_object.d(34): Error: template std.algorithm.searching.countUntil cannot deduce function from argument types !()(MyObject[], ulong), candidates are: C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm\searching.d(768):std.algorithm.searching.countUntil(alias pred = "a == b", R, Rs...)(R haystack, Rs needles) if (isForwardRange!R && (Rs.length > 0) && (isForwardRange!(Rs[0]) == isInputRange!(Rs[0])) && is(typeof(startsWith!pred(haystack, needles[0]))) && (Rs.length == 1 || is(typeof(countUntil!pred(haystack, needles[1..__dollar]) C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm\searching.d(856): std.algorithm.searching.countUntil(alias pred = "a == b", R, N)(R haystack, N needle) if (isInputRange!R && is(typeof(binaryFun!pred(haystack.front, needle)) : bool)) C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm\searching.d(915): std.algorithm.searching.countUntil(alias pred, R)(R haystack) if (isInputRange!R && is(typeof(unaryFun!pred(haystack.front)) : bool)) It's not a ulong? Have I forgotten so much?
Re: What kind of Editor, IDE you are using and which one do you like for D language?
On Sunday, 29 December 2019 at 21:25:44 UTC, Adam D. Ruppe wrote: My experience is IDEs are just different, not necessarily better or worse. Just different enough that people used to one find the others difficult to learn. Amen, hear-hear, and all that. I thought it was just me.
Re: What kind of Editor, IDE you are using and which one do you like for D language?
On Sunday, 29 December 2019 at 14:41:46 UTC, Russel Winder wrote: On Sat, 2019-12-28 at 22:01 +, p.shkadzko via Digitalmars-d-learn wrote: […] p.s. I found it quite satisfying that D does not really need an IDE, you will be fine even with nano. The fundamental issue with these all battery included fancy IDE's (especially in Java) is that they tend to become dependencies of the projects themselves. How many times have I seen in my professionnal world, projects that required specific versions of Eclipse with specific versions of extensions and libraries? At my work we have exactly currently the problem. One developer wrote one of the desktop apps and now left the company. My colleagues of that department are now struggling to maintain the app as it used some specific GUI libs linked to some Eclipse version and they are nowhere to be found. You may object that it's a problem of the project management and I would agree. It was the management error to let the developer choose the IDE solution in the first place. A more classical/portable approach would have been preferable. Furthermore, it is extremely annoying that these IDE change over time and all the fancy stuff gets stale and changed with other stuff that gets stale after time. Visual Studio is one of the worst offenders in that category. Every 5 years it changes so much that everything learnt before can be thrown away. IDE's work well for scenarios that the developers of the IDE thought of. Anything a little bit different requires changes that are either impossible to model or require intimate knowledge of the functionning of the IDE. Visual Studio comes to mind again of an example where that is horribly painful (I do not even mention the difficulty to even install such behemoth programs on our corporate laptops which are behind stupid proxies and follow annoying corporate policy rules).
Re: What kind of Editor, IDE you are using and which one do you like for D language?
On 30/12/2019 9:19 PM, Piotr Mitana wrote: On Sunday, 22 December 2019 at 17:20:51 UTC, BoQsc wrote: There are lots of editors/IDE's that support D language: https://wiki.dlang.org/Editors What kind of editor/IDE are you using and which one do you like the most? IntelliJ IDEA CE with this extension: https://intellij-dlanguage.github.io/ Wow, nobody else uses this? I do.
Re: Concatenation/joining strings together in a more readable way
On Monday, 30 December 2019 at 09:41:55 UTC, mipri wrote: On Monday, 30 December 2019 at 06:47:37 UTC, Marcone wrote: Use Python format() style: import std; import std: Format = format; // format() string format(T...)(T text){ string texto = text[0]; foreach(count, i; text[1..$]){ texto = texto.replaceFirst("{}", to!string(i)); texto = texto.replace("{%s}".Format(to!string(count)), to!string(i)); } return texto; } This leaks too much. writeln("Helo {} {}".format("xx", "name")); // Helo xx name writeln("Helo {} {}".format("{}", "name")); // Helo name {} This function replace {} for arguments received. You just need don't send {} as arguments. I tested native function format() in Python: print("Helo {} {}".format("{}", "name")) # Helo {} name Nothing wrong, working same way. Works with index too. writeln("Hi, my name is {1} and I live in {0}.".format("Brasil", "Marcone")); writeln("Hi, my name is {} and I live in {}.".format("Marcone", "Brasil"));
Re: Concatenation/joining strings together in a more readable way
On Monday, 30 December 2019 at 06:47:37 UTC, Marcone wrote: Use Python format() style: import std; import std: Format = format; // format() string format(T...)(T text){ string texto = text[0]; foreach(count, i; text[1..$]){ texto = texto.replaceFirst("{}", to!string(i)); texto = texto.replace("{%s}".Format(to!string(count)), to!string(i)); } return texto; } This leaks too much. writeln("Helo {} {}".format("xx", "name")); // Helo xx name writeln("Helo {} {}".format("{}", "name")); // Helo name {}
Re: How create a function that receive a function and run it in another threading?
On Friday, 27 December 2019 at 07:06:52 UTC, mipri wrote: On Friday, 27 December 2019 at 06:08:16 UTC, Marcone wrote: import std; import core.thread; auto threading(lazy void fun){ return task!fun().executeInNewThread(); } void main(){ threading(writeln("Hello World!")); } I want to create a function threading() to run some function in other threading, but I get this error bellow. How can I get success? Error: static function Programa.threading.Task!(fun).Task.impl cannot access frame of function Programa.threading Error: template instance `Programa.threading.Task!(fun)` error instantiating This works: import std; import core.thread; auto threading(void function() fun){ return task(fun).executeInNewThread(); } void main(){ writeln("Main: ", thisTid); threading({ writeln("Hello, ", thisTid); }); } or you can use just https://dlang.org/library/std/concurrency/spawn.html from std.concurrency to avoid needless bike construction. Best regards, Alexandru.
Re: What kind of Editor, IDE you are using and which one do you like for D language?
On Sunday, 22 December 2019 at 17:20:51 UTC, BoQsc wrote: There are lots of editors/IDE's that support D language: https://wiki.dlang.org/Editors What kind of editor/IDE are you using and which one do you like the most? IntelliJ IDEA CE with this extension: https://intellij-dlanguage.github.io/ Wow, nobody else uses this?
Re: What type does byGrapheme() return?
On Friday, 27 December 2019 at 17:26:58 UTC, Robert M. Münch wrote: ... There are set of range interfaces that can be used to mask range type. Check for https://dlang.org/library/std/range/interfaces/input_range.html for starting point, and for https://dlang.org/library/std/range/interfaces/input_range_object.html for wrapping any range to those interfaces. Note: resulting wrapped range is an object and has reference semantics, beware of using it directly with other range algorithms as they can consume your range. Best regards, Alexandru.