d

D file I/O functions

I'm just learning D. Looks like a great language, but I can't find any info about the file I/O functions. I may be being dim (I'm good at that!), so could somebody point me in the right direction, please? Thanks ...

Is it possible to write one program with three programming languages?

Is it possible to make one program, written in Java, C++ and D? ...

How/where is the working directory of a program stored?

When a program accesses files, uses system(), etc., how and where is the current working directory of that program physically known/stored? Since logically the working directory of a program is similar to a global variable, it should ideally be thread-local, especially in languages like D where "global" variables are thread-local by def...

Loading Plugins (DLLs) on-the-fly

Is there a way to dynamically load and call functions from DLLs dynamically in D? I'd like my program to be able to load plugins at startup and perhaps on-the-fly as well. ...

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

Better D Documentation

Where can I find good solid D documentation? I've been trying to learn D, and am having issues finding good reference docs for the language. For instance, I see op opImplicitCast talked about back in 2007...was that ever implemented? Overall the language information seems to be extremely fragmented between dsource the digitalmars site...

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

What is a "yield return" equivalent in the D programming language?

Here is a simple generator in C#. IEnumerable<int> Foo() { int a = 1, b = 1; while(true) { yield return b; int temp = a + b; a = b; b = temp; } } How do I write a similar generator in Digital Mars D? (The question is about the yield return sta...

Linking to Static libraries

Coming from a C/C++ background. What is the proper way to link a D static (or dynamic) library to a D .exe file? Can I simply "import" the module from the library and then link to the .lib file at compile time? ...

Binary file I/O

How to read and write to binary files in D language? In C would be: FILE *fp = fopen("/home/peu/Desktop/bla.bin", "wb"); char x[4] = "RIFF"; fwrite(x, sizeof(char), 4, fp); I found rawWrite at D docs, but I don't know the usage, nor if does what I think. fread is from C: T[] rawRead(T)(T[] buffer); If the f...

Namespaces with classes and structs?

Will be nice if I got 'nested members' in D language, so I have the inglorious idea to code class Keyboard { struct Unused { string key1 = "Wake Up"; string key2 = "Sleep"; string key3 = "Power"; } Unused unused; } int main() { Keyboard kb; kb.unused.key1 = "Scroll Lock"; return 0; } ...

Haskell or D for GUI desktop application?

I like haskell and many things connected with it as its type-engine, lot of packages at Hackage, nice community, active development etc. Otoh, I had experience that some people gave up on our planned project considering Haskell too complicated (monads, lot of jargon from academia...) to grok (coming from C++ background), so it might be ...

std.algorithm.filter!() template with two parameters instead of just one?

Here is an example: int[] arr = [ 1, 2, 3, 4, 5 ]; auto foo = filter!("a < 3")(arr); assert(foo == [ 1, 2 ]); // works fine Now I want to be able to parameterize the predicate, e.g. int max = 3; int[] arr = [ 1, 2, 3, 4, 5 ]; auto foo = filter!("a < max")(arr); // doesn't compile This snippet won't compile obviously, sine the filte...

Non Member range functions

I have a class that I'm implementing ranges for. I'd like to implement the functions the way the phobos library does, i.e. outside the main class. void popBack(T)(ref T[] a) if (!is(Unqual!T == char) && !is(Unqual!T == wchar)) { assert(a.length); a = a[0 .. $ - 1]; } Here's my version: void popFront(T)(ref PersistentList!(T)...

Receive arrays of arrays of ... in D function?

Don't know if is possible, I want receive maybe data[n] or data[n][n][n]. In C could be (correct me if wrong): void save_data(void* arr, int n, int dimensions) { // do ugly things } But must exist a more elegant way in D. ...

Multiple types in one specialized D template

Say I have to deal ushort and uint some way, but string differently. So guess I need one specialized template for string and other to both ushort and uint. Is it? // for most void func(T)(T var) { ... } // for uint and ushort void func(T: uint, ushort)(T var) { ... } That is the idea, although the code can't compile. It's valid or ...

Basic question about D.

In D main fnc is defined: void main(/*perhaps some args but I do not remember*/) { } My question is that I know for sure that this fnc returns zero on success and non-zero on failure and yet it is defined as to not returning anything. What is the logic behind it? ...

Declare class member at runtime in D

I want the following struct as a class member, but I don't know the type of T, so I need "declare" the struct at runtime. struct Chunk (T) { string id; T[][] data; } class FileBla { this() { Chunk !int ck; // need to be turned in a class member } } Should be missing something easy. ...

CMake or Waf for D project

Hello! We are looking for adequate build tool for a desktop GUI application to be written in D (using Qt toolkit), consisting of several native libraries, using 3rd party C-lib(s). It has to build on Linux (native development) and Mac as well on Windows. We might adopt Code::Blocks as IDE. Waf already has support for D language, while ...

Setting up a working D2.x toolchain (with gtkd) on Ubuntu 10.04

I've been playing around with D for a few days and was getting quite excited about it until, that is, I tried to get gtkd working. I've now wasted the best part of 3 days trying to get a working setup and am beginning to get (read; long ago got) a bit demoralised. I was wondering if anyone can help before I give up. A lot of the informat...