Questions tagged [phobos]

Phobos is the official runtime and standard library of the D programming language.

97 questions
2
votes
1 answer

std.regex.regex() not pure. Why?

In D std.regex.regex() is not pure: import std.regex; pure void test() // test.d(5): Error: pure function 'test' cannot call impure function 'regex' { auto r = regex(r"patern123", "g"); } Why? Is it A. Not enough pure keywords were thrown…
dnsmkl
  • 792
  • 5
  • 17
2
votes
2 answers

Read data from a webpage in D?

how to simply open an url and read the data from a webpage with D? (I prefer phobos over tango, if needing to use standard lib functionality)
Samuel Lampa
  • 4,336
  • 5
  • 42
  • 63
2
votes
1 answer

What is the reasoning behind the design of std.complex?

unittest { immutable float a = 1.1, b = 1.2; auto c1 = complex(a,b); auto r1 = c1 + c1; // error, not mutable } Which means that I can have Complex!(immutable float), but I can never use its opBinary functions against another instance of…
Arlen
  • 6,641
  • 4
  • 29
  • 61
1
vote
0 answers

Adding a custom type to a RedBlackTree

I want to keep an ordered set of records and the standard provides me with RedBlackTree. The record is of type Tuple!(string, uint). Here's what it looks like: import std.json : parseJSON; uint[string] wordTable; import…
noconst
  • 639
  • 4
  • 15
1
vote
1 answer

how to check for array or range length being at least N in Dlang

For N=1, I would use std.array : empty to check for length being at least N, and avoid having to go through the whole input. For N>1 (or all N), what is the idiomatic way in D language? I've tried to use the std.range : take which "Lazily takes only…
V-R
  • 1,309
  • 16
  • 32
1
vote
1 answer

Using std.algorithm.iteration.sum with Duration[]

Why I can't use std.algorithm.iteration.sum with Duration[] ? I thought I can use the sum in the same way than e.g. with int[]: int[] ints = [40, 27, 5]; int intSum = ints.sum(); assert(intSum == 72); But instead I get an unexpected (unexpected for…
user272735
  • 10,473
  • 9
  • 65
  • 96
1
vote
2 answers

Get the variable values at runtime using reflection in Dlang

Is it possible to get the class/struct/other variables value during runtime in dlang to get/set its value? If yes how to do that please provide example. And also is it possible to get the runtime variable value? Ex: class S{ int svariable =…
Hakuna Matata
  • 755
  • 3
  • 13
1
vote
4 answers

Is there an equivalent for Glob in D Phobos?

In python I can use glob to search path patterns. This for instance: import glob for entry in glob.glob("/usr/*/python*"): print(entry) Would print…
Matthew Jones
  • 372
  • 2
  • 11
1
vote
1 answer

A class that can parse IP domain (e.g. 192.168.0.0/16)

I am writing a simple script in D that needs to interface with command-line network programs that use IP domain addresses (e.g. 10.0.14.0/24). Is there any ready parser existing for that in D? Something, that can validate a domain and break it into…
Adam Ryczkowski
  • 7,592
  • 13
  • 42
  • 68
1
vote
1 answer

try to install Tango+D2 but compile with error symbol undefined (Window)

I try to use Tango and Phobo together in D2 and I downloaded the package from link and follow its installation process. But it has only Linux installation but not windows. This is what I do. Visual-D and DMD already installed. link I save the file…
Hami
  • 335
  • 1
  • 7
  • 22
1
vote
1 answer

Odd behaviour from Array in BinaryHeap

I have a tree-like structure using Node objects with references to other Node objects. Node is a class. Now, one of the routines I'm writing needs a minimum priority queue, which I'm implementing using std.container.BinaryHeap and…
Koz Ross
  • 3,040
  • 2
  • 24
  • 44
1
vote
1 answer

Cartesian product of immutable ranges

Why can't we compute the cartesian product of two immutable ranges ? The following code : import std.stdio; import std.algorithm; void main() { immutable int[] B = [ 1, 2, 3 ]; immutable int[] C = [ 4, 5, 6 ]; auto BC =…
matovitch
  • 1,264
  • 11
  • 26
1
vote
1 answer

D Socket Programming Basic Connection Script

I am brand new to D programming so please excuse my ignorance. I am trying to create a basic program to connect to a website and download a page or connect to a restful API and download info. Right now all I need to worry about is TCP (streams). I'm…
user2395126
  • 526
  • 1
  • 7
  • 20
1
vote
2 answers

Attempt string-to-real conversion in D without exceptions

Given an array of string, I want to find the first one that can be successfully converted to a real without using exceptions. The only relevant functions I can see in Phobos are std.conv.to and std.conv.parse, but both of these will throw an…
Peter Alexander
  • 53,344
  • 14
  • 119
  • 168
1
vote
2 answers

Segfault in D for too large inputs

The following D program crashes for input 939971 or higher, but not for input 939970 or lower: #!/usr/bin/rdmd --shebang -w -d-debug --relocation-model=pic import std.stdio; import std.bigint; import std.conv; import std.array; //extern (C) void…
Demi
  • 3,535
  • 5
  • 29
  • 45