Re: D create many thread
On Thursday, 6 February 2020 at 22:00:26 UTC, tchaloupka wrote: On Wednesday, 5 February 2020 at 13:05:59 UTC, Eko Wahyudin wrote: Hi all, I'm create a small (hallo world) application, with DMD. But my program create 7 annoying threads when create an empty class. If you don't want the parallel sweep enabled for your app, you can turn it of ie with: ``` extern(C) __gshared string[] rt_options = [ "gcopt=parallel:0" ]; ``` Or in various other ways as described in mentioned documentation: https://dlang.org/spec/garbage.html#gc_config Why are we doing it like that? That's the least user-friendly method of configuring the GC I have ever seen.
Re: D create many thread
On 07/02/2020 8:53 AM, uranuz wrote: Is it also possible to set some custom thread name for GC threads in order to be distinguishable from other threads in utilities like `htop`? It would be handy... https://dlang.org/phobos/core_thread_osthread.html#.Thread.name.2
Re: How to converte string to wstring[]?
import std.conv: to; string str = "test1"; wstring[] wstr = [to!wstring(str)];
Re: D create many thread
On Wednesday, 5 February 2020 at 13:05:59 UTC, Eko Wahyudin wrote: Hi all, I'm create a small (hallo world) application, with DMD. But my program create 7 annoying threads when create an empty class. If you don't want the parallel sweep enabled for your app, you can turn it of ie with: ``` extern(C) __gshared string[] rt_options = [ "gcopt=parallel:0" ]; ``` Or in various other ways as described in mentioned documentation: https://dlang.org/spec/garbage.html#gc_config
Re: How to converte string to wstring[]?
On Thursday, 6 February 2020 at 21:53:08 UTC, Marcone wrote: How to converte "string" to wstring[] in Dlang? You don't, generally. A string can be converted to a wstring, but a wstring[] is a very different thing. import std.conv; wstring s = to!wstring(some_string); note that works for most types. just string to wstring[] depends on the context.
How to converte string to wstring[]?
How to converte "string" to wstring[] in Dlang?
Re: D create many thread
Is it also possible to set some custom thread name for GC threads in order to be distinguishable from other threads in utilities like `htop`? It would be handy...
Re: Trying to use a template class with ranges
On Thursday, 6 February 2020 at 16:29:57 UTC, Steven Schveighoffer wrote: On 2/6/20 11:05 AM, mark wrote: src/package.d(50,35): Error: no property opCall for type diffrange.Diff!(dchar[]), did you mean new Diff!(dchar[])? Hah, forgot that it's a class. Yes, I DID mean new Diff ;) -Steve Wow, that's all it needed to compile! And I've added the extra check you suggested: auto differ(T)(T a, T b) if ( isForwardRange!T && // T is a range is(typeof(T.init.front == T.init.front)) // Elements support == ) { return new Diff!T(a, b); } Thanks!
Re: Trying to use a template class with ranges
On 2/6/20 11:05 AM, mark wrote: src/package.d(50,35): Error: no property opCall for type diffrange.Diff!(dchar[]), did you mean new Diff!(dchar[])? Hah, forgot that it's a class. Yes, I DID mean new Diff ;) -Steve
Re: Trying to use a template class with ranges
On Thursday, 6 February 2020 at 15:21:46 UTC, Steven Schveighoffer wrote: [snip] 3. You should declare constraints signifying what types are valid. i.e.: class Diff(T) if ( isForwardRange!T // it's a forward range && is(typeof(T.init.front == T.init.front)) // elements are comparable ) Might be good to put this constraint on the factory function too. I don't know how to do that syntactically. I tried the obvious and it wouldn't compile. But even without that it won't compile although it is much closer now! import std.range: ElementType, front, isForwardRange; class Diff(T) if ( isForwardRange!T && // T is a range is(typeof(T.init.front == T.init.front)) // Elements support == ) { alias E = ElementType!T; T a; T b; size_t[][E] b2j; this(T a, T b) { this.a = a; this.b = b; chainB(); } private final void chainB() { foreach (i, element; b) b2j[element] ~= i; // TODO } } auto differ(T)(T a, T b) { return Diff!T(a, b); } unittest { import std.array; import std.stdio: writeln; writeln("unittest for the diffrange library."); auto d1 = differ("one two three four".array, "one too tree four".array); auto a = ["Tulips are yellow,", "Violets are blue,", "Agar is sweet,", "As are you."]; auto b = ["Roses are red,", "Violets are blue,", "Sugar is sweet,", "And so are you."]; auto d2 = differ(a, b); } Here's the error output: Excluding package.d file from test due to https://issues.dlang.org/show_bug.cgi?id=11847 src/package.d(50,35): Error: no property opCall for type diffrange.Diff!(dchar[]), did you mean new Diff!(dchar[])? src/package.d(57,21): Error: template instance diffrange.differ!(dchar[]) error instantiating src/package.d(50,35): Error: no property opCall for type diffrange.Diff!(string[]), did you mean new Diff!(string[])? src/package.d(62,21): Error: template instance diffrange.differ!(string[]) error instantiating /home/mark/opt/bin/ldc2 failed with exit code 1. Curiously the "Excluding package.d file" message isn't true. Not that I mind, I just want to be able to get it going. Thanks! PS The line numbers don't match because I've deleted some structs & enums that are above the class but which aren't used yet.
Re: Object "A" inherited object "B". And you need to return the object link "B".
On 2/6/20 10:11 AM, Steven Schveighoffer wrote b.step(); // virtual call, calls B.step I meant, calls A.step; -Steve
Re: Trying to use a template class with ranges
On 2/6/20 7:16 AM, mark wrote: I am starting on porting Python's difflib's sequence matcher to D. I want to have a class that will accept two ranges whose elements are of the same type and whose elements can be compared for equality. How do I make a class declaration that specifies a (forward) range type and an equality-supporting element type? Here's what doesn't work: class Diff(T, E) { T a; // T should be a forward range of E elements T b; // E elements must support == and != // This is a hash key=E element, value=slice of size_t size_t[][E] b2j; this(T a, T b) { this.a = a; this.b = b; chainB(); } void chainB() { foreach (i, element; b) b2j[element] ~= i; // TODO } } unittest { import std.stdio: writeln; writeln("unittest for the diffrange library."); auto a = ["Tulips are yellow,", "Violets are blue,", "Agar is sweet,", "As are you."]; auto b = ["Roses are red,", "Violets are blue,", "Sugar is sweet,", "And so are you."]; auto diff = Diff(a, b); } 1. If one template parameter depends 100% on the other, it doesn't need to be a parameter. i.e. I would do: class Diff(T) { alias E = ElementType!T; ... } 2. Class constructors do not support IFTI. You have to explicitly instantiate. To use IFTI, you need to create a factory function. i.e. to make the code above work, your ctor call should be Diff!(typeof(a)) (assuming you take the advice in 1). But you can instead write a function to use IFTI: auto makeDiff(T)(T r1, T r2) { return Diff!T(r1, r2); } ... auto diff = makeDiff(a, b); 3. You should declare constraints signifying what types are valid. i.e.: class Diff(T) if ( isForwardRange!T // it's a forward range && is(typeof(T.init.front == T.init.front)) // elements are comparable ) Might be good to put this constraint on the factory function too. Note: is(typeof(...)) basically checks if the thing inside the typeof compiles. -Steve
Re: Object "A" inherited object "B". And you need to return the object link "B".
On 2/6/20 8:05 AM, Mihail Lorenko wrote: On Thursday, 6 February 2020 at 12:37:01 UTC, Adam D. Ruppe wrote: On Thursday, 6 February 2020 at 12:15:17 UTC, Mihail Lorenko wrote: B* b; A pointer to a class is a rare thing in B since they are already automatic references. Just use `B b;` and ten `b = a` will just work. Thanks for the answer! Well, apparently I have to get around my problem. Thanks again! Not sure, but you might misunderstand. B is already a pointer in D (like Java, D's class instances are always references). And derived classes implicitly cast to base classes. So the a.B syntax is not necessary. To illustrate further: A a = new A; // note, instances by default are null, you need to new them B b = a; // implicit cast assert(a is b); // they are the same object b.step(); // virtual call, calls B.step assert(a.a != 0); // note, protected allows access from same module. -Steve
Re: const pointers C vs. D
On Tuesday, 4 February 2020 at 10:17:39 UTC, Dennis wrote: C++ has a const system that is closer to D's than any other language, but it still has huge differences: Thanks, that clears it up a bit!
Re: Trying to use a template class with ranges
I forgot to mention: I want the class to work with: Diff(aForwardRange, bForwardRange) where T = ForwardRange, E = anything that supports == A common use case is for two sequences of strings (i.e., lines read from two files). Diff(aString, bString) where T = char[] or wchar[] or dchar[] E = char or wchar or dchar
Re: Object "A" inherited object "B". And you need to return the object link "B".
On Thursday, 6 February 2020 at 12:37:01 UTC, Adam D. Ruppe wrote: On Thursday, 6 February 2020 at 12:15:17 UTC, Mihail Lorenko wrote: B* b; A pointer to a class is a rare thing in B since they are already automatic references. Just use `B b;` and ten `b = a` will just work. Thanks for the answer! Well, apparently I have to get around my problem. Thanks again!
Re: Object "A" inherited object "B". And you need to return the object link "B".
On Thursday, 6 February 2020 at 12:15:17 UTC, Mihail Lorenko wrote: B* b; A pointer to a class is a rare thing in B since they are already automatic references. Just use `B b;` and ten `b = a` will just work.
Object "A" inherited object "B". And you need to return the object link "B".
Hello! Interested in a question. Object "A" inherited object "B". And you need to return the object link "B". Is this possible in this language? Here is an example: class B { protected int a; public void step() {}; } class A : B { public override step() { import std.random; a = uniform(5,100); } } void main() { B* b; A a; a.step(); b = a.B; // @FixMe: Here you need a link to object B from object A. } Sorry to trouble you, thanks in advance!
Trying to use a template class with ranges
I am starting on porting Python's difflib's sequence matcher to D. I want to have a class that will accept two ranges whose elements are of the same type and whose elements can be compared for equality. How do I make a class declaration that specifies a (forward) range type and an equality-supporting element type? Here's what doesn't work: class Diff(T, E) { T a; // T should be a forward range of E elements T b; // E elements must support == and != // This is a hash key=E element, value=slice of size_t size_t[][E] b2j; this(T a, T b) { this.a = a; this.b = b; chainB(); } void chainB() { foreach (i, element; b) b2j[element] ~= i; // TODO } } unittest { import std.stdio: writeln; writeln("unittest for the diffrange library."); auto a = ["Tulips are yellow,", "Violets are blue,", "Agar is sweet,", "As are you."]; auto b = ["Roses are red,", "Violets are blue,", "Sugar is sweet,", "And so are you."]; auto diff = Diff(a, b); }
Detecting unneeded imports in CI
Hello folks, Are there any well-established CI patterns/tools for detecting unneeded imports in D code? Ideally including detecting unused symbols from selective imports? Thanks and best wishes, -- Joe
Re: Dub - vibe.d - hunt framework ... problems
On Saturday, 1 February 2020 at 10:35:52 UTC, seany wrote: Hi I want to start a small server, that will be accessible form outside. Not a huge deal right? Not quite. My machine: 4.15.0-66-generic #75-Ubuntu SMP Tue Oct 1 05:24:09 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux DMD : DMD64 D Compiler v2.090.0 Copyright (C) 1999-2019 by The D Language Foundation, All Rights Reserved written by Walter Bright How much memory does this machine have? Is it a virtual machine provided by a hosting company? My suspicion is that your server is very slow for some peculiar reason.
Re: Dub - vibe.d - hunt framework ... problems
On Saturday, 1 February 2020 at 10:35:52 UTC, seany wrote: Hi I want to start a small server, that will be accessible form outside. Not a huge deal right? Not quite. My machine: 4.15.0-66-generic #75-Ubuntu SMP Tue Oct 1 05:24:09 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux DMD : DMD64 D Compiler v2.090.0 Copyright (C) 1999-2019 by The D Language Foundation, All Rights Reserved written by Walter Bright Now, I try to install dub from the official repo. Then I do * dub init server -t vibe.d * cd server * dub I hit this issue : https://github.com/dlang/dub/issues/1712 As suggested, i try to build dub from github, following: https://github.com/dlang/dub/releases I call ./build.d - and everything stops, and machine crashes. I then try to install DaNode: https://github.com/DannyArends/DaNode It breaks with : module std.algorithm import 'mean' not found Then I try to install the Hunt Framework. It breaks with : basic type expected, not foreach Please help. I really want this issue to be resolved- ## 1. For simple server you can using hunt-http library. Sample code: ``` import hunt.http; void main() { HttpServer server = HttpServer.builder() .setListener(8080, "0.0.0.0") .onPost("/", (RoutingContext context) { context.end("Hello World!"); }) .onGet("/user/:name", (RoutingContext ctx) { string name = ctx.getRouterParameter("name"); ctx.write("Hello " ~ name); ctx.end(); }) .build(); server.start(); } ``` ## 2. For full server, you can using hunt-skeleton (hunt-framework based): ```bash git clone https://github.com/huntlabs/hunt-skeleton.git myproject/ cd myproject/ dub run -v ``` You can Add pages in `config/routes` , like this: ``` GET / index.index GET /user/{name}user.detail ``` Add Controller file `controller/UserController.d` : ``` module app.controller.UserController; import hunt.framework; class UserController : Controller { mixin MakeController; @Action string detail(string name) { return "Hello " ~ name; } } ``` Build and run it: ``` cd myproject/ dub run -v ``` You can see it in the borwser: ``` http://localhost:8080 ```