Re: Doubt about this book: The D Programming Language
On Sunday, 16 December 2018 at 19:57:08 UTC, Steven Schveighoffer wrote: On 12/16/18 1:37 PM, Marko wrote: On Amazon The D Programming Language has good reviews but it's 8 years old. So is this book still relevant today? Mostly, yes. And it's a pretty good book, even if it has some outdated parts. There's errata somewhere too. Would you recommend another book? I highly recommend this book (available online for free or you can purchase a hard copy): http://ddili.org/ders/d.en/index.html It is continually updated by Ali, so it should be up to date with the latest compiler. PS: I am already a programmer writing mainly in C and C#. I hope you feel right at home here :) But I must warn you, if you're anything like me, you will hate having to go back to another language. -Steve Too bad when I need to go back to C# and/or C++ for a while. haha
Re: Checking if CTFE is used?
On Tuesday, 18 December 2018 at 14:23:38 UTC, berni wrote: On Tuesday, 18 December 2018 at 13:53:01 UTC, Stefan Koch wrote: Why would you need to know? Well, first out of curiosity. But there are also other reasons: I've got a large immutable array. Without CTFE I'd use some php script and add it as a large literal. With CTFE I don't need that php script nor do I need to put that large literal in the source code. But I need to know, that indeed the array is calculated by the compiler, else the solution with the php script would result in faster code. How is the items in the array generated? if the function can be called as following: enum myArr = generateArray(); then you know for sure you have a satic array of strings at compile time. I've used something similar, to generate a JSON string from all UDAs in a give class, which I needed to pass to a C# application (I made the D output a string from the request by command line option). I did something like this: string getAvailableForms() { import extensions.enumeration : staticMembers; import asdf; // JSON serializer import std.traits : getUDAs, hasUDA; import externalPaths : ExternalAppPath, DisplayName; import std.algorithm : startsWith; import std.conv : to; FormDisplayNameObj[] output; static foreach(string fieldName; staticMembers!ExternalAppPath) {{ static if(hasUDA!(__traits(getMember, ExternalAppPath, fieldName), DisplayName)) { if(fieldName.startsWith(startKey)) { DisplayName dn = getUDAs!(__traits(getMember, ExternalAppPath, fieldName), DisplayName)[0]; string id = extractDigits(fieldName[startKey.length - 1 .. $]); int i = to!int(id); auto o = new FormDisplayNameObj(); o.value = dn.value; o.index = i; output ~= o; } } }} return output.serializeToJson; } then: enum s = getAvailableForms; writeln(s); I did consider at first make a script to generate that string but I managed to make it work with CTFE that way.
Re: How can I define a label inside a switch?
On Sunday, 14 December 2014 at 18:27:28 UTC, ketmar via Digitalmars-d-learn wrote: On Sun, 14 Dec 2014 18:24:39 + MachineCode via Digitalmars-d-learn wrote: I used to do it in C but in D it's giving this compile error message: > switch case fallthrough - 'use goto case;' if intended Here's the code: > switch(value) { > // alof of cases here > // ... > white: // regular label >case 'a': case 'c': >case 'd': case 'k': >do_something(); >break; > case 'e': >do_something2(); > break; > default: assert(0); > } How is it fall through if there's a break? does D switch differ from C in any way? why do you need that? you can use literally what compiler told you: `goto case 'a';` for example. The labels are disabled then? I find that goto case case_value ugly and prefer goto labelName; but if it's the only way to go let's do it
How can I define a label inside a switch?
I used to do it in C but in D it's giving this compile error message: switch case fallthrough - 'use goto case;' if intended Here's the code: switch(value) { // alof of cases here // ... white: // regular label case 'a': case 'c': case 'd': case 'k': do_something(); break; case 'e': do_something2(); break; default: assert(0); } How is it fall through if there's a break? does D switch differ from C in any way?
Re: Why the DMD Backend?
On Sunday, 30 November 2014 at 02:07:16 UTC, ketmar via Digitalmars-d-learn wrote: On Sat, 29 Nov 2014 22:57:52 -0300 Ary Borenszweig via Digitalmars-d-learn wrote: > besides, i don't want to use anything llvm-related. Why not? let's say that there is some "ideological" reasons. but do you use anything gpl-related?
Re: Why the DMD Backend?
On Sunday, 30 November 2014 at 22:15:44 UTC, bearophile wrote: MachineCode: I tried to use others compilers which use gcc/llvm as backend where I had to do alot of workaround just to make it working on Windows that I just gave up. I using ldc2 on Windows with no problems, and the installation is very easy, just download two archives and unpack them in the root. Add a path to your path file, and you are done. Bye, bearophile I wasn't speaking about the ldc(I haven't used it yet) but other compilers gcc/llvm-based that I've tried to use a while ago.
Re: Why the DMD Backend?
On Friday, 28 November 2014 at 19:59:40 UTC, Xinok wrote: Given that we have GDC with the GCC backend and LDC with the LLVM backend, what are the benefits of keeping the DMD compiler backend? It seems to me that GCC and LLVM are far more developed and better supported by their respective communities. They have superior optimizers and are better equipped for migrating D to new platforms. On the other hand, from what I gather, there's lots of work to be done on DMD on improving support for x64 Windows and ARM. It's a genuine question, which is why I posted this to D.learn. I don't follow development on the backend and overall I'm unfamiliar with compilers, so I'm not sure what the benefits are of the D community continuing to maintain it's own backend. I don't want to download neither gcc or llvm just to use D language. If so, I could refuse to install and move me away from the language. I tried to use others compilers which use gcc/llvm as backend where I had to do alot of workaround just to make it working on Windows that I just gave up.
Re: help
On Thursday, 20 November 2014 at 07:25:45 UTC, Suliman wrote: You need to check if remote file exist of server and only after it download шею is this software name written in russian language?
Re: Reflections on isPalindrome
On Tuesday, 28 October 2014 at 14:09:50 UTC, MattCoder wrote: On Tuesday, 28 October 2014 at 13:30:05 UTC, Nordlöw wrote: On Tuesday, 28 October 2014 at 11:51:42 UTC, MattCoder wrote: I forgot to say that I'm compiling with DMD without any compiler hints/optimizations. Try compiling with DMD flag -release and perhaps also -release -noboundscheck to get relevant results. DMD is currently not that good at inlining range primitives. Interesting! With -release the second version still faster but only by 10%. Now with: -release -noboundscheck they are equal and sometimes your version is slightly faster by ~3 milliseconds. Matheus. I'm very surprise. If they either equal or fast sometimes the compiler did great optizations or it's just a multicore processor that's helping or what else? the first version (from your post, the one using ranges) change in each iteration two pointers (in pop*() calls) and request r's length 3 times (in .empty calls) while the second doesn't, just run until an already know index (when enter in the loop) and access two index in each iteration. This without consider the amount of ifs. I don't know, maybe I just thinking in the C-way as that code would run.
Re: passing non-dynamic arrays to variadic functions
On Monday, 27 October 2014 at 02:27:32 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 27 Oct 2014 02:19:49 + MachineCode via Digitalmars-d-learn wrote: It worked fine for me. Output: > abc > abc Environment: Win 8.1 64-bit (but dmd target is 32-bit, IIRC), dmd v2.066.0 yes, thank you too. that was one of my custom patches that broke this. i already found that patch, and it's not even mine! ;-) You're welcome :) what do you call git head is the dmd compiler compiled from dmd's source code on github?
Re: Where is a variable declared in a module allocated?
On Saturday, 25 October 2014 at 22:16:12 UTC, John Colvin wrote: On Saturday, 25 October 2014 at 21:52:13 UTC, MachineCode wrote: Where is a variable declared in a module allocated? is it same as a C's global? for example: module foo; int myvar; that is in thread local storage. __shared, shared or immutable cause the variable to be in classic global storage like in C. See: http://dlang.org/migrate-to-shared.html Thank you guy. :) I need to learn to use that forum search.
Re: forum.dlang.org open source?
On Sunday, 26 October 2014 at 23:57:41 UTC, Mike wrote: Does forum.dlang.org have an open source repository somewhere that we can contribute pull requests to, or are bug reports to recommended procedure. I see that the left navigation menu needs updating, and I think we can wordsmith the forum descriptions a little to make it clearer where to post things. Some other nice features like backtick(`) markup and the ability to collapse/expand threads are also on my mind at the moment. Thanks for the support, Mike Are you going to use HTML in the posts? because neither Walter and probably forum maintainer wants to use it.
Re: passing non-dynamic arrays to variadic functions
On Monday, 27 October 2014 at 00:26:00 UTC, ketmar via Digitalmars-d-learn wrote: Hello. let's assume we have this code: void doWrite(A...) (A args) { import std.stdio; import std.conv; writeln(to!string(args[0])); } void main () { char[3] a0 = "abc"; char[3] a1 = ['a', 'b', 'c']; doWrite(a0); doWrite(a1); } i don't know why, but this code prints complete garbage each time i run it. yet if i'll change `doWrite()` invocations to this: doWrite(a0[]); doWrite(a1[]); everything is working fine. am i doing something wrong in the first sample and missed the relevat part of documentation, or this is a bug? and do we have workaround for this? It worked fine for me. Output: abc abc Environment: Win 8.1 64-bit (but dmd target is 32-bit, IIRC), dmd v2.066.0
Where is a variable declared in a module allocated?
Where is a variable declared in a module allocated? is it same as a C's global? for example: module foo; int myvar;
Re: Global const variables
On Tuesday, 21 October 2014 at 08:02:52 UTC, bearophile wrote: Currently this code gets rejected: const int[] a = [1]; void main() pure { auto y = a[0]; } test2.d(3,14): Error: pure function 'D main' cannot access mutable static data 'a' test2.d(3,14): Error: pure function 'D main' cannot access mutable static data 'a' But is this a good idea? Isn't it better to accept it? Bye, bearophile pure functions are also supposed to don't use global variables at all, according to functional programming paradigm
Re: Beginner ?. Why does D suggest to learn java
On Thursday, 16 October 2014 at 22:42:21 UTC, Ali Çehreli wrote: On 10/16/2014 03:26 PM, RBfromME wrote: > I'm a newbie to programming and have been looking into the D lang as a > general purposing language to learn, yet the D overview indicates that > java would be a better language to learn for your first programming > language. Why? Looks like D is easier than Java... Here: http://dlang.org/overview.html "As a first programming language - Basic or Java is more suitable for beginners." I say, just ignore that comment. :) We should open a bug report for that page. I had great fun writing a programming book for complete beginners and found it very easy to use D for that purpose: http://ddili.org/ders/d.en/ Ali I don't understand. If at least it were C but java? why not D itself?
Check if give an array is equal to first elements in another array
Is there one function in the Phobos library to check if give an array is equal to first elements in another array? e.g, f(a, b) the entire b array must match to first elements in a and then return true otherwise false, ie: a[0 .. b.length] == b probably there's no such a function (but I wouldn't find bad if there was) in the D's library so what's a good name (that'a descriptive) to such a function? btw, what it solves is: if(a.length >= b1.length && a[0 .. b1.length] == b1) { ... } if(a.length >= b2.length && a[0 .. b2.length] == b2) { ... } since if bx.length < a.length is valid I can't remove all the a.length >= bx.length checks otherwise I can have a range violation error