Re: Concatenation of ubyte[] to char[] works, but assignation doesn't
On Sunday, 4 October 2015 at 21:57:44 UTC, Jonathan M Davis wrote: When appending, b to a, the elements in b are being copied onto the end of a, and presumably it works in this case, because a ubyte is implicitly convertible to char. But all it's doing is converting the individual elements. It's not converting the array. ... It make sense now, thanks.
Posix termios
Is it just me, or is not posix termios.h implemented in phobos? (git), I am looking at core.sys.linux.termios but all I get there is a few enums(B57600, B115200, etc..)?
Re: How to break gdb on D exception ?
On Sunday, 4 October 2015 at 14:31:43 UTC, BBasile wrote: On Friday, 2 October 2015 at 09:15:13 UTC, Dmitri wrote: On Friday, 2 October 2015 at 04:50:59 UTC, BBasile wrote: On Friday, 2 October 2015 at 04:46:51 UTC, BBasile wrote: On Friday, 2 October 2015 at 04:24:11 UTC, Adam D. Ruppe wrote: [...] unfortunately it doesn't work, i get --- (gdb) Function "d_throw"/"d_throwc" not defined. it was almost that actually, 'break _d_throwc Or you could break on a specific exception class's constructor. This would be better. 1/ because I could propose a modifiable list of the exception kinds to track in the options). 2/ because with _d_trow_c, info stack #1 is really not interesting. #2 or #3 is usually where the 'thing' really happens. How can I do that, for example with FileException class ? Ast visitor -> ThrowStatement -> detect class from token text -> break file:line ? Puting BP manally is not an option. I ask this for GDB integration in my IDE ;)
Re: gl3n does not seem to have an ortho function like glm. Any replacements?
On Monday, 5 October 2015 at 00:05:42 UTC, Rene Zwanenburg wrote: On Sunday, 4 October 2015 at 21:30:43 UTC, WhatMeWorry wrote: I'm porting some C++/OpenGL/glm code over to D, And I've run into a glm::ortho function. glm::mat4 projection = glm::ortho(0.0f, static_cast(WIDTH), 0.0f, static_cast (HEIGHT)); gl3n is great for vecs and mats but does not appear to have an ortho function. Any suggestions? Thanks in advance. https://github.com/Dav1dde/gl3n/blob/master/gl3n/linalg.d#L1284 Thanks! I did search all over before posting. I went back to GitHub in the search field and typed ortho. Got nothing. Typed in orthographic and got hits.
Re: Threading Questions
On Sunday, October 04, 2015 14:42:48 bitwise via Digitalmars-d-learn wrote: > Since D is moving towards a phobos with no GC, what will happen > to things that are classes like Condition and Mutex? Phobos and druntime will always use the GC for some things, and some things just plain need classes. Rather, we're trying to make it so that Phobos does not use the GC when it doesn't need to use the GC as well reduce how much the GC is required for stuff like string processing where lazy ranges can be used instead in many cases. As for Condition and Mutex specifically, I don't know whey they were ever classes except perhaps to take advantage of the monitor in Object. Maybe they'll get changed to structs, maybe they won't, but most D code is thread-local, and most of the code that isn't is going to use message passing, which means that explicit mutexes and conditions are unnecessary. So, most code won't be impacted regardless of what we do with Condition and Mutex. Regardless, I doubt that anything will be done with Condition or Mutex until shared is revisted, which is supposed to happen sometime soon but hasn't happened yet. What happens with shared could completely change how Condition and Mutex are handled (e.g. they don't support shared directly even though they should probably have most of their members marked with shared, because Sean Kelly didn't want to be doing anything with shared that he'd have to change later). - Jonathan M Davis
Re: gl3n does not seem to have an ortho function like glm. Any replacements?
On Sunday, 4 October 2015 at 21:30:43 UTC, WhatMeWorry wrote: I'm porting some C++/OpenGL/glm code over to D, And I've run into a glm::ortho function. glm::mat4 projection = glm::ortho(0.0f, static_cast(WIDTH), 0.0f, static_cast (HEIGHT)); gl3n is great for vecs and mats but does not appear to have an ortho function. Any suggestions? Thanks in advance. https://github.com/Dav1dde/gl3n/blob/master/gl3n/linalg.d#L1284
Re: Concatenation of ubyte[] to char[] works, but assignation doesn't
On Sunday, October 04, 2015 16:13:47 skilion via Digitalmars-d-learn wrote: > Is this allowed by the language or it is a compiler bug ? > > void main() { > char[] a = "abc".dup; > ubyte[] b = [1, 2, 3]; > a = b; // cannot implicitly convert expression (b) of type > ubyte[] to char[] > a ~= b; // works > } When appending, b to a, the elements in b are being copied onto the end of a, and presumably it works in this case, because a ubyte is implicitly convertible to char. But all it's doing is converting the individual elements. It's not converting the array. On other hand, assigning b to a would require converting the array, and array types don't implicitly convert to one another, even if their elements do. Honestly, I think that the fact that the character types implicitly convert to and from the integral types of the corresponding size is problematic at best and error-prone at worst, since it almost never makes sense to do something like append a ubyte to string. However, if it didn't work, then you'd have to do a lot more casting when you do math on characters, which would cause its own set of potential bugs. So, we're kind of screwed either way. - Jonathan M Davis
gl3n does not seem to have an ortho function like glm. Any replacements?
I'm porting some C++/OpenGL/glm code over to D, And I've run into a glm::ortho function. glm::mat4 projection = glm::ortho(0.0f, static_cast(WIDTH), 0.0f, static_cast (HEIGHT)); gl3n is great for vecs and mats but does not appear to have an ortho function. Any suggestions? Thanks in advance.
Re: std.functional:partial - disambiguating templated functions
On Sunday, 4 October 2015 at 20:34:53 UTC, John Colvin wrote: On Sunday, 4 October 2015 at 20:26:51 UTC, John Colvin wrote: template bish(T) { alias tmp = bish0!T; alias tmp = bish1!T; alias bish = tmp; } https://issues.dlang.org/show_bug.cgi?id=15156 Thanks very much, for both John. Laeeth.
Re: std.functional:partial - disambiguating templated functions
On Sunday, 4 October 2015 at 20:26:51 UTC, John Colvin wrote: template bish(T) { alias tmp = bish0!T; alias tmp = bish1!T; alias bish = tmp; } https://issues.dlang.org/show_bug.cgi?id=15156
Re: std.functional:partial - disambiguating templated functions
On Sunday, 4 October 2015 at 19:12:51 UTC, Laeeth Isharc wrote: On Sunday, 4 October 2015 at 18:24:08 UTC, John Colvin wrote: On Sunday, 4 October 2015 at 18:08:55 UTC, Laeeth Isharc wrote: On Sunday, 4 October 2015 at 17:17:14 UTC, Laeeth Isharc wrote: On Sunday, 4 October 2015 at 16:37:34 UTC, John Colvin wrote: On Sunday, 4 October 2015 at 15:45:55 UTC, Laeeth Isharc wrote: How do I persuade partial to tie itself to the appropriate overload? --- As far as I can see std.functional.partial only does one argument at a time. bars=partial!(partial!(partial!(slurpBars!BarType, filename), startDate), endDate); or maybe, I'm not sure, but maybe you can do: bars=partial!(slurpBars!BarType, AliasSeq!(filename, startDate, endDate)); If you find you really need to manually mess with overloads, use http://dlang.org/traits.html#getOverloads. You may have to wrap it in AliasSeq in some situations due to grammar/parser constraints. fwiw - still doesn't work (whether I use alias or auto, trying each of your solutions). I'll look at getOverloads. How do I distinguish between two overloads that return the same type but have different arguments? It looks like getOverloads only deals with cases where the return type is different, judging by the docs. getOverloads should give you all the overloads of a function, whether they return the same or different types. The example in the docs just happens to have different types. In general, return types are not considered when talking about overloads. For example, two functions that take the same arguments but have different return types are not overloaded, they are in conflict. Thanks for this. The only problem then is how to manipulate what getOverloads returns. (No need to do this now as it's not worth it - I just wanted to try using partial if it wasn't too much work. easier just to make an alternate declaration with the type in its name). Is this not a bug in the implementation of partial? import std.functional; import std.stdio; void bish(T)(string arg, string barg) { writefln("bishs: %s, %s",arg,barg,to!T); } void bish(T)(int argi, string barg) { writefln("bishi: %s, %s",argi,barg.to!T); } void main(string[] args) { alias b=partial!(bish!string,"hello"); // this line does not compile alias c=partial!(b,"therex"); b("there"); c(); } [laeeth@engine marketdata]$ dmd partial.d partial.d(15): Error: template partial.bish matches more than one template declaration: partial.d(4): bish(T)(string arg, string barg) and partial.d(8): bish(T)(int argi, string barg) partial knows which overload to call - I told it! The problem happens before partial. Something like alias b = bish!string; is an error, because it matches both templates. For some reason if you call it directly, e.g. bish!string("",""); that's ok, but I have no idea why. What you can do, is this: template bish(T) { void bish(string arg, string barg) { writefln("bishs: %s, %s",arg,barg.to!T); } void bish(int argi, string barg) { writefln("bishi: %s, %s",argi,barg.to!T); } } which is just a template containing an overload set, which is no problem. Or: void bish0(T)(string arg, string barg) { writefln("bishs: %s, %s",arg,barg.to!T); } void bish1(T)(int argi, string barg) { writefln("bishi: %s, %s",argi,barg.to!T); } alias bishStr = bish0!string; alias bishStr = bish1!string; void main(string[] args) { alias b=partial!(bishStr,"hello"); alias c=partial!(b,"therex"); b("there"); c(); } Or: void bish0(T)(string arg, string barg) { writefln("bishs: %s, %s",arg,barg.to!T); } void bish1(T)(int argi, string barg) { writefln("bishi: %s, %s",argi,barg.to!T); } template bish(T) { alias tmp = bish0!T; alias tmp = bish1!T; alias bish = tmp; } void main(string[] args) { alias b=partial!(bish!string, "hello"); alias c=partial!(b,"therex"); b("there"); c(); }
Re: buffered output to files
On Saturday, 3 October 2015 at 22:21:08 UTC, Gerald Jansen wrote: My simple test program is here: http://dpaste.dzfl.pl/329023e651c4. An alternative link to the program (that doesn't try to run it) http://codepad.org/FbHJJqYM.
Re: std.functional:partial - disambiguating templated functions
On Sunday, 4 October 2015 at 18:24:08 UTC, John Colvin wrote: On Sunday, 4 October 2015 at 18:08:55 UTC, Laeeth Isharc wrote: On Sunday, 4 October 2015 at 17:17:14 UTC, Laeeth Isharc wrote: On Sunday, 4 October 2015 at 16:37:34 UTC, John Colvin wrote: On Sunday, 4 October 2015 at 15:45:55 UTC, Laeeth Isharc wrote: How do I persuade partial to tie itself to the appropriate overload? --- As far as I can see std.functional.partial only does one argument at a time. bars=partial!(partial!(partial!(slurpBars!BarType, filename), startDate), endDate); or maybe, I'm not sure, but maybe you can do: bars=partial!(slurpBars!BarType, AliasSeq!(filename, startDate, endDate)); If you find you really need to manually mess with overloads, use http://dlang.org/traits.html#getOverloads. You may have to wrap it in AliasSeq in some situations due to grammar/parser constraints. fwiw - still doesn't work (whether I use alias or auto, trying each of your solutions). I'll look at getOverloads. How do I distinguish between two overloads that return the same type but have different arguments? It looks like getOverloads only deals with cases where the return type is different, judging by the docs. getOverloads should give you all the overloads of a function, whether they return the same or different types. The example in the docs just happens to have different types. In general, return types are not considered when talking about overloads. For example, two functions that take the same arguments but have different return types are not overloaded, they are in conflict. Thanks for this. The only problem then is how to manipulate what getOverloads returns. (No need to do this now as it's not worth it - I just wanted to try using partial if it wasn't too much work. easier just to make an alternate declaration with the type in its name). Is this not a bug in the implementation of partial? import std.functional; import std.stdio; void bish(T)(string arg, string barg) { writefln("bishs: %s, %s",arg,barg,to!T); } void bish(T)(int argi, string barg) { writefln("bishi: %s, %s",argi,barg.to!T); } void main(string[] args) { alias b=partial!(bish!string,"hello"); // this line does not compile alias c=partial!(b,"therex"); b("there"); c(); } [laeeth@engine marketdata]$ dmd partial.d partial.d(15): Error: template partial.bish matches more than one template declaration: partial.d(4): bish(T)(string arg, string barg) and partial.d(8): bish(T)(int argi, string barg) partial knows which overload to call - I told it! it works fine without templated arguments. so the following works fine: import std.functional; import std.stdio; void bish(string arg, string barg) { writefln("bishs: %s, %s",arg,barg); } void bish(int argi, string barg) { writefln("bishi: %s, %s",argi,barg); } void main(string[] args) { alias b=partial!(bish,"hello"); alias c=partial!(b,"therex"); b("there"); c(); }
Re: std.functional:partial - disambiguating templated functions
On Sunday, 4 October 2015 at 18:08:55 UTC, Laeeth Isharc wrote: On Sunday, 4 October 2015 at 17:17:14 UTC, Laeeth Isharc wrote: On Sunday, 4 October 2015 at 16:37:34 UTC, John Colvin wrote: On Sunday, 4 October 2015 at 15:45:55 UTC, Laeeth Isharc wrote: How do I persuade partial to tie itself to the appropriate overload? --- As far as I can see std.functional.partial only does one argument at a time. bars=partial!(partial!(partial!(slurpBars!BarType, filename), startDate), endDate); or maybe, I'm not sure, but maybe you can do: bars=partial!(slurpBars!BarType, AliasSeq!(filename, startDate, endDate)); If you find you really need to manually mess with overloads, use http://dlang.org/traits.html#getOverloads. You may have to wrap it in AliasSeq in some situations due to grammar/parser constraints. fwiw - still doesn't work (whether I use alias or auto, trying each of your solutions). I'll look at getOverloads. How do I distinguish between two overloads that return the same type but have different arguments? It looks like getOverloads only deals with cases where the return type is different, judging by the docs. getOverloads should give you all the overloads of a function, whether they return the same or different types. The example in the docs just happens to have different types. In general, return types are not considered when talking about overloads. For example, two functions that take the same arguments but have different return types are not overloaded, they are in conflict.
Re: std.functional:partial - disambiguating templated functions
On Sunday, 4 October 2015 at 17:17:14 UTC, Laeeth Isharc wrote: On Sunday, 4 October 2015 at 16:37:34 UTC, John Colvin wrote: On Sunday, 4 October 2015 at 15:45:55 UTC, Laeeth Isharc wrote: How do I persuade partial to tie itself to the appropriate overload? --- As far as I can see std.functional.partial only does one argument at a time. bars=partial!(partial!(partial!(slurpBars!BarType, filename), startDate), endDate); or maybe, I'm not sure, but maybe you can do: bars=partial!(slurpBars!BarType, AliasSeq!(filename, startDate, endDate)); If you find you really need to manually mess with overloads, use http://dlang.org/traits.html#getOverloads. You may have to wrap it in AliasSeq in some situations due to grammar/parser constraints. fwiw - still doesn't work (whether I use alias or auto, trying each of your solutions). I'll look at getOverloads. How do I distinguish between two overloads that return the same type but have different arguments? It looks like getOverloads only deals with cases where the return type is different, judging by the docs.
Re: std.functional:partial - disambiguating templated functions
On Sunday, 4 October 2015 at 16:37:34 UTC, John Colvin wrote: On Sunday, 4 October 2015 at 15:45:55 UTC, Laeeth Isharc wrote: How do I persuade partial to tie itself to the appropriate overload? --- As far as I can see std.functional.partial only does one argument at a time. bars=partial!(partial!(partial!(slurpBars!BarType, filename), startDate), endDate); or maybe, I'm not sure, but maybe you can do: bars=partial!(slurpBars!BarType, AliasSeq!(filename, startDate, endDate)); If you find you really need to manually mess with overloads, use http://dlang.org/traits.html#getOverloads. You may have to wrap it in AliasSeq in some situations due to grammar/parser constraints. fwiw - still doesn't work (whether I use alias or auto, trying each of your solutions). I'll look at getOverloads. Laeeth.
Re: std.functional:partial - disambiguating templated functions
On Sunday, 4 October 2015 at 16:37:34 UTC, John Colvin wrote: On Sunday, 4 October 2015 at 15:45:55 UTC, Laeeth Isharc wrote: How do I persuade partial to tie itself to the appropriate overload? I have: alias bars=partial!(slurpBars!BarType,filename,startDate,endDate); where there are two overloads of slurpBars: SomeBar[] slurpBars(SomeBar)(string filename,string datasetName, typeof(SomeBar.date) startDate, typeof(SomeBar.date) endDate) SomeBar[] slurpBars(SomeBar)(hid_t filehandle,string datasetName, typeof(SomeBar.date) startDate, typeof(SomeBar.date) endDate) And I receive the following error: Error: template kprop.marketdata.retrievebars.slurpBars matches more than one template declaration: Thanks. Laeeth. As far as I can see std.functional.partial only does one argument at a time. bars=partial!(partial!(partial!(slurpBars!BarType, filename), startDate), endDate); or maybe, I'm not sure, but maybe you can do: bars=partial!(slurpBars!BarType, AliasSeq!(filename, startDate, endDate)); If you find you really need to manually mess with overloads, use http://dlang.org/traits.html#getOverloads. You may have to wrap it in AliasSeq in some situations due to grammar/parser constraints. Thanks, John. I will give that a try. Laeeth.
Re: __simd_sto confusion
That's a shame. I've read that each compiler has his own quirks and not support everything dmd supports. I do want to keep the code as portable as possible. Guess I'll try using inline assembler and runtime checks for the right cpu architecture. Thanks for the help people.
Re: std.functional:partial - disambiguating templated functions
On Sunday, 4 October 2015 at 15:45:55 UTC, Laeeth Isharc wrote: How do I persuade partial to tie itself to the appropriate overload? I have: alias bars=partial!(slurpBars!BarType,filename,startDate,endDate); where there are two overloads of slurpBars: SomeBar[] slurpBars(SomeBar)(string filename,string datasetName, typeof(SomeBar.date) startDate, typeof(SomeBar.date) endDate) SomeBar[] slurpBars(SomeBar)(hid_t filehandle,string datasetName, typeof(SomeBar.date) startDate, typeof(SomeBar.date) endDate) And I receive the following error: Error: template kprop.marketdata.retrievebars.slurpBars matches more than one template declaration: Thanks. Laeeth. As far as I can see std.functional.partial only does one argument at a time. bars=partial!(partial!(partial!(slurpBars!BarType, filename), startDate), endDate); or maybe, I'm not sure, but maybe you can do: bars=partial!(slurpBars!BarType, AliasSeq!(filename, startDate, endDate)); If you find you really need to manually mess with overloads, use http://dlang.org/traits.html#getOverloads. You may have to wrap it in AliasSeq in some situations due to grammar/parser constraints.
Concatenation of ubyte[] to char[] works, but assignation doesn't
Is this allowed by the language or it is a compiler bug ? void main() { char[] a = "abc".dup; ubyte[] b = [1, 2, 3]; a = b; // cannot implicitly convert expression (b) of type ubyte[] to char[] a ~= b; // works }
std.functional:partial - disambiguating templated functions
How do I persuade partial to tie itself to the appropriate overload? I have: alias bars=partial!(slurpBars!BarType,filename,startDate,endDate); where there are two overloads of slurpBars: SomeBar[] slurpBars(SomeBar)(string filename,string datasetName, typeof(SomeBar.date) startDate, typeof(SomeBar.date) endDate) SomeBar[] slurpBars(SomeBar)(hid_t filehandle,string datasetName, typeof(SomeBar.date) startDate, typeof(SomeBar.date) endDate) And I receive the following error: Error: template kprop.marketdata.retrievebars.slurpBars matches more than one template declaration: Thanks. Laeeth.
Re: Threading Questions
On Wednesday, 30 September 2015 at 10:32:01 UTC, Jonathan M Davis wrote: On Tuesday, September 29, 2015 22:38:42 Johannes Pfau via Digitalmars-d-learn wrote: [...] What I took from the answers to that SO question was that in general, it really doesn't matter whether a condition variable has spurious wakeups. You're going to have to check that the associated bool is true when you wake up anyway. Maybe without spurious wakeups, it wouldn't be required if only one thread was waiting for the signal, but you'd almost certainly still need an associated bool in case it becomes true prior to waiting. In addition, if you want to avoid locking up your program, it's ferquently the case that you want a timed wait so that you can check whether the program is trying to exit (or at least that the thread in question is being terminated), and you'd need a separate bool in that case as well so that you can check whether the condition has actually been signaled. So, ultimately, while spurious wakeups do seem wrong from a correctness perspective, when you look at what a condition variable needs to do, it usually doesn't matter that spurious wakeups exist, and a correctly used condition variable will just handle spurious wakeups as a side effect of how it's used. - Jonathan M Davis Yea, I guess you're right. The class in the example I posted was a crude reproduction of something I'm using right now in another project: http://codepad.org/M4fVyiXf I don't think it would make a difference whether it woke up randomly or not. I've been using this code regularly with no problems. Bit
Re: Threading Questions
On Tuesday, 29 September 2015 at 23:20:31 UTC, Steven Schveighoffer wrote: yeah, that could probably be done. One thing to note is that these classes are from ages ago (probably close to 10 years). New API suggestions may be allowed. -Steve I'm still thinking about my last rant, here... So by new API, do you mean just adding a couple of new functions, or rewriting a new Condition class(as is the plan for streams)? Since D is moving towards a phobos with no GC, what will happen to things that are classes like Condition and Mutex? If DIP74 were implemented, Condition and Mutex could be made ref counted, but DIP74 seems like something that will be very complicated, and may not happen for a long time. So the only other alternative is to make it a struct, but for a Mutex, that would prevent you from doing this: Mutex m = new Mutex(); synchronized(m) { } I also don't mind the way that the current streams are made up of a class hierarchy. Although inheritance is overused sometimes, I don't think it's bad. But, if I'm correct about the current trend in D, it seems any new stream stuff will end up getting flattened into some template/struct solution. Any comments on this? Thanks, Bit
Re: How to break gdb on D exception ?
On Friday, 2 October 2015 at 09:15:13 UTC, Dmitri wrote: On Friday, 2 October 2015 at 04:50:59 UTC, BBasile wrote: On Friday, 2 October 2015 at 04:46:51 UTC, BBasile wrote: On Friday, 2 October 2015 at 04:24:11 UTC, Adam D. Ruppe wrote: On Friday, 2 October 2015 at 03:58:45 UTC, BBasile wrote: none of the following GB commands work: give break d_throw or maybe `break d_throwc` a try unfortunately it doesn't work, i get --- (gdb) Function "d_throw"/"d_throwc" not defined. it was almost that actually, 'break _d_throwc Or you could break on a specific exception class's constructor. This would be better. 1/ because I could propose a modifiable list of the exception kinds to track in the options). 2/ because with _d_trow_c, info stack #1 is really not interesting. #2 or #3 is usually where the 'thing' really happens. How can I do that, for example with FileException class ?
Re: __simd_sto confusion
On Saturday, 3 October 2015 at 14:47:02 UTC, Nachtraaf wrote: I'm trying to create some linear algebra functions using simd intrinsics. I watched the dconf 2013 presentation by Manu Evans but i'm still confused about some aspects and the following piece of code doesn't work. I'm trying to copy the result of a dot product from the register to memory but dmd fails with an overload resolution error, which i guess is due some implicit conversion? dmd error: simd1.d(34): Error: core.simd.__simd_sto called with argument types (XMM, float, __vector(float[4])) matches both: /usr/include/dlang/dmd/core/simd.d(434): core.simd.__simd_sto(XMM opcode, double op1, __vector(void[16]) op2) and: /usr/include/dlang/dmd/core/simd.d(435): core.simd.__simd_sto(XMM opcode, float op1, __vector(void[16]) op2) from the following piece of code: float dot_simd1(float4 a, float4 b) { float4 result = __simd(XMM.DPPS, a, b, 0xFF); float value; __simd_sto(XMM.STOSS, value, result); return value; } What am I doing wrong here? core.simd is horribly broken. I recommend that you avoid it for any serious work. If you want to do simd programming with D get LDC or GDC and use their simd intrinsics instead of core.simd. If you have to do simd with dmd write inline assembly.