Re: Phobos: __FILE__ as template default parameter
On Saturday, 18 June 2016 at 18:13:22 UTC, Johan Engelen wrote: An example of how __FILE__ as template parameter will break your library: In library, distributed in binary+source form: ``` alias file_templ_alias = file_templ!bool; T file_templ(T, string file = __FILE__, size_t line = __LINE__) (T value) { return value; } ``` In user code, linking to the library binary: ``` bool foo(bool b){ return file_templ_alias(b); } ``` By calling the alias, both DMD and LDC will decide that the template does not need reinstantiation in the user object file and will try to link with the symbol in the library binary. So you have to be lucky to install the library source in the same path as where it was when the library was built on someone else's machine, otherwise you'll get a linker error and are left wondering what went wrong. -Johan Can't one just use __MODULE__ instead? So: T file_templ(T, string mod = __MODULE__, size_t line = __LINE__) (T value) { return value; }
Re: D plugin for Visual Studio Code
On Sunday, 22 May 2016 at 12:16:36 UTC, Martin Nowak wrote: Anyone working on a D language plugin for Visual Studio's cross platform IDE? Of course we're late to the party, language support for everything else is already there. http://code.visualstudio.com/ How is the D language experience on Atom and Sublime Text? There are about 3 plug-ins for D on Atom, all of which aren't exactly spectacular. They are all missing a few keywords IIRC and/or also fuck up your syntax highlighting quite badly with some constructions (primarily the ones with parentheses).
Re: My favourite game: DMD guess the error reason.
On Monday, 2 May 2016 at 07:13:17 UTC, Iain Buclaw wrote: Here's a small puzzle, in which there are both a simple and cryptic combined. To make it easier, I've added a some multiple choice answers at the bottom. [...] std/uni.d:2627:50: error: template std.algorithm.searching.countUntil cannot deduce function from argument types !("a[0] > 0x80")(CodepointInterval[]), candidates are: [...] [1]: Template deduction/matching failed to find a suitable candidate for countUntil. [...] 1
Re: Using private constructor with std.experimental.allocater:make
On Sunday, 1 May 2016 at 11:17:27 UTC, earthfront wrote: Hello! [...] class A { int b; private this(int a){b=a;} } [...] I don't think classes are supposed to be able to have a private constructor...
Re: aquivalent to pragma comment
On Thursday, 28 April 2016 at 16:05:39 UTC, andi wrote: hey guys, as the title says, im looking for an aquivalent to pragma comment(linker, "export:functionname"), is there any in D? greetings, Andi export void functionname() {} There.
Re: Checking if an Integer is an Exact Binary Power
On Saturday, 23 April 2016 at 21:04:52 UTC, Nordlöw wrote: On Saturday, 23 April 2016 at 20:42:25 UTC, Lass Safin wrote: CPUID: https://en.wikipedia.org/wiki/CPUID. You can check for the presence of a lot of instructions with this instruction. However this will only work on x86 and only run-time. Code you give a complete code example in D, please or point out a suitable place in druntime/phobos? I just found this: https://dlang.org/phobos/core_cpuid.html#.hasPopcnt! It does exactly as it says: checks if the system has popcnt. Though read the top of https://dlang.org/phobos/core_cpuid.html before you use it: Bugs: Currently only works on x86 and Itanium CPUs. Many processors have bugs in their microcode for the CPUID instruction, so sometimes the cache information may be incorrect. Example; import core.bitop; import core.cpuid; int count; if(hasPopcnt) count = _popcnt; // Uses x86-instruction "popcnt". else count = popcnt; // Phobos's software implementation. // Do stuff with count
Will the GC scan this pointer?
// Omitting the required imports. void[] ptr; void main() { uint buffer; glCreateBuffers(1, ); // Filling the buffer with data and such... ptr = glMapNamedBufferRange(buffer, 0, 512, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT)[0 .. 512]; } So the question is: Will the GC scan ptr? As you can see, it is a write-only pointer, so reading from it will cause undefined behavior (such as return data which looks like a pointer to data..), and can potentially be reallly slow. Do I have to mark it with NO_SCAN each time I call glMapNamedBufferRange?
Re: Checking if an Integer is an Exact Binary Power
On Saturday, 23 April 2016 at 20:34:52 UTC, Nordlöw wrote: On Saturday, 23 April 2016 at 17:28:21 UTC, Andrei Alexandrescu wrote: Yah, that's the canonical. I forgot why I chose (x & -x) > (x - 1) over it. -- Andrei So is there a way to check if popcnt builtin is available on current platform? CPUID: https://en.wikipedia.org/wiki/CPUID. You can check for the presence of a lot of instructions with this instruction. However this will only work on x86 and only run-time.
Re: Why does map take lambda as a template parameter
On Saturday, 23 April 2016 at 20:06:39 UTC, xtreak wrote: map takes lambda as a template parameter and so does filter and many other functions. Sometimes they take something other than lambda as a template parameter. Eg. In case of to!int("5") int is a type and hence might need it as a template parameter but why does map and others take it as template parameter. Adam D Ruppe pointed out in IRC it helps in inlining and optimization. Is there a thumb rule to decide this so that my functions too can benefit the performance and hence I could structure and understand my code better. Non-template function parameters can not be inlined, since they're not determinable at compile-time, only at run-time. You can have two versions if you want, one with the function as a template parameter, and one with it as a function pointer. I don't really think there is a rule of thumb to it other than using templates when you desire performance and also nicer syntax (in my opinion). Templates also use up more space in the executable by the way, so if you're developing on a platform with very limited memory, then function pointers may be the better alternative.
Re: VariantPointer
On Wednesday, 20 April 2016 at 20:07:31 UTC, Nordlöw wrote: On Wednesday, 20 April 2016 at 16:08:32 UTC, Lass Safin wrote: core.memory.GC.setAttr can set attributes for a block of memory, with which you can set the attribute NO_SCAN, which as it implies, forces that no scan be done in the particular block of memory. This can be used to insure that the GC doesn't mark blocks not alive as alive. Is this needed - *only* for regions allocated with GC.malloc or - *also* for memory allocated with non malloc/calloc/realloc? NO_SCAN should probably be set for all types of memory blocks. I don't even know if the GC actually scans mallocated memory in the first place.
Re: about destroy and delete.
On Wednesday, 20 April 2016 at 08:10:15 UTC, Dsby wrote: I see https://dlang.org/deprecate.html#delete The delete will be removeed, when will be deprecate? and i test destroy/GC.free and delte in struct, the value is difference; struct Struct { string value = "struct"; ~this() { writeln(value); } } void main() { auto s = new Struct(); delete s; writeln(""); } will printf : struct But in void main() { auto s = new Struct(); s.destroy; GC.free(s); writeln(""); } will printf : struct If I only GC.free(s); only printf: so, I want to know why don't destroy direct printf ? This is according to the reference, however this behavior should probably be changed to match that of the class, which will call the destructor immediately.
Re: VariantPointer
On Wednesday, 20 April 2016 at 14:36:54 UTC, Nordlöw wrote: On Wednesday, 20 April 2016 at 13:41:27 UTC, Nordlöw wrote: At https://github.com/nordlow/phobos-next/blob/master/src/variant_pointer.d Further: What to do with fact that the GC will fail to scan VariantPointers? Can the GC be tweaked to mask out the type bits before scanning? core.memory.GC.setAttr can set attributes for a block of memory, with which you can set the attribute NO_SCAN, which as it implies, forces that no scan be done in the particular block of memory. This can be used to insure that the GC doesn't mark blocks not alive as alive. Then, use GC.addRoot with the pointer to your actual data, with the typeinfo bits cleared, passed as a parameter, to add an internal pointer inside the GC itself to the data, so that is considered live until removeRoot is called on the same pointer. addRoot and removeRoot can be put into this and ~this, respectively.
Re: VariantPointer
On Wednesday, 20 April 2016 at 13:41:27 UTC, Nordlöw wrote: At https://github.com/nordlow/phobos-next/blob/master/src/variant_pointer.d I've implemented a pointer-only version of Variant called VariantPointer. [...] It safe to assume that `typeBits` most significant bits of a pointer on a 64-bit system are always zero? Note that I didn't want to use the lower bits because I'm currently unsure whether I need to represent stack-pointers aswell. I'm very sure that there is no obligation for the OS to not issue a stack of memory starting at addresses near the limit of a 64-bit system. Thus, you can't count on it 100% of the time, though it is so rare as far as I know, that a simple enforce() for checking that the upper bits are clear should be acceptable. Though, it may perhaps be unusable in a few decades time, if you still care then. I can't answer your second question.
Re: So what does (inout int = 0) do?
On Saturday, 16 April 2016 at 22:06:10 UTC, Marco Leise wrote: Am Fri, 15 Apr 2016 09:44:05 -0400 schrieb Andrei Alexandrescu: inout must go. -- Andrei Ceterum censeo Carthaginem esse delendam. -- Marcus Porcius Cato :o) What does that have to do with what he said? Are you comparing him to Cato?
Re: Cancelling a stdin.read?
On Monday, 11 April 2016 at 14:53:31 UTC, Adam D. Ruppe wrote: On Sunday, 10 April 2016 at 08:29:22 UTC, Lass Safin wrote: Thus, my question is: Is there any way to cancel the read from stdin prematurely from another thread, so that the thread can finish? What operating system are you on? I wouldn't be using threads for this at all, you might want to reorganize the program to get terminal events sent to the same gui event loop so exiting it would exit all of it. But failing that, canceling an I/O request can be done by sending yourself a signal on posix and on Windows there's a system API call that one thread can cancel another thread's blocking read. The D library would see these cancels as an error and throw an exception. You could catch it or let it kill the thread, since you want to exit anyway. My savior! I can't put it in one loop, since the window also has some autonomous features.
Re: Cancelling a stdin.read?
On Sunday, 10 April 2016 at 18:00:31 UTC, hilop wrote: On Sunday, 10 April 2016 at 08:29:22 UTC, Lass Safin wrote: I have a multi-threaded program, one thread drawing to a window and handling it, the other handling stdin. [...] The external program that writes to the input has to close it when it has finished to write. I'm writing from my terminal, and I have my graphical window opened beside it. I want to close the input from not an external program, but rather from within.
Cancelling a stdin.read?
I have a multi-threaded program, one thread drawing to a window and handling it, the other handling stdin. The thread which handles stdin is something like this: char[] buf; while(true) { readln(buf); } The window thread also has to receive close-events from the OS, such as when the user pressed Ctrl-Q or whatnot. The following code is what I used to terminate my program: import core.runtime : Runtime; import core.stdc.stdlib : exit; Runtime.terminate; exit(0); However this doesn't work, because Runtime.terminate waits for the other threads to terminate before proceeding. So I thought about replacing my above loop with somethings like this: while(NOTCLOSING) { ... } But this doesn't work either, because the conditional clause first gets read when a single loop finishes. And my loop won't finish until I give it input via stdin. This means that I can't use e.g. the close button for closing the button, without also writing to stdin. Because of this, I have to resort to an exit(0) alone, forcing the program to terminate without running destructors (static destructors are my concern here..) of any kind. Thus, my question is: Is there any way to cancel the read from stdin prematurely from another thread, so that the thread can finish? Or perhaps, just running the shared static destructors alone, so that at least they can get run before closing via exit?
Re: The Sparrow language
On Wednesday, 6 April 2016 at 16:56:17 UTC, Kagamin wrote: On Wednesday, 6 April 2016 at 13:15:48 UTC, Andrei Alexandrescu wrote: Anyway it's a new level of type system. Does D still accept new features of such complexity? D3?
Re: We gunna be rich
On Saturday, 2 April 2016 at 21:03:28 UTC, Patience wrote: On Saturday, 2 April 2016 at 15:43:53 UTC, Andrei Alexandrescu wrote: Hello all, I've created an Amazon Affiliates link for the D Language Foundation (dlang-20). Subsequently I've changed https://wiki.dlang.org/Books to use it. Please follow up with changing dlang.org to also use the links, and also let me know if you need affiliate links for any other products. Thanks! -- Andrei Wait, how is this going to make me be rich? I think you left that part out? 1. More money for Developers (pun heavily intended) 2. More incentive to work 3. Better language 4. More people know about it 5. You're now a computer wizard and everyone's trying to hire you 6. Profit
Re: How my little brother try D
On Saturday, 2 April 2016 at 21:29:27 UTC, Daniel Kozak wrote: Few days ago, my little brother (13 years old) ask me about writing some small utility. He needed find all files with selected extensions and move them to some another location. He asked me about using D or C# for it. My answer was: try both and you will see which one suited you better. [...] Maybe it would be nice to have alias for rename method or have better doc for rename. And probably we should fixed copy method to not remove files with same src and dst path :) You're right in how it isn't obvious for non-techy people. I do suppose it would be doable without breaking any old code (unless for some arcane reason the code depends on static assert(!__traits(allMember, std.file).canFind("move"))...), so why not create a PR with "alias move = rename" inside?
Re: Any reason as to why this isn't allowed?
On Saturday, 2 April 2016 at 16:58:14 UTC, Paul O'Neil wrote: On 04/02/2016 09:02 AM, Lass Safin wrote: class C { ~this() {} immutable ~this() {} } This gives a conflict error between the two destructors. What do you expect the difference to be? I'm not sure what I expect the semantics of destroying an immutable object to be. It's more that I wish the immutable destructor to be empty, thus never destroying it properly. I just don't really see the reason as to why we can have immutable and mutable constructors but not immutable and mutable destructors. Though currently it is possible if I create two functions, one immutable and one not, then set the value inside the vtable manually within two constructors, again, one immutable and one not.
Any reason as to why this isn't allowed?
class C { ~this() {} immutable ~this() {} } This gives a conflict error between the two destructors.
Re: Oh, my GoD! Goroutines on D
On Monday, 28 March 2016 at 13:10:45 UTC, Jin wrote: On Sunday, 27 March 2016 at 20:39:57 UTC, Walter Bright wrote: On 3/27/2016 11:17 AM, Jin wrote: [...] Nice! Please write an article about this! My english is too bad to write articles, sorry :-( Just use engrish, we won't care. Really.
Re: Females in the community.
On Thursday, 17 March 2016 at 20:03:08 UTC, John Carter wrote: It is very clear from the 'net that some communities welcome woman, and some actively hate them, some ignore them. I personally would feel reluctant to get involved in anything where there was a high probability of vitriolic rejection. (Yes, sadly, some 'net communities have, unfortunately, gone to very extreme lengths in their rejection.) Part me says ignore them, gender has nothing to do with programming. Part of me observes we are human first, programmers second, and human groups with a healthy gender mix are simpler more pleasant and functional places. Certainly Python has done well to actively welcome them, and I would suggest we do the same. So a simple statement of welcome and some level of outreach would go a long way. https://www.gnome.org/outreachy/ Currently, internships are open >internationally to women (cis and trans), >trans men, and genderqueer people. >Additionally, they are open to residents >and nationals of the United States of any >gender who are Black/African American, >Hispanic/Latin@, American Indian, Alaska >Native, Native Hawaiian, or Pacific Islander. We are planning to expand the >program to more participants from >underrepresented backgrounds in the >future. I, I mean, I just really CAN'T take you seriously, when you link shit like that. I mean, sure, groups with a better balance of women and men tend to fare better, but thing is, we don't really care about the gender of someone, whom we aren't with physically. We just don't. The only moment, where members of the D community meet each other, is at DConf, and we aren't holding DConf every single day of the year. And the thing which you've linked to, that (absolutely horrendous) outreachy thing, is something I'd rather actually not see, if I was a women: I wouldn't fucking want to join a community, who presents a text like that to my face. What the _fuck_ is shit like "cis" and "genderqueer" supposed to mean? When I see a text like that, all I think is that the community surrounding this language (or software or I don't know whhat) is instead of focusing on improving the language, focusing om fixing social pseudo-problems. This is a huge turn-off for me. Just, please, don't.
Re: How do I extend an enum?
On Saturday, 19 March 2016 at 17:40:27 UTC, Lass Safin wrote: Why: enum Base { A, B, } enum Derived : Base { C, // Gives error, says it can't implicitly convert expression to Base. D = 1, // Same error E = cast(Base)294, // Finally works. Can only be cast(Derived) instead. } void func(Derived d) {} func(Derived.E); // works. func(Derived.A); // Gives error, says it can't call function with Base.A. func(cast(Derived)Derived.A); // Works. So, what's the proper way of extending an enum? Meant "Can also be cast(Derived) instead."
How do I extend an enum?
Why: enum Base { A, B, } enum Derived : Base { C, // Gives error, says it can't implicitly convert expression to Base. D = 1, // Same error E = cast(Base)294, // Finally works. Can only be cast(Derived) instead. } void func(Derived d) {} func(Derived.E); // works. func(Derived.A); // Gives error, says it can't call function with Base.A. func(cast(Derived)Derived.A); // Works. So, what's the proper way of extending an enum?
Re: Is D a good choice for embedding python/octave/julia
On Sunday, 13 March 2016 at 13:02:16 UTC, Bastien wrote: Hi, apologies for what may be a fairly obvious question to some. ## The background: I have been tasked with building software to process data output by scientific instruments for non-experts - basically with GUI, menus, easy config files (JSON or similar) - and the ability to do some serious number crunching. My background is python/octave and would be happy building it in python (or god forbid, even octave), but it would end up clunky and slow once ported to a standalone executable. Hence why I'm looking at other languages. D caught my eye. ## The problem: The sticking point is unless I commit the rest of my life to maintaining this software, I can't write it all in D. The algorithms change/are improved yearly; the output format from the instrument changes once in a while and therefore these need to be easily scripted/modified by other (non-programming) scientists and the community that only really know python and octave. Essentially I'd like a D front end, and a D back-end that does most of the memory and data management but calls and interprets .py, .m and/or .jl scripts (python, matlab, julia) to know how to treat the data. This leaves the py/m/jl scripts visible to be edited by the end user. ## The question: Can it be done? Does this entirely defeat the point of using D and I should just code it in python because of the added overheads? Thanks for your help! B I REALLY don't think you should use _any_ scripted language, if what you're looking for is speed. Now for your main question: It can be done. An incomplete list of libraries and bindings for D: http://wiki.dlang.org/List_of_Libraries_and_Frameworks. It includes tools such as GTK. And I'm very sure that it will be faster than writing it completely in python. Another thing: I myself find D *much* easier to program in than python (having experience in both). The many meta-programming tools in D and the nice syntactic features of D really make-up for the increased complexity of the language compared to Python. Somethings I'd like to recommend: OpenCL. For algorithms and such, using the GPU is much much faster than using the CPU.
Re: Parameterized Keywords
On Monday, 7 March 2016 at 05:56:54 UTC, Patience wrote: int[size] <- creates an integer of size bits. You declare arrays of integers with int[size], you know that, right? And I really don't see any useful improvement, that could be added with this. It would just be wasted efforts.
Re: Uniform Function Call Syntax?
On Monday, 7 March 2016 at 07:58:53 UTC, Era Scarecrow wrote: On Monday, 7 March 2016 at 06:57:48 UTC, Ola Fosheim Grøstad wrote: immutable π = 3.14; Oh, the horror! With the assumption pi is declared elsewhere (say, in std.math), what i wonder is the number for pi vs 2 letters. Unicode 03C0h, so now i have to convert that to decimal, code 960. Alt+960 = └ That's not pi... Looking up the symbol by itself in the character map was annoying enough. No, this is not a good idea unless it's easily accessible, preferably with 2 or fewer keystrokes to symbolize pi. As a reminder most of us are programmers, not scientists or mathematicians. Having specialized symbols won't give us any benefit. It's not like we're filling out a complex formula with college level math for a thesis. Have you ever heard of .XCompose? For linux: https://github.com/kragen/xcompose For windows: https://github.com/samhocevar/wincompose How it works: You choose a compose key, then use it to compose special characters with specific sequences. Examples: ComposeKey, *, p: π. ComposeKey, s, s: ß ComposeKey, ComposeKey, d, e, g, c (degree Celsius): ℃ It is not impossible to use unicode special characters on a daily base easily, with the use of this tool. No need to use the character map or anything. I think it would be very nice, if one had the option of using these special characters. E.g. → instead of >>, if you desire that; std.math defining π as π. Small gimmicks like these are things I find to be good for a language to have.
Re: GSoC 2016 "GDC Project - The GNU D Compiler" project
On Tuesday, 1 March 2016 at 11:50:02 UTC, Abhishek Kumar wrote: Hello I am Abhishek Kumar,computer science student from India.I am interested in working on D language during GSoC 2016.I found "GDC Project - The GNU D Compiler" interesting. I have interest in programming languages and compilers.I have been working on a Python to C++ code converter,also I am writing a Javascript parser for code minification in Scala(Using scala fastparse). I have prior open source experience in Scala and good knowledge of C/C++. Can someone help me with how to start and get familiar with D? I'll be glad to have your help and suggestions. Thanks Abhishek Kumar I had good C/C++ experience before learning D, thus to learn D I simply read the entire language reference at http://dlang.org/spec/intro.html; though you may find it a bit boring.