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...
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...
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.
...
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...
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 ...
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...
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...
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 );
...
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 ...
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...
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?
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 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?
...
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?
...
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...
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,...
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));
}
}
...