Questions tagged [d]
D is a multi-paradigm systems programming language developed by Walter Bright and, since 2006, Andrei Alexandrescu. Now, D is an open source collaboration.
2,612
questions
0
votes
3
answers
38
views
D language import local module
I am new to D language. i have a project A. When i executed dub build it has created me libA.so. i am trying to create a different .d file and import this module.
now i wanted to write a D wrapper to ...
0
votes
1
answer
38
views
Using dplyr to remove duplicates conditionally
I have a dataset in longformat that contains both visit and measure dates for each ID. What I want is to remove the duplicate visit dates for each ID conditionally, namely:
IF visit date - measure ...
0
votes
0
answers
22
views
VS code Dlang: can't change build config
I am giving D a shot with the VS code extension code-d. Everything works fine, except that I can't switch configuration, arch type or build type. If I try to do any of these things, I receive the ...
2
votes
1
answer
77
views
Returning a filtered range
I'm looking at filtering ranges, and getting a little confused. In D, I can write this code:
import std.stdio;
import std.range;
import std.algorithm;
auto filterNums(int[] vals)
{
int limit = 3;
...
1
vote
1
answer
52
views
Returning by reference from struct method in D
I'm starting my journey in D from C++. In C++ passing by reference or value is quite explicit, but in D it seems to vary between structs and classes.
My question is how can I force a return by ...
0
votes
0
answers
50
views
Undefined structures and functions from WinInet import
I'm making my first steps with D, and as a trial I am trying to access a SOAP API via the Internet. I have a working C++ app (Visual Studio 2019, Windows 10) which uses the wininet library. I am using ...
2
votes
1
answer
63
views
Where is D's `std.sumtype`?
I'm working on a project in the D language and I want to use a module from the standard library called std.sumtype. I'm on debian oldstable, and I've tried both GDC and LDC. DMD is unavailable, ...
0
votes
2
answers
63
views
How do you define a decimal number in a PEG grammar?
I have the following grammar
Arithmetic:
Term < Factor (Add / Sub)*
Add < "+" Factor
Sub < "-" Factor
Factor < Primary (Mul / Div)*
...
2
votes
2
answers
135
views
Is it possible to create a contiguous multidimensional array at runtime in D?
I would like to create a rectangular multidimensional array at runtime, such that the entire array is stored in a contiguous block of memory. It is not necessary for the array to be resizable after ...
0
votes
1
answer
72
views
Converting C "srand(time(NULL));" to D language
What's the equivalent in D language for C statement srand(time(NULL));
0
votes
1
answer
122
views
VS Code custom run configuration for D
Is there a way to add a custom run configuration that would run a current file in the terminal?
Currently no extensions exist for debugging .d files on Visual Studio Code. I still can manually enter ...
3
votes
2
answers
91
views
dlang incompatible type error in checking string
i have this code to check if string have j character
import std.stdio;
void main() {
const string name = "john";
for (int i = 0;i < name.length;i++) {
if (name[i] == &...
0
votes
0
answers
32
views
How do I replace keybindings
I'm trying to replace the scroll event for a GtkScrollabelWindow with the the middle mouse button so I can move the contents around and the zoom event with the mouse wheel. What's the best way to go ...
1
vote
1
answer
59
views
D language: I can't split a text block copied from a Wikipedia unicode chart into a list of single-letter strings. Output comes out wrong in editor
The MWE and the only code you need to see this is the following:
module unicode_support;
import std.string;
const wstring unicodeVarSource = `
𝐀 𝐁 𝐂 𝐃 𝐄 𝐅 𝐆 𝐇 𝐈 𝐉 𝐊 𝐋 𝐌 𝐍 ...
0
votes
1
answer
73
views
How to do string formatting in BetterC mode?
I'd like to use something like the "Concepts" package from Atila Neves.
I implemented the check of an object against a type signature myself in a simple naive way. I can check struct objects ...
0
votes
2
answers
63
views
How to get string input from a socket in D?
I'm using this code to listen to a port:
int start(){
ushort port = 61888;
listener = new TcpSocket();
assert(listener.isAlive);
listener.blocking = false;
...
0
votes
2
answers
49
views
How do I build a DAllegro project using dub?
I'm fairly new to D, and wish to use allegro for graphics. I also want to use dub to build my project. However, after running
dub add allegro (https://code.dlang.org/packages/allegro), and trying to ...
0
votes
1
answer
32
views
Unable to read a text file using `std.file.readText(fileName)` in Visual D (throws strange exception)
The exception details are:
Unhandled exception at 0x00007FF7B11A7F40 in mutation_lib.exe: 0xC0000096: Privileged instruction.
And it occurs at this line in the standard library source:
void[] read(R)(...
1
vote
1
answer
76
views
Problems using malloc in D language: why writeln call the destructor twice in this example
I am trying to write a D wrapper for a C library (libmpdec) that stores its data using the standard C malloc function. But the are
some nasty bugs in my programs that I don't know how to solve.
So I ...
0
votes
0
answers
82
views
Drawing top line in viewport using GL3
I drawing OpenGL rectangle:
Code is:
glViewport( 0, 0, 100, 100 );
Vertex[4] vertices =
[
Vertex( [-1.0f, 1.0f ], glColor ), // top-left
Vertex( [ 1.0f, 1.0f ], glColor ), // top-right
...
0
votes
1
answer
54
views
How to get the template argument of an alias-this-struct via is-expression in D?
I was playing around with alias this which can simulate inheritance for structs in D. For a library that I recently started I also would like to provide trait templates which detect the proper type ...
2
votes
2
answers
54
views
Inconsitent behaviour with computation of "greatest product given 'n' adjacent digits" (D language)
I'm working on a solution for Project Euler (problem 8) which involves working out the largest product of thirteen adjacent digits. I wrote a solution (below) but it doesn't seem to be outputting the ...
0
votes
0
answers
55
views
How to store MongoClient in session store
What is the best way to store client connection? It needs in order to each request didn't request authorization to mongo. When I try:
auto msettings = new MongoClientSettings();
MongoClient client = ...
2
votes
0
answers
101
views
Why does switching draw call order mess things up using Cairo and Win32 layered windows?
I'm working on a Win32 app with layered windows. The window contents are drawn using Cairo. The transparency is very unpredictable however. Sometimes everything is correct; opaque parts are opaque, ...
0
votes
0
answers
73
views
Fasteest algorithm to compute avg distance between two Sets of points
Please see picture :
Given the set of points marked in Red, I take two consecutive points (here 0 and 1 - these numbers are just for illustration , thus not the index in the array holding these ...
2
votes
2
answers
75
views
How do you print or capture the current module name?
I want to print the module name of my main source file in that source file. I tried this:
import std.stdio;
import std.traits; // moduleName template
int main(string[] args)
{
writeln("The ...
1
vote
1
answer
353
views
Error: A dynamic link library (DLL) initialization routine failed on electron but it's fine on node js
I'm trying to load a custom module in electron written in D with node_dlang package, which is fine with node, but it fails within electron.
the test with node, that runs just fine, goes like this:
...
0
votes
2
answers
144
views
Unexpected '\n' when converting from type string to type int while converting user input to int from string
I get a mysterious error when I compile my code I wrote in dlang it shows
"Unexpected '\n' when converting from type string to type int"
I checked it on google but I did not find a solution (...
0
votes
0
answers
73
views
Linear regression error - line slope wrong
Consider this function:
double calculate_geoHeading(double [] x, double [] y) {
/+ +++++++++
++ This function will return the heading of the best fit line
++
+/
double r;
...
-2
votes
1
answer
577
views
Compiler Explorer Assembly Output for C, C++ and D (dlang) [closed]
When using Compiler Explorer (https://godbolt.org/) to compare assembly output of simple programs, why D language assembly output is so long compared to C or C++ output. The simple square function ...
1
vote
4
answers
99
views
Destructured iteration over variadic arguments like a tuple sequence in D
Let's say I want to process a variadic function which alternately gets passed start and end values of 1 or more intervals and it should return a range of random values in those intervals. You can ...
1
vote
0
answers
50
views
Sorting Json struct from vibe.d
I faced a problem with wrong sorting JSON keys. I use mongo db and I need to send a creating user form command.
vibe-d JSON:
Json a2 = Json([
"createUser": ...
0
votes
1
answer
37
views
Having trouble with package.d
I am having trouble with D's package.d feature. I have my package.d file:
module dew;
public
import dew.util;
I then have util.d:
module dew.util;
struct Size
{
int width;
int height;
}
...
1
vote
1
answer
82
views
How to get template function from so/dll?
How to get template function from so/dll?
I tried:
Library libdll;
T abc(T)();
static this()
{
libdll = Library("libs/libdll.so");
abc = cast(typeof(abc)) libdll.loadSymbol!(typeof(...
1
vote
1
answer
65
views
Can I Convert a String to an Enum Value in D?
I have the following enum declared which using a string as its underlying value:
enum IssueType : string {
STUDENT_LEAVING = "leaving",
STUDENT_CONFLICT = "conflict",
...
2
votes
1
answer
100
views
A D range that is RandomAccess and hasLength but not hasSlicing?
In the implementation of findSplit in Phobos, we have this special case:
static if (isSomeString!R1 && isSomeString!R2
|| (isRandomAccessRange!R1 && hasSlicing!R1 && ...
1
vote
2
answers
114
views
Iterate JSON during compile-time, in Dlang
I want to iterate over the JSON using CTFE. I have tried both std.json and vibe.data.json, but there is no luck. I am not sure what I am missing.
import std.stdio;
import std.json;
import std.array;
...
1
vote
2
answers
70
views
How to access module AST from DMD mars.d
In the DMD source the tryMain function runs several optimization passes on the AST. What I am trying to do is grab the AST, run the passes manually and examine the module AST. Does one just hack the ...
3
votes
1
answer
216
views
Why is my D code for finding prime numbers much faster than my C++ code?
I coded two small projects in C++ and D(lang) respectively to calculate a given number of prime numbers. The code is very similar in both projects. However, my D code runs MUCH faster than my C++ code,...
1
vote
1
answer
78
views
Draw a Concave Shape, given a set of lines
Consider the picture :
Given the black "irregular line" segments, I want to have the green boundary surrounding them.
My Attempt to solve :
Note, that I need to capture the concavity. Thus ...
-2
votes
1
answer
71
views
Can't render a triangle with EBO
I wanna render a rectangle with GL_ELEMENT_ARRAY_BUFFER but I get only one line render. With GL_ARRAY_BUFFER it works. For example, I've tried to render only one triangle but it also doesn't work.
...
2
votes
0
answers
50
views
VisualD/Visual Studio Cannot Open Premake Generated .visualdproj
I've been trying out premake with D, and have found that Visual Studio cannot open the generated visualdproj files. Even the example given in the readme for the module does not work. However, a C ...
0
votes
1
answer
69
views
Why is the button not expanding to fill all the space?
I've made a tiny test GtkD DUB project (with GtkD 3.9.0 as dependency) to make a minimal reproducible example of a problem I am having in a larger project. Apparently Box is not expanding the middle ...
0
votes
2
answers
104
views
Why dub doesn't see the source folder?
I wanted to run my first project with dub. I initialized the project with dub init sandbox', then ran it with dub run. But dub said this:
Configuration 'application' of package sandbox contains no ...
0
votes
1
answer
94
views
Check If Index Exists in Array D
I apologize in advance if anything isn't clear enough.
While attempting to check if an index value exists of an array in D, I encountered an unexpected RangeError.
I'm attempting to make an array ...
1
vote
2
answers
117
views
How do I import a package from the local filesystem using dub?
I have a project that uses dub. I want to use an external file vendored into my project, as a dependency. How do I do this? I don't want to have it in my project's source/ dir. I don't want to add it ...
0
votes
1
answer
72
views
How to know the memory size of a trie?
Trie: https://en.wikipedia.org/wiki/Trie
I want to impl different kinds of Trie and compare their memory size.
Is there a generic function like a.memoryUsage() in core or std? Or need to impl ...
0
votes
1
answer
94
views
Dynamically Bind extern(Objective-C) Classes in D
I want to make heavy use of extern (Objective-C) classes in my D app as I don't want to deal with manually sending Objective-C messages. However, I'm mainly using frameworks like AppKit, IOKit, and ...
3
votes
1
answer
186
views
Deprecation: returning this escapes a reference to parameter this
Ran into this while updating DMD to 2.094.1 in our codebase. What is it about and how to fix it?
Deprecation: returning this escapes a reference to parameter this
perhaps annotate the parameter ...
0
votes
0
answers
97
views
How to define vkCreateXcbSurfaceKHR in Erupted-V2?
I'm trying to use XCB with Vulkan bindings Erupted-V2 but I'm getting an error:
source/gfxdevicevulkan.d(231,24): Error: undefined identifier vkCreateXcbSurfaceKHR
Here's my dub.json:
{
"name&...