d

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

百般思念 提交于 2019-11-30 10:45:17
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 assuming that anything that does IO or accesses global variables automatically is not pure? Sure, you can

Call C++(C) from D language

廉价感情. 提交于 2019-11-30 09:40:19
How to call C++ function from D program? I still can't understand how to do it. What commands do I need to execute? I use dmd in Fedora. Vlad Simplest example I can think of, if you're calling C functions: $ cat a.c int f(int a, int b){ return a + b + 42; } $ cat a.di extern (C): int f(int, int); $ cat b.d import std.stdio; import a; void main(){ writeln( f( 100, 1000) ); } $ gcc -c a.c $ dmd b.d a.o $ ./b 1142 $ If you're using shared objects, you could so something like: $ cat sdltest.di module sdltest; extern (C): struct SDL_version{ ubyte major; ubyte minor; ubyte patch; } SDL_version *

How does memchr() work under the hood?

折月煮酒 提交于 2019-11-30 08:55:32
Background: I'm trying to create a pure D language implementation of functionality that's roughly equivalent to C's memchr but uses arrays and indices instead of pointers. The reason is so that std.string will work with compile time function evaluation. For those of you unfamiliar w/ D, functions can be evaluated at compile time if certain restrictions are met. One restriction is that they can't use pointers. Another is that they can't call C functions or use inline assembly language. Having the string library work at compile time is useful for some compile time code gen hacks. Question: How

How to extract text from resonably sane HTML?

若如初见. 提交于 2019-11-30 07:05:48
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 as well as C/C#/D libraries. SLaks You need to use the HTML Agility Pack . You probably want to find

Why 0.1 + 0.2 == 0.3 in D?

假装没事ソ 提交于 2019-11-30 05:50:26
问题 assert(0.1 + 0.2 != 0.3); // shall be true is my favorite check that a language uses native floating point arithmetic. C++ #include <cstdio> int main() { printf("%d\n", (0.1 + 0.2 != 0.3)); return 0; } Output: 1 http://ideone.com/ErBMd Python print(0.1 + 0.2 != 0.3) Output: True http://ideone.com/TuKsd Other examples Java: http://ideone.com/EPO6X C#: http://ideone.com/s14tV Why is this not true for D? As understand D uses native floating point numbers. Is this a bug? Do they use some specific

Examples of what D’s templates can be used for

你说的曾经没有我的故事 提交于 2019-11-30 03:08:31
I hear that the D language has powerful metaprogramming features for executing functions at compile time. That sounds very exciting, but I find it difficult to think of practical examples of things that are hard to accomplish without them. Can anyone give some examples of situations where D's metaprogramming features comes in very handy? One really cool and practical usage of compile time function execution is for generating code at compile time, possibly from config files, or maybe scripts. Here's a simple example of processing a file at compile time. main.d string make_ints(string s) {

Overhead of exception handling in D

送分小仙女□ 提交于 2019-11-30 02:12:45
问题 In the D2 programming language, what are the performance implications of using exception handling? In particular: What if I write no exception handling code? What if I do, but no exceptions are ever thrown? What if I do, and exception are thrown? Does exception handling cause any optimization opportunities to be missed? Can exception handling be disabled like it can in many (most?) C++ implementations? I know that almost all commercial game development studios disable exception handling in

Where to find algorithms for standard math functions?

别等时光非礼了梦想. 提交于 2019-11-30 01:34:32
I'm looking to submit a patch to the D programming language standard library that will allow much of std.math to be evaluated at compile time using the compile-time function evaluation facilities of the language. Compile-time function evaluation has several limitations, the most important ones being: You can't use assembly language. You can't call C code or code for which the source is otherwise unavailable. Several std.math functions violate these and compile-time versions need to be written. Where can I get information on good algorithms for computing things such as logarithms, exponents,

How fast is D compared to C++?

左心房为你撑大大i 提交于 2019-11-29 18:41:23
I like some features of D, but would be interested if they come with a runtime penalty? To compare, I implemented a simple program that computes scalar products of many short vectors both in C++ and in D. The result is surprising: D: 18.9 s [see below for final runtime] C++: 3.8 s Is C++ really almost five times as fast or did I make a mistake in the D program? I compiled C++ with g++ -O3 (gcc-snapshot 2011-02-19) and D with dmd -O (dmd 2.052) on a moderate recent linux desktop. The results are reproducible over several runs and standard deviations negligible. Here the C++ program: #include

When does template instantiation bloat matter in practice?

巧了我就是萌 提交于 2019-11-29 17:34:52
问题 It seems that in C++ and D, languages which are statically compiled and in which template metaprogramming is a popular technique, there is a decent amount of concern about template instantiation bloat. It seems to me like mostly a theoretical concern, except on very resource-constrained embedded systems. Outside of the embedded space, I have yet to hear of an example of someone being able to demonstrate that it was a problem in practice. Can anyone provide an example outside of severely