d

Does D have 'newtype'?

你离开我真会死。 提交于 2019-12-03 12:38:29
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, seconds and kilograms. This would error at compile time if your program added a quantity in metres to a quantity in seconds, but would be just as fast at runtime as if both were doubles (which they are at runtime). If D doesn't have something analogous to 'newtype',

Loading Plugins (DLLs) on-the-fly

折月煮酒 提交于 2019-12-03 12:00:50
问题 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. 回答1: It depends on how dynamic you want to get. If you want to dynamically load a dll and run some predefined functions, there is a very nice wrapper by Wei Li here. Thanks to the power of templates, it allows you to do things like these: // define functions alias Symbol!("MessageBoxW", int function(HWND, LPCWSTR, LPCWSTR,

How to use a C library from D?

痴心易碎 提交于 2019-12-03 10:05:40
Today I heard about the D programming and that it is compatible to C code. Nevertheless I haven't found any information on whether it is possible to use C libraries like GTK or PortAudio from D? If it is possible, could you explain how to do this? It is possible to call C libraries from D. What you need to do is to convert the C header files to D. For the most part this is pretty straightforward, and there is a hard-to-use command-line tool to help automate the process. It's never really worked for me on anything but toy examples, but it could be a good start to see the kind of transformations

Can traits in D be used for type classes?

爱⌒轻易说出口 提交于 2019-12-03 05:52:15
I'm new to D, and I'm looking for a good way to program with Haskell-like type classes e.g. Functors, Monoids, etc. in D. Is something like this implemented in Tango or Phobos? I've heard about traits which enable compile-time type checking for certain properties. Can they be used for type classes? I've tried a little bit with template specialization and come up with this: // Monoid.d // generic Monoid gets called when there is no instance of Monoid for Type T class Monoid(T) { pragma(msg, "Type is not a Monoid"); } // Monoid instance for double class Monoid(T:double) { static T mzero() {

ptrdiff_t too small?

故事扮演 提交于 2019-12-03 05:03:57
I've always wondered: isn't ptrdiff_t supposed to be able to hold the difference of any two pointers by definition ? How come it fails when the two pointers are too far? (I'm not pointing at any particular language... I'm referring to all languages which have this type.) (e.g. subtract the pointer with address 1 from the byte pointer with address 0xFFFFFFFF when you have 32-bit pointers, and it overflows the sign bit...) No, it is not. $5.7 [expr.add] (from n3225 - C++0x FCD) When two pointers to elements of the same array object are subtracted, the result is the difference of the subscripts

Applications development with D language

微笑、不失礼 提交于 2019-12-03 04:56:04
问题 For those who had developed applications with D, which libraries did you use to build your application? those libraries were good documented? did you use Tango? do you feel that D is ready to build big applications? which IDE did you use? Descent maybe? 回答1: Note that any C library can be used with D, as D fully supports the C ABI. D has some limited support for C++ libraries, though not C++ template libraries. 回答2: I used tango libraries + dfl and a bit of my own. Tango documentation is

D programming without the garbage collector

别等时光非礼了梦想. 提交于 2019-12-03 03:01:18
问题 I've been looking at D today and on the surface it looks quite amazing. I like how it includes many higher level constructs directly in the language so silly hacks or terse methods don't have to be used. One thing that really worries me if the GC. I know this is a big issues and have read many discussions about it. My own simple tests sprouted from a question here shows that the GC is extremely slow. Over 10 times slower than straight C++ doing the same thing. (obviously the test does not

Loading Plugins (DLLs) on-the-fly

我是研究僧i 提交于 2019-12-03 02:28:08
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. It depends on how dynamic you want to get. If you want to dynamically load a dll and run some predefined functions, there is a very nice wrapper by Wei Li here . Thanks to the power of templates, it allows you to do things like these: // define functions alias Symbol!("MessageBoxW", int function(HWND, LPCWSTR, LPCWSTR, UINT)) mbw; alias Symbol!("MessageBoxA", int function(HWND, LPCSTR, LPCSTR, UINT)) mba; // load dll auto

Is D's grammar really context-free?

南笙酒味 提交于 2019-12-03 01:02:19
问题 I've posted this on the D newsgroup some months ago, but for some reason, the answer never really convinced me, so I thought I'd ask it here. The grammar of D is apparently context-free. The grammar of C++, however, isn't (even without macros). ( Please read this carefully! ) Now granted, I know nothing (officially) about compilers, lexers, and parsers. All I know is from what I've learned on the web. And here is what (I believe) I have understood regarding context, in not-so-technical lingo:

Metaprogramming in C++ and in D

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 01:00:52
问题 The template mechanism in C++ only accidentally became useful for template metaprogramming. On the other hand, D's was designed specifically to facilitate this. And apparently it's even easier to understand (or so I've heard). I've no experience with D, but I'm curious, what is it that you can do in D and you cannot in C++, when it comes to template metaprogramming? 回答1: The two biggest things that help template metaprogramming in D are template constraints and static if - both of which C++