Re: Type-Safer Modern High-Level Performant OpenGL
On Thursday, 6 March 2014 at 23:16:26 UTC, Nordlöw wrote: GFM (my own, PLEASE, PLEASE CHOOSE ME) I'm trying to build your package using dub but I get the error θ61° [per:~/justd/gfm] master ± dub Error executing command run: Main package must have a binary target type, not none. Cannot build. I'm using a recent build of dub from git master. What is wrong? I get the same behaviour, but this looks reasonable to me. dub tries to build the package named gfm, which has targetType none because it's an umbrella package to group sub-packages. What you can do instead is just referencing the sub-packages you need in your dub.json. Should work then.
Re: Type-Safer Modern High-Level Performant OpenGL
On Thursday, 6 March 2014 at 23:03:35 UTC, Nordlöw wrote: On thing though...why did you choose SDL2 of GLFW3? I of course mean SDL2 *over* GLFW3. Mostly familiarity because I've never used GLFW. What I really like in SDL is the software/DirectX renderers, which provides a tiny feature set, but allows reliable rendering with no graphics API whatsoever :). In all case you will be able to use gfm:opengl with GLFW, to create and select an OpenGL context is the only requirement.
Re: Template mixins - why only declarations
On Thursday, 6 March 2014 at 18:36:12 UTC, Dejan Lekic wrote: Template mixins can't contain statements, only declarations, because they (template mixins) are a way to inject code into the context. Therefore it makes sense to forbid statements, as they can't appear in ANY context. If I side-step slightly, the compiler does not appear to have difficulty coping: import std.stdio; import std.conv; string codeString(string A, string B, int I)() { enum n = I*3; return writeln(\~A~\); writeln(\~B~\); writefln(\%d\,~to!string(n)~);; } void foo() { mixin(codeString!(One, Two, 1)()); writeln(Hello world); } void main() { foo(); }
Re: Best way to reference an array in a child class...
On Thu, 06 Mar 2014 17:44:09 -0500, captain_fid bell@gmail.com wrote: this() {items = [ {10, first}, {20, second}];} strangely enough, when modeling this the first time (using items as a class) and 'new item() syntax) there was no real issue. I thought using a static array of structs in the children would be more efficient when instantiating the objects. Never mind whether its true or not - Speed isn't a really a concern, learning is. I missed this the first time. That is a difference between my code and your code. Mine creates a new instance of an array on *object* initialization, yours creates ONE instance of an array, that all objects share. This is not necessarily a good thing. Because you've created a mutable version of the array. I believe it is initialized on startup from the heap. One really bad thing is, the same array is used if you initialize from multiple threads. And it's mutable, making it implicitly shared even though it shouldn't be. You should make the array immutable and static, or else initialize it in the constructor. I don't know your use case, so it's hard to say what you should do. -Steve
Re: Template mixins - why only declarations
On Thursday, 6 March 2014 at 18:31:02 UTC, Frustrated wrote: On Thursday, 6 March 2014 at 17:27:35 UTC, Steve Teale wrote: Pretty much what the subject says. Why can't template mixins include statements ans so on? Is it just too hard, or is it just too much like C macros? Steve template mixins mix in directly into the code as if you typed them. If they contained statements then you could mixin statements into classes, say, and it would then be illegal. I guess there is no reason per se, but I guess that wasn't the desired behavior for template mixins. I imagine there could be a definite downside to having template mixins containing statements. Also, they can't be self contained. e.g., mixin template C() { i = i + 1; // invalid } ... int i = 0; mixin C(); The template itself can't be semantically checked in place because i is unknown inside the template. (it is not self contained so to speak) In any case, just seems wrong for templates to do that. They are not grouping expressions but grouping definitions and declarations of things so you don't have to do them multiple times. string mixins, OTOH, could do the above. template C() { string C() { return i = i + 1;; } } ... int i = 0; mixin(C); and this will work. This is because the statement is contained within a string and the compiler simply inserts the string directly. The template can still be validated in place(since i = i + 1 is a string and has no other meaning in the template). Interesting. I regularly use template mixins referring to 'this' and they work fine. e.g.: mixin template Bar() { public int getFoo() { return this.foo; } } class Foo { private int foo; mixin Bar; }
Compiling D through command line
What arguments would I do to compile a d project through command line. Been trying a few things, but can't get it working. I always get Error: cannot read file x Read around the net and it most says it's an installation error and that reinstalling should fix it, but it works when compiling through a few IDE's so I assume it's mistake of my own. Tried like this: -c c:\testproject\main.d -m32 -ofc:\testd\out.exe And tried doing -v and it shows the correct information. Anyone who got an example to achieve it. The documents doesn't explain it proper IMO as there is no example on compiling manual.
Re: Compiling D through command line
On Friday, 7 March 2014 at 16:59:30 UTC, Bauss wrote: What arguments would I do to compile a d project through command line. Been trying a few things, but can't get it working. I always get Error: cannot read file x Read around the net and it most says it's an installation error and that reinstalling should fix it, but it works when compiling through a few IDE's so I assume it's mistake of my own. Tried like this: -c c:\testproject\main.d -m32 -ofc:\testd\out.exe And tried doing -v and it shows the correct information. Anyone who got an example to achieve it. The documents doesn't explain it proper IMO as there is no example on compiling manual. I've not used dmd directly in ages, rdmd [1] is easier to use. It's included in the installation. Does that work for you? http://dlang.org/rdmd.html
Re: Compiling D through command line
On Friday, 7 March 2014 at 17:08:24 UTC, Rene Zwanenburg wrote: On Friday, 7 March 2014 at 16:59:30 UTC, Bauss wrote: What arguments would I do to compile a d project through command line. Been trying a few things, but can't get it working. I always get Error: cannot read file x Read around the net and it most says it's an installation error and that reinstalling should fix it, but it works when compiling through a few IDE's so I assume it's mistake of my own. Tried like this: -c c:\testproject\main.d -m32 -ofc:\testd\out.exe And tried doing -v and it shows the correct information. Anyone who got an example to achieve it. The documents doesn't explain it proper IMO as there is no example on compiling manual. I've not used dmd directly in ages, rdmd [1] is easier to use. It's included in the installation. Does that work for you? http://dlang.org/rdmd.html Nope still get the same compile error. Compiling as such: --build-only --force -ofc:\testd\out.exe c:\testproject\main.d I'm sure I do it wrong.
Re: Compiling D through command line
On Fri, Mar 07, 2014 at 04:59:29PM +, Bauss wrote: What arguments would I do to compile a d project through command line. Been trying a few things, but can't get it working. I always use the command line, and it has always worked fine for me. (Caveat: I use Linux, so I've no idea if what I say applies to Windows in any way.) It's simply: dmd -ofprogram main.d module1.d module2.d ... I assume on Windows it would be something like: dmd.exe -ofprogram.exe main.d module1.d module2.d ... Note that you do have to specify all source files, including any sources in subdirectories that your code uses, otherwise you may get linker errors. I always get Error: cannot read file x Read around the net and it most says it's an installation error and that reinstalling should fix it, but it works when compiling through a few IDE's so I assume it's mistake of my own. Tried like this: -c c:\testproject\main.d -m32 -ofc:\testd\out.exe Why are you using -c? That is only if you want to separately compile individual source files into object files without linking. If you're trying to make an executable, you shouldn't be using -c. T -- A program should be written to model the concepts of the task it performs rather than the physical world or a process because this maximizes the potential for it to be applied to tasks that are conceptually similar and, more important, to tasks that have not yet been conceived. -- Michael B. Allen
Re: Compiling D through command line
On Friday, 7 March 2014 at 17:44:46 UTC, H. S. Teoh wrote: On Fri, Mar 07, 2014 at 04:59:29PM +, Bauss wrote: What arguments would I do to compile a d project through command line. Been trying a few things, but can't get it working. I always use the command line, and it has always worked fine for me. (Caveat: I use Linux, so I've no idea if what I say applies to Windows in any way.) It's simply: dmd -ofprogram main.d module1.d module2.d ... I assume on Windows it would be something like: dmd.exe -ofprogram.exe main.d module1.d module2.d ... Note that you do have to specify all source files, including any sources in subdirectories that your code uses, otherwise you may get linker errors. I always get Error: cannot read file x Read around the net and it most says it's an installation error and that reinstalling should fix it, but it works when compiling through a few IDE's so I assume it's mistake of my own. Tried like this: -c c:\testproject\main.d -m32 -ofc:\testd\out.exe Why are you using -c? That is only if you want to separately compile individual source files into object files without linking. If you're trying to make an executable, you shouldn't be using -c. T Alright ty, but since you only specify the module names, how would it know to look in which path? Also do I have to specify all the modules from the std lib etc.?
Re: Compiling D through command line
On Friday, 7 March 2014 at 16:59:30 UTC, Bauss wrote: What arguments would I do to compile a d project through command line. Been trying a few things, but can't get it working. I always get Error: cannot read file x Read around the net and it most says it's an installation error and that reinstalling should fix it, but it works when compiling through a few IDE's so I assume it's mistake of my own. Tried like this: -c c:\testproject\main.d -m32 -ofc:\testd\out.exe And tried doing -v and it shows the correct information. Anyone who got an example to achieve it. The documents doesn't explain it proper IMO as there is no example on compiling manual. I would say that you should make sure that the files are where you expect them to be. When using the console, iff you're in the source directory you shouldn't need to specify a full path for those files at least, which could help the compiler find them. You can still specify the output directory for the exe. On a side note, why use the m32 switch on Windows? That's the default, so it isn't needed.
Re: Compiling D through command line
On Friday, 7 March 2014 at 16:59:30 UTC, Bauss wrote: What arguments would I do to compile a d project through command line. Been trying a few things, but can't get it working. I always get Error: cannot read file x Read around the net and it most says it's an installation error and that reinstalling should fix it, but it works when compiling through a few IDE's so I assume it's mistake of my own. Tried like this: -c c:\testproject\main.d -m32 -ofc:\testd\out.exe Take a step back. Your file is in folder c:\testproject, so do cd \testproject dmd main.d Then look for a file called main.exe in the \testproject folder. I may be off the mark, since I have not used dmd under Windows for quite a long time, but try it.
Re: Compiling D through command line
On Friday, 7 March 2014 at 18:07:00 UTC, Steve Teale wrote: On Friday, 7 March 2014 at 16:59:30 UTC, Bauss wrote: What arguments would I do to compile a d project through command line. Been trying a few things, but can't get it working. I always get Error: cannot read file x Read around the net and it most says it's an installation error and that reinstalling should fix it, but it works when compiling through a few IDE's so I assume it's mistake of my own. Tried like this: -c c:\testproject\main.d -m32 -ofc:\testd\out.exe Take a step back. Your file is in folder c:\testproject, so do cd \testproject dmd main.d Then look for a file called main.exe in the \testproject folder. I may be off the mark, since I have not used dmd under Windows for quite a long time, but try it. Well trying what you all suggest still no results. http://prntscr.com/2yqfhi
Re: Compiling D through command line
- I apologize for it all, my bad. It wasn't even a problem with the compiler nor arguments. I thought I had file extensions to show, so my main.d was actually main.d.txt Explains why it couldn't read the file. Fixed and got everything compiled fine.
New to std.algorithm and generics, no idea how to make simple things to work
I really can't wrap my head around these. I fought whole day trying to figure out how to do the simplest thing one can imagine: remove an element from a doubly linked list. Here's what I've tried, see if there is a recurring mistake of thought or something: import std.stdio; import std.algorithm; import std.range; import std.container; struct Point { int x; int y; } void main() { DList!Point points; points.insert(Point(0,0)); points.insert(Point(10,10)); points.insert(Point(5,5)); points.insert(Point(20,20)); points.remove(takeOne(find!(p = p.x 7)(points[]))); // test.d(18): Error: function std.container.DList!(Point).DList.remove (Range r) is not callable using argument types (Result) points.linearRemove(takeOne(find!(p = p.x 7)(points[]))); // test.d(21): Error: template std.container.DList!(Point).DList.linearRemove cannot deduce function from argument types !()(Result), candidates are: // /usr/include/dmd/phobos/std/container.d(2234): std.container.DList!(Point).DList.linearRemove(R)(R r) if (is(R == Range)) // /usr/include/dmd/phobos/std/container.d(2240): std.container.DList!(Point).DList.linearRemove(R)(R r) if (is(R == Range)) // /usr/include/dmd/phobos/std/container.d(2253): std.container.DList!(Point).DList.linearRemove(R)(R r) if (is(R == Take!Range)) points.remove(find!(p = p.x 7)(points[])); // 0 points.remove(takeOne(filter!(p = p.x 7)(points[]))); // test.d(30): Error: function std.container.DList!(Point).DList.remove (Range r) is not callable using argument types (Result) points.remove(filter!(p = p.x 7)(points[])); // test.d(33): Error: function std.container.DList!(Point).DList.remove (Range r) is not callable using argument types (FilterResult!(__lambda3, Range)) points.linearRemove(filter!(p = p.x 7)(points[])); // test.d(36): Error: template std.container.DList!(Point).DList.linearRemove cannot deduce function from argument types !()(FilterResult!(__lambda1, Range)), candidates are: // /usr/include/dmd/phobos/std/container.d(2234): std.container.DList!(Point).DList.linearRemove(R)(R r) if (is(R == Range)) // /usr/include/dmd/phobos/std/container.d(2240): std.container.DList!(Point).DList.linearRemove(R)(R r) if (is(R == Range)) // /usr/include/dmd/phobos/std/container.d(2253): std.container.DList!(Point).DList.linearRemove(R)(R r) if (is(R == Take!Range)) foreach (Point p; points) { if (p.x 7) { //points.remove(/* Somehow get the range */); break; } } foreach (Point p; points) { writeln(p.x); } } Purpose is to remove one element that matches predicate, or any amount really. Now DList.remove is defined as Range remove(Range r) and filter is auto filter(Range)(Range rs) if (isInputRange!(Unqual!Range)) with explanation The call filter!(predicate)(range) returns a new range only containing elements x in range for which predicate(x) is true. So if I understand correctly, filter should return a range that I can remove from the list. Why isn't this working?
Re: New to std.algorithm and generics, no idea how to make simple things to work
Text went nuts at least for me so here's raw pastebin of it http://pastebin.com/raw.php?i=JfLFdsNj
exception handling and dynamic loading
I am loading my own small dynamic library of functions, using Runtime.loadLibrary in core.runtime and want an exception thrown in a function in the dynamic library to be caught close to where I call it, which is of course in the program that's doing the dynamic loading. How do I get the exception mechanism to collaborate properly in this situation? The document http://dlang.org/phobos/core_runtime.html#.Runtime.loadLibrary asserts that the runtime in the dynamic library is integrated with that in the main program, but any exception I throw in the dynamic library causes a fatal crash. Exceptions thrown in my main program are caught properly with no problems. I'm using DMD32 D Compiler v2.064 on windows, and I followed the advice in http://dlang.org/dll.html as well as having a proper winMain function as defined here http://wiki.dlang.org/D_for_Win32 .
Re: exception handling and dynamic loading
On Friday, 7 March 2014 at 20:14:07 UTC, Carl Sturtivant wrote: I'm using DMD32 D Compiler v2.064 on windows This is the main problem. All recent work Martin Nowak has done on improving dynamic loading is Linux-only for now. Windows support is very limited compared to it.
Re: Best way to reference an array in a child class...
On Friday, 7 March 2014 at 13:57:31 UTC, Steven Schveighoffer wrote: On Thu, 06 Mar 2014 17:44:09 -0500, captain_fid bell@gmail.com wrote: this() {items = [ {10, first}, {20, second}];} strangely enough, when modeling this the first time (using items as a class) and 'new item() syntax) there was no real issue. I thought using a static array of structs in the children would be more efficient when instantiating the objects. Never mind whether its true or not - Speed isn't a really a concern, learning is. I missed this the first time. That is a difference between my code and your code. Mine creates a new instance of an array on *object* initialization, yours creates ONE instance of an array, that all objects share. This is not necessarily a good thing. Because you've created a mutable version of the array. I believe it is initialized on startup from the heap. One really bad thing is, the same array is used if you initialize from multiple threads. And it's mutable, making it implicitly shared even though it shouldn't be. You should make the array immutable and static, or else initialize it in the constructor. I don't know your use case, so it's hard to say what you should do. -Steve I don't know your use case, so it's hard to say what you should do. Steve, I don't think I know my use case -- So it's not you. I'm attempting to model hardware, where 'items' in this case are an static array of registers. Single threaded (for now). Mainly, this a learning opportunity to get a better understanding of D for future comparison (vs. C++). This is not necessarily a good thing. Because you've created a mutable version of the array. I believe it is initialized on startup from the heap. Lot to learn. I understand initialized from the heap, but do you mean at program startup, or object instantiation? If program, I would have expected that with __gshared (globals) only, not with this. One really bad thing is, the same array is used if you initialize from multiple threads. And it's mutable, making it implicitly shared even though it shouldn't be. You should make the array immutable and static, or else initialize it in the constructor. I appreciate your suggestions and the patience.
Converting string to ascii value
Hello all! I am having trouble converting a letter in a array of string to the ascii value. For example: string[] stringarray[3]; stringarray[0] = blahblahblah; stringarray[1] = a; stringarray[3] = 5; long y = to!long(stringarray[2]); // makes y the value 5 long x = to!long(stringarray[1]); // errors This is not working properly. I want to get the ascii value of the characters. In this case y should equal 97, b should equal 53. How do I do this properly? Thanks!
Re: Converting string to ascii value
On Fri, Mar 07, 2014 at 10:21:57PM +, Setra wrote: On Friday, 7 March 2014 at 22:21:06 UTC, Setra wrote: Hello all! I am having trouble converting a letter in a array of string to the ascii value. For example: string[] stringarray[3]; stringarray[0] = blahblahblah; stringarray[1] = a; stringarray[2] = 5; long y = to!long(stringarray[2]); // makes y the value 5 long x = to!long(stringarray[1]); // errors This is not working properly. I want to get the ascii value of the characters. In this case y should equal 97, b should equal 53. How do I do this properly? [...] long x = cast(ubyte) stringarray[0]; Using to!long is for when you're trying to parse a number represented in string format. T -- Famous last words: I *think* this will work...
Re: Converting string to ascii value
On 03/07/2014 02:21 PM, Setra wrote: On Friday, 7 March 2014 at 22:21:06 UTC, Setra wrote: Hello all! I am having trouble converting a letter in a array of string to the ascii value. For example: string[] stringarray[3]; That is three string slices, not three strings. This works for the following statements: string[3] stringarray; stringarray[0] = blahblahblah; stringarray[1] = a; stringarray[2] = 5; long y = to!long(stringarray[2]); // makes y the value 5 long x = to!long(stringarray[1]); // errors This is not working properly. I want to get the ascii value of the characters. In this case y should equal 97, b should equal 53. How do I do this properly? Thanks! You don't need any conversion. Characters are encoding values anyway: auto s = a; assert(s[0] == 97); However, don't forget that strings in D are UTF-encoded. So, what you expect will work only for ASCII content. Ali
Re: Converting string to ascii value
On Friday, 7 March 2014 at 22:21:06 UTC, Setra wrote: Hello all! I am having trouble converting a letter in a array of string to the ascii value. For example: string[] stringarray[3]; stringarray[0] = blahblahblah; stringarray[1] = a; stringarray[2] = 5; long y = to!long(stringarray[2]); // makes y the value 5 long x = to!long(stringarray[1]); // errors This is not working properly. I want to get the ascii value of the characters. In this case y should equal 97, b should equal 53. How do I do this properly? Thanks! Whoops this is the correct version.
Re: Converting string to ascii value
Thanks! Now I feel kind of dumb. For some reason I thought it would not be that simple...
Re: Converting string to ascii value
On 3/7/2014 5:21 PM, Setra wrote: Hello all! I am having trouble converting a letter in a array of string to the ascii value. For example: First of all: string[] stringarray[3]; This isn't your main problem, but that line is incorrect. Actually, I'm kinda surprised that even works. It should be one of these, depending if you want a static array or a dynamic one: string[3] staticStringArray; string[] dynamicStringArray; dynamicStringArray.length = 3; Or you can do it all in one like this: string[] dynamicStringArray = [blahblahblah, a, 5]; stringarray[0] = blahblahblah; stringarray[1] = a; stringarray[3] = 5; long y = to!long(stringarray[2]); // makes y the value 5 long x = to!long(stringarray[1]); // errors This is not working properly. I want to get the ascii value of the characters. In this case y should equal 97, b should equal 53. How do I do this properly? Thanks! First of all, ASCII is outdated, it's all Unicode now. D's strings are UTF-8. See this if you need a primer on Unicode: http://www.joelonsoftware.com/articles/Unicode.html That said, the English letters and numeric digits just happen to be the same in UTF-8 as ASCII, so in your examples, you can still get the ASCII values (as long as you remember it's *really* Unicode's UTF-8). Just keep in mind you don't normally want to be dealing with ASCII or even individual characters. Usually you want to just stick with with full strings. Back to your code though, your code is trying to convert the *entire* string to a long. So that's not going to get you want you want. You want the numeric representation of an *individual* character *within* the string. In your example, you'd do that like this: char c2 = stringarray[2][0]; // First 'char' in string #2: '5' char c1 = stringarray[1][0]; // First 'char' in string #1: 'a' Again, remember those aren't really characters, they're UTF-8 code units. So if your strings have any non-english characters, then that won't always work as you expect. Now, to get the numeric representation of c1 and c2 (ie the UTF-8 code unit, which in your example just happens to also be the ASCII code, but only by pure chance), you can just cast it to a ubyte: ubyte y = cast(ubyte)c2; ubyte x = cast(ubyte)c1;
Re: Converting string to ascii value
On 3/7/2014 5:33 PM, H. S. Teoh wrote: long x = cast(ubyte) stringarray[0]; long x = cast(ubyte) stringarray[0][0]; ;)
Re: Converting string to ascii value
On 3/7/2014 5:37 PM, Setra wrote: Thanks! Now I feel kind of dumb. For some reason I thought it would not be that simple... In a lot of languages it isn't that simple ;)