d2

What debugger can be used with D 2.0 on windows and how do I use it?

I have been playing around with D 2.0 a bit today mostly because of the "The Case for D" in DDJ. I have downloaded D 2.0 for windows but have not figured out how to step through a running program in the debugger. I tried to get the shipped copy of windbg.exe to work but it is crashing on me all the time and does not seem to see the sou...

How to use pure in D 2.0

While playing around with D 2.0 I found the following problem: Example 1: pure string[] run1() { string[] msg; msg ~= "Test"; msg ~= "this."; return msg; } This compiles and works as expected. When I try to wrap the string array in a class I find I can not get this to work: class TestPure { string[] msg; void ad...

DMD 2 on Snow Leopard

Has anyone tried the Digitalmars D compiler (version 2) on Snow Leopard? I'd like to upgrade but I'd rather have a working D compiler. ...

Thread-local, class instance-local storage?

Is there a good, platform-agnostic way to implement a variable that's local to both a thread and a class instance, i.e. if you have T threads and I class instances, you have TxI instances of that variable? I'm using the D programming language, version 2, but a good language-agnostic answer would also be useful. Here are some constraint...

How well does D support 64 bit?

I'd like to try out the D programming language. I have simple pet project I've been meaning to finish and I thought it would be good opportunity to learn D 2.0. However, my primary OS is kubuntu 64bit dual booting with Windows 7 64bit and I can't seem to get it to work. The project will use SDL and I suspect my 64 bit OS might be the ...

How to get started with D on Mac OS X 10.6 (Snow Leopard)

I've been more or less interested in "D" for a couple years now and recently decided to start actually playing with it. I've been able to grasp the basics quite easily and I completely love the basic feature set of the language and the more I read about it, tho more impressed I get. Now, I'm very interested in writing a custom web appli...

Why allow concatenation of string literals?

I recently got bit by a subtle bug. char ** int2str = { "zero", // 0 "one", // 1 "two" // 2 "three",// 3 nullptr }; assert( values[1] == "one"_s ); // passes assert( values[2] == "two"_s ); // fails If you have godlike code review powers you'll notice I forgot the , after "two". After the considerable effort to fin...

how to convert a c string to a d string?

This is so simple I'm embarrassed to ask, but how do you convert a c string to a d string in D2? I've got two use cases. string convert( const(char)* c_str ); string convert( const(char)* c_str, size_t length ); ...

D callbacks in C functions

I am writing D2 bindings for Lua. This is in one of the Lua header files. typedef int (*lua_CFunction) (lua_State *L); I assume the equivalent D2 statement would be: extern(C) alias int function( lua_State* L ) lua_CFunction; Lua also provides an api function: void lua_pushcfunction( lua_State* L, string name, lua_CFunction func ...

Link compatibility between C++ and D

D easily interfaces with C. D just as easily interfaces with C++, but (and it's a big but) the C++ needs to be extremely trivial. The code cannot use: namespaces templates multiple inheritance mix virtual with non-virtual methods more? I completely understand the inheritance restriction. The rest however, feel like artificial limi...

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

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"]...

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

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

Synchronizing arbitrary properties in an object transparently in D

Let's say I have a class like so: class Gerbil{ int id; float x,y,z; } Let's further say this is part of a real-time simulation where I have a server/client setup and I change a property on the server-side: //... gerbil.x = 9.0; //... Now I want to send over this change to the client to synchronize the world state. However,...

Using std.algorithm.map with member functions in D2.

I have: Foo foo = new Foo(); foreach (i; 0..10) { Bar bar = foo.getBar(i); ... } I want to be able to instead say (equivalently): foreach (bar; foo.getAllBars()) { ... } How do I go about implementing getAllBars()? I figured something like this: class Foo { auto getAllBars() { return map!(getBar)(iota(10)); } } ...