rpc between Tasks of vibe.d
Hi All! I will try to illustrate by code what exactly I have in mind: // we have not shared class/struct with some interface. class FooController { ... int foo1(int a, string b); string foo2(Struct1 c); ... } // now we want to make a running task with an instance inside auto controllerTask = runTask((){ auto controller = new FooController(); ReceiveCalls!FooController(controller); }); // and call it from other tasks, like this int result1 = Call!FooController(controllerTask).foo1(123, "abc"); string result2 = Call!FooController(controllerTask).foo2(Struct1(...)); Is there any interface generator for this? Or what can you suggest? Thanks!
[Issue 16645] 3 errors messages instead of 1 after CTFE divide by 0
https://issues.dlang.org/show_bug.cgi?id=16645 b2.t...@gmx.com changed: What|Removed |Added Keywords||CTFE --
[Issue 16645] New: 3 errors messages instead of 1 after CTFE divide by 0
https://issues.dlang.org/show_bug.cgi?id=16645 Issue ID: 16645 Summary: 3 errors messages instead of 1 after CTFE divide by 0 Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: minor Priority: P1 Component: dmd Assignee: nob...@puremagic.com Reporter: b2.t...@gmx.com echo "enum a = 0/0;" > d.d && dmd d.d -main prints: > d.d(1): Error: divide by 0 > d.d(1): Error: divide by 0 > d.d(1): Error: divide by 0 --
Re: Mir GLAS is a C library and passes Natlib's test suite! And questions :-)
On Friday, 28 October 2016 at 16:14:56 UTC, Sameer Pradhan wrote: I must plead ignorance on the finer interface details, but from what I am reading this seems like an amazing development. I am so happy that that D has a solid base for GPU work. The post from a few weeks back with performance details compared to BLAS and others was quite impressive. details I was just telling Steve at the Boston meetup yesterday that libmir and now MirGLAS has really made me jump up and down to start using D seriously for some language processing work I have been hoping to use it for. I have been an observer and reader for several years now, but haven't taken the leap. Yet. Hopefully soon... -- Sameer For GPUs there is dcompute (also on libmir's github) on the way, although it'll be probably another month (exams, joy!) before the compiler stuff gets fully merged into LDC and we can start on an API that forwards to OpenCL/CUDA, and doesn't suck to use. If you have any experience with either OpenCL or CUDA we'd love to have your input.
[Issue 16644] New: final switch on int should error unless VRP matches all cases
https://issues.dlang.org/show_bug.cgi?id=16644 Issue ID: 16644 Summary: final switch on int should error unless VRP matches all cases Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nob...@puremagic.com Reporter: c...@dawg.eu To determine whether all cases are handled, we could use value range propagation. OK final switch (i % 2) { case 0: case 1: } ERROR final switch (i % 3) { case 0: case 1: } In cases where we don't know the range, it should be an error. --
Re: D garbage collector and real-time systems
On Wednesday, 28 January 2015 at 07:43:35 UTC, ketmar wrote: On Wed, 28 Jan 2015 06:58:41 +, Tom wrote: Or is there now the possibility of disabling the GC altogether, or replacing it with a refcounting 'GC' etc? you still can do manual memory management with `malloc()` and friends. but you must be very cautious with dynamic arrays and slices. may be your best bet is to not use built-in dynamic arrays at all and write a replacement class with manual memory management. ah, and the same for AAs. it's possible, if somewhat cumbersome. and you can use 'dmd -vgc' to check for hidden allocations. so it may be not as simple as adding some compiler switch, but still not that hard too. For manually managed arrays, containers, I would recommend the emsicontainers (https://github.com/economicmodeling/containers)
Re: Is there Typeof template ?
On Friday, 28 October 2016 at 18:39:36 UTC, Ali Çehreli wrote: On 10/28/2016 11:25 AM, Jonathan M Davis via Digitalmars-d-learn wrote: >> void main() { >> @(`str`, 123) uint k; >> foreach (a; __traits(getAttributes, k)) { >> pragma(msg, typeof(a)); >> } >> } > I don't know if Typeof is actually needed for what the OP is trying to do, > but if you wanted to apply typeof using something like std.meta.staticMap, > then you'd need something like Typeof. I see. Just to add something that I've just remembered, it is possible to apply typeof to __traits(getAttributes) as well: foreach (T; typeof(__traits(getAttributes, k))) { pragma(msg, T); } Now we get a list of types: string int Ali I wanna use it with staticMap.
Re: Binding temporaries to ref [WAS: I close BIP27. I won't be pursuing BIPs anymore]
On Friday, 21 October 2016 at 07:56:40 UTC, Ethan Watson wrote: On Thursday, 20 October 2016 at 19:49:42 UTC, Andrei Alexandrescu wrote: I think a solid DIP addressing the problem would have a good chance to get traction. I think all the information in this thread and the "Binding rvalues to const ref in D" thread that Atilla started is enough for me to write up a solid DIP. I'll start doing that. Hopefully I'll get a draft up that I'll pass to Manu for comment/input this weekend before posting it properly. Any news on this?
[Issue 16643] CTFE internal error with null
https://issues.dlang.org/show_bug.cgi?id=16643 ag0ae...@gmail.com changed: What|Removed |Added Keywords||ice CC||ag0ae...@gmail.com --
Re: Is there Typeof template ?
On 10/28/2016 11:25 AM, Jonathan M Davis via Digitalmars-d-learn wrote: >> void main() { >> @(`str`, 123) uint k; >> foreach (a; __traits(getAttributes, k)) { >> pragma(msg, typeof(a)); >> } >> } > I don't know if Typeof is actually needed for what the OP is trying to do, > but if you wanted to apply typeof using something like std.meta.staticMap, > then you'd need something like Typeof. I see. Just to add something that I've just remembered, it is possible to apply typeof to __traits(getAttributes) as well: foreach (T; typeof(__traits(getAttributes, k))) { pragma(msg, T); } Now we get a list of types: string int Ali
Re: Is there Typeof template ?
On Friday, October 28, 2016 11:19:46 Ali Çehreli via Digitalmars-d-learn wrote: > On 10/28/2016 05:48 AM, Temtaime wrote: > > On Friday, 28 October 2016 at 12:44:20 UTC, Adam D. Ruppe wrote: > >> On Friday, 28 October 2016 at 10:52:05 UTC, Temtaime wrote: > >>> Are there something or should I create a PR to phobos? > >> > >> Why would you want that? > > > > I have UDAs with values à la @(`str`, 123) uint k; > > > > And i want to know a type of a value. > > How are you using those? typeof works with any value: > > void main() { > @(`str`, 123) uint k; > foreach (a; __traits(getAttributes, k)) { > pragma(msg, typeof(a)); > } > } > > Prints > > string > int > > You can use indexes with the loop as well: > > foreach (i, a; /* ... */ I don't know if Typeof is actually needed for what the OP is trying to do, but if you wanted to apply typeof using something like std.meta.staticMap, then you'd need something like Typeof. - Jonathan M Davis
Re: Fun: Shooting yourself in the foot in D
On 10/28/2016 04:41 AM, John Colvin wrote: > a bullet that's paused by the GC Wow. I've just said almost the same thing before reading this one. :) Ali
Re: Fun: Shooting yourself in the foot in D
On 10/28/2016 04:32 AM, Guillaume Piolat wrote: > When you try shooting at your foot with your AK-47, you realize the GC > has blown it already. Or... the bullet stops midair, waiting for the GC to finish a collection cycle (probably for a lollipop created in another thread). Ali
Re: Is there Typeof template ?
On 10/28/2016 05:48 AM, Temtaime wrote: On Friday, 28 October 2016 at 12:44:20 UTC, Adam D. Ruppe wrote: On Friday, 28 October 2016 at 10:52:05 UTC, Temtaime wrote: Are there something or should I create a PR to phobos? Why would you want that? I have UDAs with values à la @(`str`, 123) uint k; And i want to know a type of a value. How are you using those? typeof works with any value: void main() { @(`str`, 123) uint k; foreach (a; __traits(getAttributes, k)) { pragma(msg, typeof(a)); } } Prints string int You can use indexes with the loop as well: foreach (i, a; /* ... */ Ali
Re: CTFE divide by 0 prints the same error 3 times !
On 10/28/2016 07:37 AM, Basile B. wrote: try this echo "enum a = 0/0;" > d.d && dmd d.d -main any reason for this ? One is too easy to miss, two is better, but three is just right. :o) Must be an implementation oddity. Please file a bug. Ali
Re: A question of function design?
On Friday, 28 October 2016 at 14:12:53 UTC, Mike Parker wrote: On Friday, 28 October 2016 at 13:19:19 UTC, WhatMeWorry wrote: [...] I generally use GLFW event callbacks to populate an event queue with custom event types, then process the queue and handle events elsewhere. That way, the callbacks need no nothing at all about the game code. [...] Thanks! I'll study this code. I guess APIs can only give you so much.
Re: Battle-plan for CTFE
Another update on CTFE. I have found a few errors in my handling of switch-statments. An efficient solution for this is still pending, Futhermore I have begun to work on ctfe handling refernces. These are a little bit harder to do in bytecode and do pessimise performance if overused. I hope to make another leap at the end of this month. We should have string Concat-support fairly soon. Cheers, stefan
DLang Youtube channel
There isn't a official D youtube channel right? Would be be nice to have all the D related videos spread on youtube centralized in one place :)
Re: Mir GLAS is a C library and passes Natlib's test suite! And questions :-)
On Friday, 28 October 2016 at 06:31:19 UTC, Ilya Yaroshenko wrote: On Friday, 28 October 2016 at 03:44:05 UTC, Andrei Alexandrescu wrote: On 10/27/16 3:59 AM, Ilya Yaroshenko wrote: [...] I must plead ignorance on the finer interface details, but from what I am reading this seems like an amazing development. I am so happy that that D has a solid base for GPU work. The post from a few weeks back with performance details compared to BLAS and others was quite impressive. details I was just telling Steve at the Boston meetup yesterday that libmir and now MirGLAS has really made me jump up and down to start using D seriously for some language processing work I have been hoping to use it for. I have been an observer and reader for several years now, but haven't taken the leap. Yet. Hopefully soon... -- Sameer [...] Cool work! One thing I'd want to understand is how to use Mir GLAS from within D itself. If it's a straight C interface, there seems to be a fair amount of friction (we have a D program communicating with a D library through the uncomfortable confines of a C interface). Is that the case? Should there be a way to short circuit the C API and use a more expressive D interface? (Looking e.g. at Eigen, it's meant to allow people using it from C++ to take advantage of a C++-specific smooth interface.) GLAS has 2 APIs: GLAS(ndslise) and BLAS(fortran). Both APIs has C/C++ and D headers. D headers contains aliases with unified names like in core.stdc.tgmath. So, extern(C) interface for GLAS is comfortable and looks like: gemm(alpha, a, b, beta, c); // calls glas_?gemm The latest ndslice PR to stable branch solves a problem in case of const and immutable a and b. https://github.com/dlang/phobos/pull/4873 GLAS does not have syntax like Eigen, i mean c = a * b; This syntax can be a part of another package for scripting like syntax. See also Q https://github.com/libmir/mir-glas#why-glas-does-not-have-lazy-evaluation-and-aliasing-like-eigen [...] I guess I'd like to understand the dynamics better here. The main reason is compilation time (1 secs+) and template bloat (50 KB +). OpenBLAS size is more than 20 MB. GLAS is smaller, but it is not something lightweight like `sort`. Assume you are buildings a large D projects one-by-one file in parallel. It can be builded during minutes and its size can be >100 MB, only because GLAS. So, having an extern(C) layers is good practice to keep interface clear and compile time small. [...] You have all support from Walter and myself for integrating GLAS with Phobos. Before that I'd want to make sure we slice and dice things properly. Awesome! I am happy to read this) [...] That would be an interesting precedent. We should talk about it next week. (My knee-jerk reaction is if we're worth our salt we should release Phobos often enough to obviate the need for this. But the notion of hot-swapping subcomponents is cool too.) Some concepts can be found on a slides from my today's talk https://docs.google.com/presentation/d/1w1cQ8vDluglRIt8Qdnm-sY7kqxoKZxbPEWW6tR3lPpo/edit?usp=sharing Thanks, Andrei Best regards, Ilya
Re: Pattern matching in D?
Someone may be, it will be interesting, in the C# 7 `switch` will be extended syntax for pattern matching: https://github.com/dotnet/roslyn/blob/features/patterns/docs/features/patterns.md Original post: https://github.com/dotnet/roslyn/issues/206
Re: Best approach to handle accented letters
On Friday, 28 October 2016 at 15:08:59 UTC, Chris wrote: On Friday, 28 October 2016 at 14:31:47 UTC, Chris wrote: [...] What you basically do is you pass the logic on to `map` and `map` applies it to each item in the range (cf. [1]): [...] The life is beautiful ! Thx.
Re: Is there a D static site generator based on markdown (like couscous) ?
On Friday, 28 October 2016 at 13:37:55 UTC, Basile B. wrote: I would need actually something like https://github.com/CouscousPHP/Couscous but in D. You can easily make a custom SSG with https://github.com/kiith-sa/dmarkdown
Re: Best approach to handle accented letters
On Friday, 28 October 2016 at 14:31:47 UTC, Chris wrote: On Friday, 28 October 2016 at 13:50:24 UTC, Alfred Newman wrote: It boils down to something like: if (c in _accent) return _accent[c]; else return c; Just a normal lambda (condition true) ? yes : no; I'd recommend you to use Marc's approach, though. What you basically do is you pass the logic on to `map` and `map` applies it to each item in the range (cf. [1]): map!(myLogic)(range); or (more idiomatic) range.map!(myLogic); This is true of a lot of functions, or rather templates, in the Phobos standard library, especially functions in std.algorithm (like find [2], canFind, filter etc.). In this way, instead of writing for-loops with if-else statements, you pass the logic to be applied within the `!()`-part of the template. // Filter the letter 'l' auto result = "Hello, world!".filter!(a => a != 'l'); // returns "Heo, word!" However, what is returned is not a string. So this won't work: `writeln("Result is " ~ result);` // Error: incompatible types for (("Result is ") ~ (result)): 'string' and // 'FilterResult!(__lambda2, string)' It returns a `FilterResult`. To fix this, you can either write: ` import std.conv; auto result = "Hello, world!".filter!(a => a != 'l').to!string; ` which converts it into a string. or you do this: ` import std.array; auto result = "Hello, world!".filter!(a => a != 'l').array; ` Then you have a string again and ` writeln("Result is " ~ result); ` works. Just bear that in mind, because you will get the above error sometimes. Marc's example is idiomatic D and you should become familiar with it asap. void main() { auto str = "très élégant"; immutable accents = unicode.Diacritic; auto removed = str // normalize each character .normalize!NFD // replace each diacritic with its non-diacritic counterpart .filter!(c => !accents[c]) // convert each item in FilterResult back to string. .to!string; writeln(removed); // prints "tres elegant" } [1] http://dlang.org/phobos/std_algorithm_iteration.html#.map [1] http://dlang.org/phobos/std_algorithm_searching.html#.find
Re: Avoiding GC
On Friday, 28 October 2016 at 11:50:20 UTC, hardreset wrote: On Thursday, 27 October 2016 at 07:52:09 UTC, Guillaume Piolat wrote: On Wednesday, 26 October 2016 at 08:18:07 UTC, hardreset wrote: Is there a page somewhere on how to program D without using the GC? The information is scattered. How do I allocate / free structs / classes on the heap manually? Classes => https://github.com/AuburnSounds/dplug/blob/master/core/dplug/core/nogc.d#L122 Thanks. I notice you avoid GC altogether in dplug. Whats the reason for total avoidance as apposed to just avoiding it in the real time code? Not a lot of reason. It's very recent work, I'm still struggling making threadpool works. - Reason #1 was that it gives a way to unload shared libraries on OSX. This bug has been fixed in LDC but would require to make druntime and phobos a shared library to ship. That makes releases 3x larger so I went with disabling the runtime instead (one month of work and still going...). - Reason #2 is that GC does use more memory. Next release of our products use 2x fewer memory. All in all it's _painful_ not to use the D runtime, suddenly you can't use third-party code, and there is no performance enhancement to expect apart from reduced memory usage. Don't avoid the runtime on principles alone.
[Issue 16643] New: CTFE internal error with null
https://issues.dlang.org/show_bug.cgi?id=16643 Issue ID: 16643 Summary: CTFE internal error with null Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: minor Priority: P1 Component: dmd Assignee: nob...@puremagic.com Reporter: b2.t...@gmx.com null+null and null-null trigger the error: echo "enum a = null+null;" > d.d && dmd d.d -main echo "enum a = null-null;" > d.d && dmd d.d -main > Error: CTFE internal error: non-constant value null --
CTFE divide by 0 prints the same error 3 times !
try this echo "enum a = 0/0;" > d.d && dmd d.d -main any reason for this ?
Re: Best approach to handle accented letters
On Friday, 28 October 2016 at 13:50:24 UTC, Alfred Newman wrote: On Friday, 28 October 2016 at 11:40:37 UTC, Chris wrote: [...] @Chris As a new guy in the D community, I am not sure, but I think the line below is something like a Python's lambda, right ? auto removed = to!string(str.map!(a => (a in _accent) ? _accent[a] : a)); Can you please rewrite the line in a more didatic way ? Sorry, but I'm still learning the basics. Thanks in advance It boils down to something like: if (c in _accent) return _accent[c]; else return c; Just a normal lambda (condition true) ? yes : no; I'd recommend you to use Marc's approach, though.
Re: The DLang UPB Languages and Systems Research Scholarship
On Friday, 28 October 2016 at 13:57:37 UTC, Mike Parker wrote: How is a scholarship for CS degrees off topic? OK, nevermind. Been a while since I looked at the sidebar. "If there is no code in your link, it probably doesn't belong here."
Re: A question of function design?
On Friday, 28 October 2016 at 13:19:19 UTC, WhatMeWorry wrote: Anyone have a good example of what I should be doing? I generally use GLFW event callbacks to populate an event queue with custom event types, then process the queue and handle events elsewhere. That way, the callbacks need no nothing at all about the game code. ``` void setCallbacks() { glfwSetKeyCallback(_callback); } private: MyEventQueue _eventq; extern(C) void key_callback(GLFWwindow* window, int key, int scancode, int action, int modifier) { eventq.push(KeyEvent(window, key, scancode, action, modifier); } An alternative approach is to forego the event queue and just have the callbacks process event listeners. The listeners could be delegates, function pointers, or interfaces, whatever works for your scenario, or some specific event handler class. They might be stored in flat arrays, or aas keyed on the window or a KeyEvent structure. Whatever works. ``` alias KeyHandler = bool delegate(GLFWwindow, int, int, int, int); void registerKeyHandler(KeyHandler handler) { _keyHandlers ~= handler; } private: KeyHandler[] _keyHandlers; extern(C) void key_callback(GLFWwindow* window, int key, int scancode, int action, int modifier) { foreach(handler; _keyHandlers) { if(_keyHandler(window, key, scancode, action, modifier)) break; } } ```
Re: The DLang UPB Languages and Systems Research Scholarship
On Friday, 28 October 2016 at 10:43:36 UTC, thedeemon wrote: On Wednesday, 26 October 2016 at 01:11:05 UTC, Mike Parker wrote: For anyone tempted to share this on /r/programming, please wait! I hope to do a blog post about this on Friday, so I'll post to reddit then. Thanks! Please don't. This is a total offtopic for /r/programming, don't create the reputation "dlang seeks for attention and spams with irrelevant stuff". How is a scholarship for CS degrees off topic?
Re: Best approach to handle accented letters
On Friday, 28 October 2016 at 11:40:37 UTC, Chris wrote: On Friday, 28 October 2016 at 11:24:28 UTC, Alfred Newman wrote: Hello, I'm getting some troubles to replace the accented letters in a given string with their unaccented counterparts. Let's say I have the following input string "très élégant" and I need to create a function to return just "tres elegant". Considering we need to take care about unicode chars, what is the best way to write a D code to handle that ? Cheers You could try something like this. It works for accents. I haven't tested it on other characters yet. import std.stdio; import std.algorithm; import std.array; import std.conv; enum { dchar[dchar] _accent = ['á':'a', 'é':'e', 'è':'e', 'í':'i', 'ó':'o', 'ú':'u', 'Á':'A', 'É':'E', 'Í':'I', 'Ó':'O', 'Ú':'U'] } void main() { auto str = "très élégant"; auto removed = to!string(str.map!(a => (a in _accent) ? _accent[a] : a)); writeln(removed); // prints "tres elegant" } @Chris As a new guy in the D community, I am not sure, but I think the line below is something like a Python's lambda, right ? auto removed = to!string(str.map!(a => (a in _accent) ? _accent[a] : a)); Can you please rewrite the line in a more didatic way ? Sorry, but I'm still learning the basics. Thanks in advance
Is there a D static site generator based on markdown (like couscous) ?
I would need actually something like https://github.com/CouscousPHP/Couscous but in D.
Re: Fun: Shooting yourself in the foot in D
On Friday, 28 October 2016 at 11:41:11 UTC, John Colvin wrote: You unregister your feet from the runtime in order to move smoothly, wander in front of a bullet that's paused by the GC, which then un-pauses and hits you in the foot. This is the best one so far! This is typical D: circumvent safety to enable you to shoot yourself in the foot.
Re: A question of function design?
On Thursday, 27 October 2016 at 22:51:13 UTC, pineapple wrote: On Thursday, 27 October 2016 at 22:17:35 UTC, WhatMeWorry wrote: I'm using Derelict GLFW3 and I found the following GLFW3 code snippet in a demo. In a small demo, crap like this usually isn't a big deal. It's not common practice, though, and for good reason. You should definitely avoid imitating it. Anyone have a good example of what I should be doing?
Re: Best approach to handle accented letters
On Friday, 28 October 2016 at 12:52:04 UTC, Marc Schütz wrote: On Friday, 28 October 2016 at 11:24:28 UTC, Alfred Newman wrote: [...] import std.stdio; import std.algorithm; import std.uni; import std.conv; void main() { auto str = "très élégant"; immutable accents = unicode.Diacritic; auto removed = str .normalize!NFD .filter!(c => !accents[c]) .to!string; writeln(removed); // prints "tres elegant" } This first decomposes all characters into base and diacritic, and then removes the latter. Cool. That looks pretty neat and it should cover all cases.
[Issue 15604] [REG2.070] std.array.array of structs with template opAssign and default initialised 'new'ed class member
https://issues.dlang.org/show_bug.cgi?id=15604 Martin Krejcirikchanged: What|Removed |Added Summary|std.array.array of structs |[REG2.070] std.array.array |with template opAssign and |of structs with template |default initialised 'new'ed |opAssign and default |class member|initialised 'new'ed class ||member --
Re: Is there Typeof template ?
On Friday, October 28, 2016 10:52:05 Temtaime via Digitalmars-d-learn wrote: > Hi ! > Tried to find > alias Typeof(alias A) = typeof(A); > or something, but failed. > > Are there something or should I create a PR to phobos? > Thanks If it were in Phobos, I'd expect it to be in std.meta, and it's not there. - Jonathan M Davis
Re: Best approach to handle accented letters
On Friday, 28 October 2016 at 11:24:28 UTC, Alfred Newman wrote: Hello, I'm getting some troubles to replace the accented letters in a given string with their unaccented counterparts. Let's say I have the following input string "très élégant" and I need to create a function to return just "tres elegant". Considering we need to take care about unicode chars, what is the best way to write a D code to handle that ? Cheers import std.stdio; import std.algorithm; import std.uni; import std.conv; void main() { auto str = "très élégant"; immutable accents = unicode.Diacritic; auto removed = str .normalize!NFD .filter!(c => !accents[c]) .to!string; writeln(removed); // prints "tres elegant" } This first decomposes all characters into base and diacritic, and then removes the latter.
Re: Is there Typeof template ?
On Friday, 28 October 2016 at 12:44:20 UTC, Adam D. Ruppe wrote: On Friday, 28 October 2016 at 10:52:05 UTC, Temtaime wrote: Are there something or should I create a PR to phobos? Why would you want that? I have UDAs with values à la @(`str`, 123) uint k; And i want to know a type of a value.
Re: Is TDPL an accurate description of the D language today?
On 29/10/2016 1:35 AM, Mark wrote: On Tuesday, 27 September 2016 at 17:53:39 UTC, Steven Schveighoffer wrote: On 9/27/16 1:38 PM, Mark wrote: I've been going through Andrei's excellent book and I noticed that the latest printing is from 2010. Since D is still a very young language I can imagine it changing quite a bit within six years. So I wonder if there are any major inconsistincies between the current state of the language and its description in TDPL. Is there a list somewhere with all the changes made in the langauge since the book was published? Thanks a lot. Most things that are "wrong" in the book should be in the errata: http://erdani.com/tdpl/errata/ There are also some things that are not wrong in the book, but have not been implemented. I think the most glaring difference is that "clear" has been renamed to "destroy". -Steve Another thing that I found today is that the book suggests nested structs within functions are of little use. I guess Voldemort types were introduced into the language after the book was published. Should this be on the errata page? It's not exactly an error. Ranges were the 'big' idiom that changed this. Otherwise they are indeed of little use. I think it shouldn't be included, but since you feel otherwise, email Andrei and let him know, no harm either way :)
Re: Is there Typeof template ?
On Friday, 28 October 2016 at 10:52:05 UTC, Temtaime wrote: Are there something or should I create a PR to phobos? Why would you want that?
Re: Is TDPL an accurate description of the D language today?
On Tuesday, 27 September 2016 at 17:53:39 UTC, Steven Schveighoffer wrote: On 9/27/16 1:38 PM, Mark wrote: I've been going through Andrei's excellent book and I noticed that the latest printing is from 2010. Since D is still a very young language I can imagine it changing quite a bit within six years. So I wonder if there are any major inconsistincies between the current state of the language and its description in TDPL. Is there a list somewhere with all the changes made in the langauge since the book was published? Thanks a lot. Most things that are "wrong" in the book should be in the errata: http://erdani.com/tdpl/errata/ There are also some things that are not wrong in the book, but have not been implemented. I think the most glaring difference is that "clear" has been renamed to "destroy". -Steve Another thing that I found today is that the book suggests nested structs within functions are of little use. I guess Voldemort types were introduced into the language after the book was published. Should this be on the errata page? It's not exactly an error.
Re: Avoiding GC
On Thursday, 27 October 2016 at 07:52:09 UTC, Guillaume Piolat wrote: On Wednesday, 26 October 2016 at 08:18:07 UTC, hardreset wrote: Is there a page somewhere on how to program D without using the GC? The information is scattered. How do I allocate / free structs / classes on the heap manually? Classes => https://github.com/AuburnSounds/dplug/blob/master/core/dplug/core/nogc.d#L122 Thanks. I notice you avoid GC altogether in dplug. Whats the reason for total avoidance as apposed to just avoiding it in the real time code?
Re: Pattern matching in D?
On Monday, 24 October 2016 at 04:14:52 UTC, Nick Sabalausky wrote: It's just...I mean, yea, it works, and you could probably DRY it up a little with a type contructing template ("alias RgbColor = DoMagic!RgbColor_"), but...meh... I think the following should be better. Instead of Proxy we would have a bespoke mixin which might fix some of the workarounds below. In the unittest, using with(Color) should help, but I couldn't get that to compile (visit thinks invalid lambdas are being passed). import std.variant; struct Color { struct Custom { float red; float green; float blue; } //mixin NewTypes!`Red, Yellow, Green`; struct Red {} struct Yellow {} struct Green {} private auto impl = Algebraic!( Custom, Red, Yellow, Green)(); import std.typecons; mixin Proxy!impl; } unittest{ Color color; // assignment works but not ctor color = Color.Custom(1, 2, 3); assert(color.type == typeid(Color.Custom)); // FIXME: currently need impl auto x = color.impl.visit!( (Color.Red) => "red", (Color.Yellow) => "yellow", (Color.Green) => "green", (Color.Custom c) => ctFormat!`rgb(%s, %s, %s)`(c.red, c.green, c.blue) ); assert(x == "rgb(1, 2, 3)"); } // TODO: implement ct parsing auto ctFormat(string s, Args...)(Args args){ import std.format; return format(s, args); }
Re: Default struct member initializer ?
On Friday, 28 October 2016 at 11:37:52 UTC, Temtaime wrote: But what about the case when default ctor is disabled ? Only relevant if you've written something like `@disable static S init();`, which you shouldn't be doing anyway. `.init` is independent of `@disable this()`
Re: Fun: Shooting yourself in the foot in D
On Thursday, 27 October 2016 at 19:49:16 UTC, Ali Çehreli wrote: http://www.toodarkpark.org/computers/humor/shoot-self-in-foot.html Some entries for reference: C - You shoot yourself in the foot. - You shoot yourself in the foot and then nobody else can figure out what you did. C++ - You accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there." Python - You shoot yourself in the foot and then brag for hours about how much more elegantly you did it than if you had been using C or (God forbid) Perl. What would the entry for D be? :) Ali You unregister your feet from the runtime in order to move smoothly, wander in front of a bullet that's paused by the GC, which then un-pauses and hits you in the foot.
Re: Best approach to handle accented letters
On Friday, 28 October 2016 at 11:24:28 UTC, Alfred Newman wrote: Hello, I'm getting some troubles to replace the accented letters in a given string with their unaccented counterparts. Let's say I have the following input string "très élégant" and I need to create a function to return just "tres elegant". Considering we need to take care about unicode chars, what is the best way to write a D code to handle that ? Cheers You could try something like this. It works for accents. I haven't tested it on other characters yet. import std.stdio; import std.algorithm; import std.array; import std.conv; enum { dchar[dchar] _accent = ['á':'a', 'é':'e', 'è':'e', 'í':'i', 'ó':'o', 'ú':'u', 'Á':'A', 'É':'E', 'Í':'I', 'Ó':'O', 'Ú':'U'] } void main() { auto str = "très élégant"; auto removed = to!string(str.map!(a => (a in _accent) ? _accent[a] : a)); writeln(removed); // prints "tres elegant" }
Re: Default struct member initializer ?
But what about the case when default ctor is disabled ?
Re: Default struct member initializer ?
On Friday, 28 October 2016 at 11:23:47 UTC, John Colvin wrote: On Friday, 28 October 2016 at 11:20:50 UTC, Temtaime wrote: Hi ! Is there such a magic ? struct S { uint k = 2; } enum Value = Foo!(S.k); // Value == 2 Thanks. struct S { int k = 2; } enum Value = S.init.k; static assert (Value == 2); Oh i see, thanks
Re: Fun: Shooting yourself in the foot in D
On Thursday, 27 October 2016 at 19:49:16 UTC, Ali Çehreli wrote: http://www.toodarkpark.org/computers/humor/shoot-self-in-foot.html Some entries for reference: C - You shoot yourself in the foot. - You shoot yourself in the foot and then nobody else can figure out what you did. C++ - You accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there." Python - You shoot yourself in the foot and then brag for hours about how much more elegantly you did it than if you had been using C or (God forbid) Perl. What would the entry for D be? :) Ali When you try shooting at your foot with your AK-47, you realize the GC has blown it already.
Re: Default struct member initializer ?
On Friday, 28 October 2016 at 11:20:50 UTC, Temtaime wrote: Hi ! Is there such a magic ? struct S { uint k = 2; } enum Value = Foo!(S.k); // Value == 2 Thanks. struct S { int k = 2; } enum Value = S.init.k; static assert (Value == 2);
Default struct member initializer ?
Hi ! Is there such a magic ? struct S { uint k = 2; } enum Value = Foo!(S.k); // Value == 2 Thanks.
Best approach to handle accented letters
Hello, I'm getting some troubles to replace the accented letters in a given string with their unaccented counterparts. Let's say I have the following input string "très élégant" and I need to create a function to return just "tres elegant". Considering we need to take care about unicode chars, what is the best way to write a D code to handle that ? Cheers
Re: The DLang UPB Languages and Systems Research Scholarship
On Tuesday, 25 October 2016 at 22:15:38 UTC, Andrei Alexandrescu wrote: The D Language Foundation is proud to announce its first scholarship, offered to CS and EE students at University "Politehnica" Bucharest in Romania. More details here: http://dlang.org/dlangupb-scholarship.html We are very excited about this program and hope to extend it to other universities in the future. Thanks, Andrei A project D > WebAssembley would be great.
Is there Typeof template ?
Hi ! Tried to find alias Typeof(alias A) = typeof(A); or something, but failed. Are there something or should I create a PR to phobos? Thanks
Re: The DLang UPB Languages and Systems Research Scholarship
On Wednesday, 26 October 2016 at 01:11:05 UTC, Mike Parker wrote: For anyone tempted to share this on /r/programming, please wait! I hope to do a blog post about this on Friday, so I'll post to reddit then. Thanks! Please don't. This is a total offtopic for /r/programming, don't create the reputation "dlang seeks for attention and spams with irrelevant stuff".
Re: Fun: Shooting yourself in the foot in D
On Friday, 28 October 2016 at 09:55:34 UTC, Patric Dexheimer wrote: On Friday, 28 October 2016 at 09:29:41 UTC, Chris wrote: On Friday, 28 October 2016 at 01:25:55 UTC, Kirill Kryukov wrote: You shoot yourself in a tuple containing your foot, boot and sock. Cannot implicitly convert expression (map(shoot(foot))) of type MapResult to std.ouch.InputRange!limb You create the bullet in your foot for efficiency (CTFE). You shoot yourself in the foot, but it doesn't matter, it was allocated on the stack.
dub build --force but only for this package
So I'm trying to debug a project with the work flow of ssh into remote box edit/compile/run if it hangs yank the power out repeat this appears to corrupt the the last modification time to some time in the future and leads to the warning File '../.dub/packages/vibe-d-0.7.29/vibe-d/libvibe-d_diet.a' was modified in the future. Please re-save. repeated a bunch. this also affect the files in my project, and dub is refusing to do a non --force'd build. Is there a way to force dub to rebuild the current package, but not its dependencies, to reduce the time to compile?
Re: Fun: Shooting yourself in the foot in D
On Friday, 28 October 2016 at 09:29:41 UTC, Chris wrote: On Friday, 28 October 2016 at 01:25:55 UTC, Kirill Kryukov wrote: You shoot yourself in a tuple containing your foot, boot and sock. Cannot implicitly convert expression (map(shoot(foot))) of type MapResult to std.ouch.InputRange!limb You create the bullet in your foot for efficiency (CTFE).
Re: Fun: Shooting yourself in the foot in D
On Friday, 28 October 2016 at 01:25:55 UTC, Kirill Kryukov wrote: You shoot yourself in a tuple containing your foot, boot and sock. Cannot implicitly convert expression (map(shoot(foot))) of type MapResult to std.ouch.InputRange!limb
Re: SoundTab Theremin software synthesizer
On Friday, 28 October 2016 at 08:28:41 UTC, Vadim Lopatin wrote: I've open sourced my project SoundTab: https://github.com/buggins/soundtab/ Play like on Theremin, but instead of moving hand in the air, move pen over wacom tablet. Volume is modulated by pen pressure, instead of left hand movement in Theremin. For better experience, use Wacom digitizer with pressure detection. You can play with mouse as well, but w/o volume modulation (no pressure information), and less precise positioning. Supports only Windows so far. Binaries may be downloaded here: https://github.com/buggins/soundtab/releases Reddit: https://www.reddit.com/r/programming/comments/59thwr/soundtab_theremin_software_synth_with_wacom/ Screenshot added: https://buggins.github.io/soundtab/screenshots/soundtab-screenshot-1.png
Re: [Slides] Generic Low Level Programming with D - The Better C for your Business
On Friday, 28 October 2016 at 08:28:31 UTC, Johan Engelen wrote: On Friday, 28 October 2016 at 06:46:27 UTC, Ilya Yaroshenko wrote: https://docs.google.com/presentation/d/1w1cQ8vDluglRIt8Qdnm-sY7kqxoKZxbPEWW6tR3lPpo/edit?usp=sharing Nice :) Something I noticed on slide 6-8. The call __adEq2 is pretty lame, we have our fix ready: https://github.com/ldc-developers/ldc/pull/1719 Nice! (you really should number your slides!) Done -Johan
Re: [Slides] Generic Low Level Programming with D - The Better C for your Business
On Friday, 28 October 2016 at 08:26:03 UTC, FreeSlave wrote: On Friday, 28 October 2016 at 06:46:27 UTC, Ilya Yaroshenko wrote: https://docs.google.com/presentation/d/1w1cQ8vDluglRIt8Qdnm-sY7kqxoKZxbPEWW6tR3lPpo/edit?usp=sharing Thanks. Was it for live presentation? Yes Is there a video? Probably no And where is this fox from? https://telegram.org/
Re: What is the right level of abstractions for D?
On Thursday, 27 October 2016 at 17:03:09 UTC, Nick Sabalausky wrote: On 10/27/2016 02:22 AM, Joakim wrote: 1. low-level compiled languages like C++, D, Rust, and Swift, meant for performance and usually experts who want to squeeze it out 2. mid-level bytecode languages like Java and C#, meant for the vast middle of day-to-day programmers to crank out libraries and apps that perform reasonably well 3. high-level "scripting" languages like Ruby and Python, meant for those who don't care too much for performance but just want to get working code I think D is positioned somewhere between 1 and 2, though closer to 1. However, there is sometimes talk of using D for all three, though perhaps that is only meant as an added benefit for people already using it for 1 or 2, ie those who already know the language better. You're falling into the common fallacy that those groups are mutually exclusive and that a single language can't be appropriate for more than one. D is all about proving that wrong, and is meant for, and good at, all three. There are good reasons for this split, and yes, it is probably impossible for one language to attract all three groups. You could use languages from 1 and 2 for all three, with a bit more work, but I don't see many scripts written in C++. :) The reason for the split is that there are different levels of software expertise and performance needs, and each of those groups is geared for a different level. Show templates to a scripting user and they probably run away screaming. D can probably do well with groups 1 and 2, but the level of power and expertise that is needed for those lower levels will scare away people from 3. Those already using it for 1 and 2 may also be comfortable with reusing D for scripting, but that's not attracting people from group 3, ie those who only want something easy to use and don't want to know the difference between a static and dynamic array. I've noticed that, for many of the people who don't "get" D, the problem they're hitting is that they're minds are so twisted around by the "polyglot" culture, that they're looking for "the one" tiny little niche that D is for, not seeing that, and thus missing the whole entire point. Yes, this has definitely hurt D, being stuck between 1 and 2. People from 2 probably look at D and think it's too low-level. People from 1 are always looking to squeeze out _more_ performance, so the GC is a way for them to just write off D. You and I think they're making a mistake, but maybe they're not wrong for their own uses. As I said, the recent push for @nogc and C++ compatibility suggests that a renewed effort is being made to focus on group 1, particularly when combined with the D benchmarks for regex and recently math. I'm happy in that space between 1 and 2, and the recent push to move languages from 2 to AoT compilation suggests that is a good place to be. So maybe group 2 will also come to us. :)
SoundTab Theremin software synthesizer
Hello, I've open sourced my project SoundTab: https://github.com/buggins/soundtab/ Play like on Theremin, but instead of moving hand in the air, move pen over wacom tablet. Volume is modulated by pen pressure, instead of left hand movement in Theremin. For better experience, use Wacom digitizer with pressure detection. You can play with mouse as well, but w/o volume modulation (no pressure information), and less precise positioning. Supports only Windows so far. Binaries may be downloaded here: https://github.com/buggins/soundtab/releases Best regards, Vadim
Re: [Slides] Generic Low Level Programming with D - The Better C for your Business
On Friday, 28 October 2016 at 06:46:27 UTC, Ilya Yaroshenko wrote: https://docs.google.com/presentation/d/1w1cQ8vDluglRIt8Qdnm-sY7kqxoKZxbPEWW6tR3lPpo/edit?usp=sharing Nice :) Something I noticed on slide 6-8. The call __adEq2 is pretty lame, we have our fix ready: https://github.com/ldc-developers/ldc/pull/1719 (you really should number your slides!) -Johan
Re: [Slides] Generic Low Level Programming with D - The Better C for your Business
On Friday, 28 October 2016 at 06:46:27 UTC, Ilya Yaroshenko wrote: https://docs.google.com/presentation/d/1w1cQ8vDluglRIt8Qdnm-sY7kqxoKZxbPEWW6tR3lPpo/edit?usp=sharing Thanks. Was it for live presentation? Is there a video? And where is this fox from?
Re: Linus' idea of "good taste" code
On Tuesday, 25 October 2016 at 22:53:54 UTC, Walter Bright wrote: Eliminating loops is something D adds, and goes even further to making code a straight line. A problem for myself and probably many programmers, is some of the tricks like what Linus did simply doesn't come to mind because it's not something we'd seen before so we can't model after it, and also that you sort of follow the same logic of how you'd resolve it because that's how you were taught to resolve it or it's how you know to resolve it. Often when I go for code I start with commenting the steps/breakdown, then I write each section, refactoring and cleaning up and shortening naturally are last, but once code is working it doesn't usually change too much even if there can be improvement. Hmm what we really need is something like a good 100 examples of good 'tasty' code, good code in a variety of code, something digestible and even explained down for those not following the full logic if how/why it works, perhaps even bad examples to work up from.
Re: [Slides] Generic Low Level Programming with D - The Better C for your Business
On Friday, 28 October 2016 at 06:46:27 UTC, Ilya Yaroshenko wrote: https://docs.google.com/presentation/d/1w1cQ8vDluglRIt8Qdnm-sY7kqxoKZxbPEWW6tR3lPpo/edit?usp=sharing Thanks for uploading these!
Re: test if the alias of a template is a literal
On Friday, 28 October 2016 at 03:33:33 UTC, Basile B. wrote: Hello, I think the correct isStringLiteral would be: import std.meta; template isStringLiteral(alias V) { enum isCompileTime = is(typeof((){enum a = V;})); enum isString = is(typeof(V) == string); enum isStringLiteral = isCompileTime && isString; } It works, Thanks. Also, i don't think in my case there is the need for a variant for types( aka isStringLiteral(V) without alias) because it's an error to pass a type to Optimize in first place. But for a general purpouse library, maybe a template isLiteral(alias V) that only checks if it is a literal without the type checking, would have more sense to have also isLiteral(V) for types that returns always false. Gianni Pisetta
Re: How to kill whole application if child thread raises an exception?
On Thursday, 27 October 2016 at 13:37:29 UTC, Steven Schveighoffer wrote: Hm... what about: import std.traits: Parameters; auto mySpawn(F)(F func, Parameters!F params) { static auto callIt(F func, Parameters!F params) { try { return func(params); } catch(Throwable t) { // print the exception/error, e.g.: import std.writeln; writeln(e.toString()); // terminate program import core.stdc.stdlib : exit; exit(1); } } return spawn(, func, params); } void main() { auto tID = mySpawn(); ... } -Steve I found the solution which works with dmd and ldc2: ... import core.stdc.stdlib: _Exit; _Exit(exitcode); ...
[Slides] Generic Low Level Programming with D - The Better C for your Business
https://docs.google.com/presentation/d/1w1cQ8vDluglRIt8Qdnm-sY7kqxoKZxbPEWW6tR3lPpo/edit?usp=sharing
Re: exercise - find invalid D tokens (Impossible ?)
On Friday, 28 October 2016 at 06:21:38 UTC, Johan Engelen wrote: On Friday, 28 October 2016 at 05:16:45 UTC, Basile B. wrote: Here are the specifications of token strings: "Token strings open with the characters q{ and close with the token }. In between must be valid D tokens. The { and }" So we can deduce that any invalid D token inside a token string will lead to a compilation error. Indeed: void main() { enum s = q{#}; // malformed special token sequence } produces an error. So are you able to find more invalid token ? Try '}' Yes and many others. Since I've posted this message I've realized that actually there are much invalid tokens. Any character that's not an Universal Alpha and that's not in a string prevents compilation. A complete list is at page 451 in http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1124.pdf
Re: Mir GLAS is a C library and passes Natlib's test suite! And questions :-)
On Friday, 28 October 2016 at 03:44:05 UTC, Andrei Alexandrescu wrote: On 10/27/16 3:59 AM, Ilya Yaroshenko wrote: Mir GLAS (Generic Linear Algebra Subprograms) has its own repository [1] now. Big news: 1. Mir GLAS does not require D / C++ runtime and can be used in any programming language as common C library! See read README [1] for more details. Cool work! One thing I'd want to understand is how to use Mir GLAS from within D itself. If it's a straight C interface, there seems to be a fair amount of friction (we have a D program communicating with a D library through the uncomfortable confines of a C interface). Is that the case? Should there be a way to short circuit the C API and use a more expressive D interface? (Looking e.g. at Eigen, it's meant to allow people using it from C++ to take advantage of a C++-specific smooth interface.) GLAS has 2 APIs: GLAS(ndslise) and BLAS(fortran). Both APIs has C/C++ and D headers. D headers contains aliases with unified names like in core.stdc.tgmath. So, extern(C) interface for GLAS is comfortable and looks like: gemm(alpha, a, b, beta, c); // calls glas_?gemm The latest ndslice PR to stable branch solves a problem in case of const and immutable a and b. https://github.com/dlang/phobos/pull/4873 GLAS does not have syntax like Eigen, i mean c = a * b; This syntax can be a part of another package for scripting like syntax. See also Q https://github.com/libmir/mir-glas#why-glas-does-not-have-lazy-evaluation-and-aliasing-like-eigen 6. GLAS is no longer distributed as a generic library. Level 2 and Level 3 generic API will be removed from Mir. There are few reasons why it is much better as precompiled library, and no reasons why it should be generic. In the same time, generic multidimensional Level 1 routines will be improved. I guess I'd like to understand the dynamics better here. The main reason is compilation time (1 secs+) and template bloat (50 KB +). OpenBLAS size is more than 20 MB. GLAS is smaller, but it is not something lightweight like `sort`. Assume you are buildings a large D projects one-by-one file in parallel. It can be builded during minutes and its size can be >100 MB, only because GLAS. So, having an extern(C) layers is good practice to keep interface clear and compile time small. Questions: 1. Would you like GLAS be packed with Phobos? You have all support from Walter and myself for integrating GLAS with Phobos. Before that I'd want to make sure we slice and dice things properly. Awesome! I am happy to read this) 2. Is it possible to make GLAS a replaceable part of Phobos? For example a user may want to use the latest GLAS without waiting a new compiler release. That would be an interesting precedent. We should talk about it next week. (My knee-jerk reaction is if we're worth our salt we should release Phobos often enough to obviate the need for this. But the notion of hot-swapping subcomponents is cool too.) Some concepts can be found on a slides from my today's talk https://docs.google.com/presentation/d/1w1cQ8vDluglRIt8Qdnm-sY7kqxoKZxbPEWW6tR3lPpo/edit?usp=sharing Thanks, Andrei Best regards, Ilya
Re: exercise - find invalid D tokens (Impossible ?)
On Friday, 28 October 2016 at 05:16:45 UTC, Basile B. wrote: Here are the specifications of token strings: "Token strings open with the characters q{ and close with the token }. In between must be valid D tokens. The { and }" So we can deduce that any invalid D token inside a token string will lead to a compilation error. Indeed: void main() { enum s = q{#}; // malformed special token sequence } produces an error. So are you able to find more invalid token ? Try '}'
Re: Comparing compilation time of random code in C++, D, Go, Pascal and Rust
On Thursday, 27 October 2016 at 12:11:09 UTC, Johan Engelen wrote: On Thursday, 27 October 2016 at 06:43:15 UTC, Sebastien Alaiwan If code generation/optimization is the bottleneck, a "ccache-for-D" ("dcache"?) tool might be very beneficial. See https://johanengelen.github.io/ldc/2016/09/17/LDC-object-file-caching.html I also have a working dcache implementation in LDC but it still needs some polishing. Hashing the LLVM bitcode ... how come I didn't think about this before! Unless someone manages to do the same thing with gdc + GIMPLE, this could very well be the "killer" feature of LDC ... Having a the fastest compiler on earth still doesn't provide scalability ; interestingly, when I build a full LLVM+LDC toolchain, the longest step is the compilation of the dmd frontend. It's the only part that is: 1) not cached: all the other source files from LLVM are ccache'd. 2) sequential: my CPU load drops to 12.5%, although it's near 100% for LLVM.