Re: std.socket.Address not allowed in tuples
On Wednesday, 23 January 2019 at 16:30:33 UTC, Neia Neutuladh wrote: As always, it helps a lot to post the error message the compiler gave you. Sorry about that. The issue is that Address doesn't have a comparison operator defined, so the resulting tuple type can't be compared with the standard operators. You need to define your own function for comparing the tuples in question and pass that to RedBlackTree. Is there any documentation or examples of how to do that? The RedBlackTree documentation gives trivial examples like auto maxTree = redBlackTree!"a > b"(iota(5)); but, that doesn't really help me figure out how to do something more complex.
std.socket.Address not allowed in tuples
Can anyone please explain to me what's going on here? import std.container; import std.socket; import std.typecons; void main() { /* Doesn't work alias Rec_type = Tuple!(Address, "x", int, "y", int, "z"); RedBlackTree!Rec_type[] records; */ // Works alias Rec_type = Tuple!(int, "y", int, "z"); RedBlackTree!Rec_type[] records; } Why am I not allowed to put Address types in tuples?
Re: Runtime heterogeneous collections?
I'd like to thank everyone for their help! I was finally able to do what I'd like. I didn't end up using a variant, but maybe there's a better way to do what I want using it, and I just couldn't figure it out. Here's the solution I finally came up with: https://run.dlang.io/is/GdDDBp If anyone has any better solutions I'm all ears!
Runtime heterogeneous collections?
I want to create a heterogeneous collection of red-black trees, and I can't seem to figure out if it's possible. I can easily do: import std.container.rbtree; import std.typecons; void main() { alias Rec_type = Tuple!(int, "x", int, "y", int, "z"); RedBlackTree!Rec_type[1] test; } That works great, but I can only add red-black trees of Rec_type. What if I want the collection of red-black trees to be different? So if you printed out the collection of red-black trees you'd see something akin to: // Formatted for easier reading [ RedBlackTree([Tuple!(int, "x", int, "y", string, "z")(1, 2, "abc")]), RedBlackTree([Tuple!(int, "x", int, "y", int, "z")(1, 2, 3)]) ] Is it possible to do this?
Re: Why does nobody seem to think that `null` is a serious problem in D?
On Monday, 19 November 2018 at 21:23:31 On Monday, 19 November 2018 at 21:23:31 UTC, Jordi Gutiérrez Hermoso wrote: I'm not the only one who has done this. I can't find it right now, but I've seen at least one person open a bug report because they misunderstood this as a bug in dmd. I have been told a couple of times that this isn't something that needs to be patched in the language, but I don't understand. It seems like a very easy way to generate a segfault (and not a NullPointerException or whatever). I love Null in an empty class variable and I use it very often in my code. It simplifies a lot. What would be a better way? (practical not theoretical) Regards Ozan
Re: Using local import path
On Friday, 9 September 2016 at 09:31:54 UTC, pineapple wrote: On Friday, 9 September 2016 at 08:25:40 UTC, rikki cattermole wrote: TLDR: no you cannot do what you were thinking. Seems like something one ought to be able to do, though. DIP time? Where can I find DIP? Here? https://forum.dlang.org/group/issues
Using local import path
Hi Example: I have a module called "a.b.c"; and a second module called "a.b.c.d.e"; For importing i can use import a.b.c; import a.b.c.d.e; or with local names import abc = a.b.c; import abcde = a.b.c.d.e; Question: Is it possible to use something similar like following import abc = a.b.c; import abc.d.e; which would be a combination of a local renamed and enhanced path? I tried and it doesn't, could be a wrong using... Thanks & Regards, Ozan
Re: Asynchronous Programming and Eventhandling in D
On Tuesday, 5 July 2016 at 20:38:53 UTC, Eugene Wissner wrote: On Tuesday, 5 July 2016 at 08:24:43 UTC, O/N/S wrote: Hi ("Grüss Gott") I like the asynchronous events in Javascript. Is something similar possible in D? Found Dragos Carp's asynchronous library (https://github.com/dcarp/asynchronous). Are there any more integrated (in Phobos/in D) ways to work asynchronously? An example: One server ask a second server to calculate something big. The first server continues with his work, until the answer come back from the second. And so on... Using threads or fibers would be a way, but has not the same elegancy like the Javascript way. (To avoid discussions: D is better ;-) Greetings from Munich, Ozan Can you describe what would you like to see more concretly. I know js but how is it supposed to work for D? Maybe you can give some example, kind of pseudo code? It would help me much to build a concept and maybe we will see someday something usable in this area :) Hi, I took a typical example (using jquery lib, other js-libs have similar calls) $.ajax({ type: "POST", url: myurl, dataType: "JSON", data: $myData, async: true, success: function(success) { ... }, error: function(error) { ... } }); If response is successful -> call function(success) If response has errors -> call function(error) In the meanwhile the code can continue without waiting for the response. In D-style it would look like ...do something.. funcAjax(["type":"POST"...], delegateSuccess, delegateError); - or - funcAjax(["type":"POST"...], (success) => {...}, (error) => {...}); ...continue without waiting... Why delegates not functions? Because responses could require changes in data, which are outside (yeah, I know, it's also technically possible with function, but that's not the idea behind) Greetings from Munich, Ozan
Asynchronous Programming and Eventhandling in D
Hi ("Grüss Gott") I like the asynchronous events in Javascript. Is something similar possible in D? Found Dragos Carp's asynchronous library (https://github.com/dcarp/asynchronous). Are there any more integrated (in Phobos/in D) ways to work asynchronously? An example: One server ask a second server to calculate something big. The first server continues with his work, until the answer come back from the second. And so on... Using threads or fibers would be a way, but has not the same elegancy like the Javascript way. (To avoid discussions: D is better ;-) Greetings from Munich, Ozan
What would be the best way to work with huge class hierarchies?
Hi I'm trying to bring a class hierarchy with a lot of classes in D style. The original classes have sometimes identical names like "button" or "control". With the namespaces I've classes like followings ui.core.Button ...and subclasses like ui.web.mobile.Button ui.web.desktop.Button ui.desktop.Button and more like this. Which would be the best way to bring them in the D world? Apple-Style like UCButton, UWMButton, UWDButton, UDButton MS-style with the use of namespaces (ui.web.mobile.Button, ui.web.desktop.Button) Java like WebMobileButton, DesktopButton ? Regards, Ozan
some strange behavior
Writing a small opengl text printer (vertex based) I have found that the next lines are "illegal" to dmd (2.031): invariant float[][][] CHARS =[ [//A [0,0], [1/2f,2], [1,0], [3/4f,1], [1/4f,1] ] ]; dmd complains (compiling with dmd -c bug.d): bug.d(9): Error: cannot implicitly convert expression ([0.5F,2F]) of type float[2u] to int[] bug.d(9): Error: cannot implicitly convert expression ([0.75F,1F]) of type float[2u] to int[] bug.d(9): Error: cannot implicitly convert expression ([0.25F,1F]) of type float[2u] to int[] is this a bug? thanks. -- if this mesage is repeated there's a problem with my browser
some strange behavior
Writing a small opengl text printer (vertex based) I have found that the next lines are "illegal" to dmd (2.031): invariant float[][][] CHARS =[ [//A [0,0], [1/2f,2], [1,0], [3/4f,1], [1/4f,1] ] ]; dmd complains (compiling with dmd -c bug.d): bug.d(9): Error: cannot implicitly convert expression ([0.5F,2F]) of type float[2u] to int[] bug.d(9): Error: cannot implicitly convert expression ([0.75F,1F]) of type float[2u] to int[] bug.d(9): Error: cannot implicitly convert expression ([0.25F,1F]) of type float[2u] to int[] is this a bug? thanks.