d

Can a compiler automatically detect pure functions without the type information about purity?

有些话、适合烂在心里 提交于 2019-11-29 15:53:58
问题 So I'm arguing with my friend who claims that a compiler like GCC can detect a pure function automatically without any type information. I doubt that. Languages like D or Haskell have purity in their type systems and a programmer explicitly defines what function is pure or not. A pure function has no side effects and can therefore very easily be parallelized. So the question is: Is this all necessary or not? Could a compiler detect purity, without any meta or type information, just by

About the non-nullable types debate

橙三吉。 提交于 2019-11-29 14:01:27
I keep hearing people talk about how non-nullable reference types would solve so many bugs and make programming so much easier. Even the creator of null calls it his billion dollar mistake , and Spec# has introduced non-nullable types to combat this problem. EDIT: Ignore my comment about Spec#. I misunderstood how it works. EDIT 2: I must be talking to the wrong people, I was really hoping for somebody to argue with :-) So I would guess, being in the minority, that I'm wrong, but I can't understand why this debate has any merit. I see null as a bug-finding tool. Consider the following: class

Should I use 'long' instead of 'int' on 64-bits in langs with fixed type size (like Java, C#)

做~自己de王妃 提交于 2019-11-29 13:17:19
In 10, or even 5 years there will be no [ Edit2: server or desktop] 32-bit CPUs. So, are there any advantages in using int (32bit) over long (64bit) ? And are there any disadvantages in using int ? Edit: By 10 or 5 years I meant on vast majority of places where those langs are used I meant which type to use by default . This days I won't even bother to think if I should use short as cycle counter, just for(int i... . The same way long counters already win registers are already 64-bit, there is already no gain in 32 bit types. And I think some loss in 8 bit types (you have to operate on more

Questions about postblit and move semantics

♀尐吖头ヾ 提交于 2019-11-29 11:59:13
问题 I have already asked a similar question a while ago, but I'm still unclear on some details. Under what circumstances is the postblit constructor called? What are the semantics of moving an object? Will it be postblitted and/or destructed? What happens if I return a local variable by value? Will it implicitly be moved? How do I cast an expression to an rvalue? For example, how would a generic swap look like? 回答1: A postblit constructor is called whenever the struct is copied - e.g. when

How to extract text from resonably sane HTML?

谁都会走 提交于 2019-11-29 07:42:42
问题 My question is sort of like this question but I have more constraints: I know the document's are reasonably sane they are very regular (they all came from the same source I want about 99% of the visible text about 99% of what is viable at all is text (they are more or less RTF converted to HTML) I don't care about formatting or even paragraph breaks. Are there any tools set up to do this or am I better off just breaking out RegexBuddy and C#? I'm open to command line or batch processing tools

D: finding all functions with certain attribute

南笙酒味 提交于 2019-11-28 23:17:29
Is it currently possible to scan/query/iterate all functions (or classes) with some attribute across modules? For example: source/packageA/something.d: @sillyWalk(10) void doSomething() { } source/packageB/anotherThing.d: @sillyWalk(50) void anotherThing() { } source/main.d: void main() { for (func; /* All @sillWalk ... */) { ... } } Believe it or not, but yes, it kinda is... though it is REALLY hacky and has a lot of holes. Code: http://arsdnet.net/d-walk/ Running that will print: Processing: module main Processing: module object Processing: module c Processing: module attr test2() has

What is the difference between const and immutable in D?

♀尐吖头ヾ 提交于 2019-11-28 23:10:33
What is the difference between the const and immutable type qualifiers in D? Something that is const cannot be mutated via that reference but could be mutated by a mutable reference to the same data. Something that is immutable can't be mutated by any reference to that data. So, if you have const C c = foo(); then you know that you cannot mutate the object referred to by c through c , but other references to the object referred to by c may exist in your code, and if they're mutable, they could mutate it and therefore change what c sees. But if you have immutable C c = foo(); then you know that

Does D have something akin to C++0x's move semantics?

血红的双手。 提交于 2019-11-28 22:42:22
A problem of "value types" with external resources (like std::vector<T> or std::string ) is that copying them tends to be quite expensive, and copies are created implicitly in various contexts, so this tends to be a performance concern. C++0x's answer to this problem is move semantics , which is conceptionally based on the idea of resource pilfering and technically powered by rvalue references . Does D have anything similar to move semantics or rvalue references? I believe that there are several places in D (such as returning structs) that D manages to make them moves whereas C++ would make

What are all the syntax problems introduced by the usage of angle brackets in C++ templates?

廉价感情. 提交于 2019-11-28 20:16:07
In C++ templates are instantiated with angle brackets vector<int> and the Java and C# languages have adopted the same syntax for their generics. The creators of D, however, have been quite vocal about the problems that angle brackets bring and they made a new syntax foo!(int) — but I've never seen too many details about what problems angle brackets bring, exactly. One of them was when instantiating a template with another template vector<vector<int>> , which would cause some (older?) compilers to confuse the trailing '>>` with the bit-shift or streaming operators. The solution was to insert a

What are the differences between concepts and template constraints?

折月煮酒 提交于 2019-11-28 15:02:56
I want to know what are the semantic differences between the C++ full concepts proposal and template constraints (for instance, constraints as appeared in Dlang or the new concepts-lite proposal for C++1y ). What are full-fledged concepts capable of doing than template constraints cannot do? sftrabbit The following information is out of date. It needs to be updated according to the latest Concepts Lite draft. Section 3 of the constraints proposal covers this in reasonable depth. The concepts proposal has been put on the back burners for a short while in the hope that constraints (i.e. concepts