d

Examples of what D’s templates can be used for

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 hand...

Unmanaged memory management in D

What's the best way to avoid using GC in D? Is there a way to use classes that doesn't involve their memory being managed, or do you have to use pointers to malloc'd structs like you would in C and C++? ...

Does D have 'newtype'?

Does D have 'newtype' (as in Haskell). It's a naive question, as I'm just skimming D, but Google didn't turn up anything useful. In Haskell this is a way of making different types of the same thing distinct at compile time, but without incurring any runtime performance penalties. e.g. you could make newtypes (doubles) for metres, seco...

Overhead of exception handling in D

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 h...

Digital Mars D compiler; acquiring ASM output

I am reading the book from Andrei Alexandrescu about the D programming language. He's an excellent writer and does a pretty good job at explaining aspects of the D language. I however find certain constructs hard to understand when I cannot imagine the ASM output or consequences of certain keywords (such as in, out, etc. or other constru...

D programming language: module stdio cannot read file std\stdio.d

I installed dmd (2.0 ?) using the windows installer and am trying to compile the following program: module tcpechoserver; import std.stdio; const int MAXPENDING = 5; int main(char[][] argv) { if(argv.length != 2){ writef("Usage: %s <port>", argv[0]); } return 0; } But I get the following compiler error: Err...

How do I install a db bindings for the D programming language?

I tried installing several db apis in D 2.0, but the documentation is often either lacking or missing altogether. Does someone know more on the subject? ...

Is it possible to generically implement the amb operator in D?

Is it possible to generically implement the amb operator in D? http://www.haskell.org/haskellwiki/Amb http://www.randomhacks.net/articles/2005/10/11/amb-operator The sort of thing I'm thinking of is: amb([1, 2]) * amb([3, 4, 5]) == amb([3, 4, 5, 6, 8, 10]) amb(["hello", "world"]) ~ amb(["qwerty"]) == amb(["helloqwerty", "worldqwerty"]...

Is worth the effort to learn D?

Ok, let me reformulate the question. Imagine you have 3 projects: A text editor for programmers, a compiler and a search engine library for at least 3 types of files: html, .xls and pdf. You have 3 choices: C++, java and C# (or any other languages I previously mention), or you could explore the alternative of doing it with D. Then, you a...

Why does Phobos use enum for constants?

Why does Phobos use enum to define constants? For example, in std.math: enum real E = 2.7182818284590452354L; Why not use a global immutable? What are the advantages/disadvantages of enum over immutable? ...

How do you initialise an array of const values in D2?

Essentially, I want to be able to do something like this: struct Foo { const(int)[2] ints; this(int x, int y) { ints = [x, y]; } } but this doesn't work. The compiler (DMD 2.048) just complains that ints isn't mutable. How are you supposed to initialise the array? ...

How can I print a variable name and its value without typing the name twice?

When you are debugging, it's very useful to do this: var = calc() print("var:", var) Is there any language where this is easy to do? In C and C++ you can use the stringify macro operator # and in Ruby I found this question: http://stackoverflow.com/questions/2603617/ruby-print-the-variable-name-and-then-its-value The solution that u...

Writing a D (D2) binding for existing C libraries

I'd really like to get more into D, but the lack of good library support is really hindering me. Therefore I'd like to create some D bindings for existing C libraries I'd like to use. I've never done any binding, but it doesn't look too difficult either. I'm planning to do this for D2 (not specifically D1, but if it could be for both, e...

Interchanging delegate/function and interface in D2

I'd like to be able to define a function that takes an interface, but can be fulfilled with a delegate or function that provide the same functionality. For example, in C++ I can write something like: typedef std::function<int (float)> toInt; void fun(toInt dg) { ... } struct impl1 { int operator()(float x) { ... } }; int impl2(fl...

Compile Time Code Generation in D

I'm currently learning D, and one of the things I've wondered about is whether D has a way of duplicating the code generation capabilities of JVM languages. Here's a scenario: I have an object, and I want to generate a string based on that object that gives it's name and all its fields. In Java/Scala, I could just use reflection, but su...

Assigning a value to a non-static function pointer resulting in crash - WHY?

I have a function which is defined like this: typedef void (*logprintf_t)(const char* format, ...); logprintf_t logprintf void my_function() { logprintf = cast(logprintf_t)0x12345; } and it causes the application to exit. However, if I make the logprintf be static (I've seen this trick somewhere), i.e.: void my_function() { s...

Using D to program to the Java Native Interface

I've been looking at the D programming language and it looks like a lot of fun to try for someone already proficient in C++. Can I use D to program to the Java Native Interface which is a C interface? ...

D support for COM

Wikipedia says the following: "On Microsoft Windows, D can access COM (Component Object Model) code." What kind of support for COM is present in D? Does it make life easier than using COM in C++. I've found this link on the D page but it doesn't tell me too much. ...

Problem with Book Example

Is it just me, or is there a problem with page 68 of "The D Programming Language" ? On this page, the author discusses D's syntax of if-else statements and how they nest. He first presents this example: if(a == b) if(b == c) writeln("all are equal!"); else writeln("a is different from b. Or is that so?"); He th...

Do all profilers significantly slow execution?

The profilers I have experience with (mainly the Digital Mars D profiler that comes w/ the compiler) seem to massively slow down the execution of the program being profiled. This has a major effect on my willingness to use a profiler, as it makes profiling a "real" run of a lot of my programs, as opposed to testing on a very small input...