dmd

d programming, parse or convert string to double

自闭症网瘾萝莉.ら 提交于 2019-12-08 15:59:32
问题 as easy as it is in other languages, i can't seem to find an option in the d programming language where i can convert a string (ex: "234.32") into a double/float/real. using atof from the std.c.stdio library only works when i use a constant string. (ex: atof("234.32") works but atof(tokens[i]); where tokens is an dynamic array with strings doesn't work). how to convert or parse a string into a real/double/float in the d-programming language? 回答1: Easy. import std.conv; import std.stdio; void

D: dmd saying something really bizarre

喜欢而已 提交于 2019-12-08 02:27:17
问题 I was writing a library for myself to help automate some really common tasks I've been doing in D for scripting from the command line. For reference, here is the code in its entirety: module libs.script; import std.stdio: readln; import std.array: split; import std.string: chomp; import std.file: File; //Library code for boring input processing and process invocation for command-line scripting. export: //Takes the args given to the program and an expected number of arguments. //If args is

Elegant operator overloading in D

点点圈 提交于 2019-12-03 15:09:39
问题 For a while I was confused about the direction of D's operator overloading, but now I realize it's a beautiful system... if It would only work with core types (int, float, etc). Consider the follow code: struct Vector { float X, Y; void opOpAssign(string op)(Vector vector) { X.opOpAssign!op(vector.X); // ERROR: no property "opOpAssign" for float Y.opOpAssign!op(vector.Y); // ERROR: ditto } } This would be beautiful code if it worked, seeing as it overloads all +=, -=, *=, etc.. operators in

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

时光怂恿深爱的人放手 提交于 2019-12-02 18:04:05
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 statement) Thanks! Update. That's interesting. Since I'm just generating a mathematical sequence, using recurrence may be a good option. auto fib = recurrence!("a[n-1] + a[n-2]")(1, 1); foreach (e; take(fib, 10)) // <- prints first ten numbers from the sequence { writeln(e); } There's no exact equivalent in D. Here are some rough equivalents: Using opApply

DMD vs. GDC vs. LDC

主宰稳场 提交于 2019-12-02 17:51:02
What are the Pros/Cons of the different D Compilers? How is the performance and the standard compliance/D2 support? How well are debuggers supported? How good are the Error messages and is the IDE integration? How good is the 64 bit support? My thought so far: DMD Mature and well maintained Only one platform, 64 bit support is not good Not FOSS GDC Supports various platforms Has very mature optimizations, so it's fast? Out of date runtime? GCC so a good debugger support? LDC Supports various platforms LLVM, so it supports JITing? Has very mature optimizations, so it's fast? Not very well

std.algorithm.joiner(string[],string) - why result elements are dchar and not char?

好久不见. 提交于 2019-12-01 16:43:32
问题 I try to compile following code: import std.algorithm; void main() { string[] x = ["ab", "cd", "ef"]; // 'string' is same as 'immutable(char)[]' string space = " "; char z = joiner( x, space ).front(); // error } Compilation with dmd ends with error: test.d(8): Error: cannot implicitly convert expression (joiner(x,space).front()) of type dchar to char Changing char z to dchar z does fix the error message, but I'm interested why it appears in the first place. Why result of joiner(string[]

Choosing Between GDC and DMD

时光总嘲笑我的痴心妄想 提交于 2019-12-01 15:41:30
I'm new to programming in D. What are the pros and cons of choosing either DMD (2.061) or GDC (4.6, 4.7 or 4.8, snapshot). And what GDC version should I pick? I've successfully built a recent snapshot of GCC-4.8 and GDC-4.8 and it compiles a hello world program. Here are my thoughts on pros so far: GDC : More platforms, run-time performance DMD : compilation-performance, more tested? What about debugging support through GDB - does it differ between GDC and DMD? Michal Minich Use DMD as it is the reference implementation and is most widely used. It is also the most up to date as new features

Choosing Between GDC and DMD

℡╲_俬逩灬. 提交于 2019-12-01 14:33:14
问题 I'm new to programming in D. What are the pros and cons of choosing either DMD (2.061) or GDC (4.6, 4.7 or 4.8, snapshot). And what GDC version should I pick? I've successfully built a recent snapshot of GCC-4.8 and GDC-4.8 and it compiles a hello world program. Here are my thoughts on pros so far: GDC : More platforms, run-time performance DMD : compilation-performance, more tested? What about debugging support through GDB - does it differ between GDC and DMD? 回答1: Use DMD as it is the