Re: Enough D to Make a Living?
On 22/02/17 13:26, Ola Fosheim Grøstad wrote: On Wednesday, 22 February 2017 at 09:09:45 UTC, Russel Winder wrote: Learning C++, then D, then Rust for example will have benefit because there are new things there even though the core computational model is effectively the same – they have differences that matter. Maybe. I think "modern" C++ is a in class of it's own at this point. It is now quite detached from it's root: C with classes. I feel slightly bad for sending you to read through the whole of http://lbrandy.com/blog/2010/03/never-trust-a-programmer-who-says-he-knows-c/ before getting to the punchline on the last sentence, but on the plus side, it is very short. On a slightly different note, "C with classes" is the name of C++'s predecessor, which was a preprocessor. Strastrup draws a very distinct line between that and the first C++ compiler (cfront). the computational model as for all the patterns you ought to follow and not nearly enough constraints from the compiler on what you should not do. That is a matter of perspective. I, for one, feel other languages put too much constraints on, making me work quite hard to get what I want expressed in the language, often blocking me from the most efficient implementation altogether. D is better in that regard than many, but still weights on me on occasion. With modern C++ you either have to go for being proficient or end up feeling miserable. Which is quite different from most imperative languages I think. Which is precisely why it is not a good language to start with unless you intend to stick with it. This is not a language mastered quickly, and superficial knowledge of it really is a dangerous thing. There is no point in aiming to learn it superficially. Shachar
[Issue 17188] `core.stdc.stdlib.qsort()` is broken
https://issues.dlang.org/show_bug.cgi?id=17188 Walter Brightchanged: What|Removed |Added Keywords||safe CC||bugzi...@digitalmars.com --
[Issue 17164] [REG 2.072.0] undefined identifier '__va_argsave'
https://issues.dlang.org/show_bug.cgi?id=17164 Walter Brightchanged: What|Removed |Added Status|NEW |RESOLVED CC||bugzi...@digitalmars.com Resolution|--- |WONTFIX --- Comment #1 from Walter Bright --- __va_argsave is an internal symbol with more or less magic semantics. Support for it has been removed, as proper stdarg semantics now works. Use core.stdc.stdarg, and va_list, va_start, va_arg and va_end. https://github.com/dlang/dmd/pull/5779 --
Re: simple static if / traits question...
On Wednesday, 22 February 2017 at 22:37:25 UTC, Profile Anaysis wrote: On Wednesday, 22 February 2017 at 21:27:47 UTC, WhatMeWorry wrote: I'm doing conditional compilation using static ifs like so: enum bool audio = true; // if audio flag is present and set to true, add to code build static if ( (__traits(compiles, audio)) && audio) playSound(soundSys, BLEEP ); This works, but I thought there might be a simpler way. For instance, after perusing std.traits, I thought I would find something like isPresent(audio) or isSymbol(audio) templates. Or am I being obtuse here? Thanks. You do realize that audio is a compile time constant? This means that in the binary, everything that depends on it is evaluated(as it can be, since it is known). This means that whatever app you are using will not be able to be able to "adapt" to the system changes. In this case, if the system has audio there is no way for the binary to use it because you compiled it out(if audio = false). In such a case you do not want to use a static or compile time variable unless you plan on creating multiple binaries. If your example above was just for demo then yes, you can do that but compiles is not what you want. Compiles only checks if the statement that follows is compilable as valid D code and it doesn't have anything to do with the value of the variables. Definitely overthought this one big time. But there is so much meta goodness in std.traits that I felt compelled to use "compiles" :) There are a few options: 1. static if(audio) 2. version(audio) 3. if (audio) It looks like you are trying to create the version(audio) semantic(if exists then use, else don't). Ultimately, though, if you are trying to make a binary that can either use audio or not depending on where it is ran, you'll have to stick to using actual run time variables and probably be a bit more organized about it. option 1 is the one I was shooting for. does the static if (audio) just check for the existence of audio, or does it also check to see if audio is true as well? I've got a game tutorial with 15 sequential projects. Each project introduces a new concept by building on the previous project code. But I soon had so much code duplication that I decided to use common modules/functions. The specific code could be injected via flags in the apps.d Hence my original question.
Re: Threads not garbage collected ?
The thread you created holds a reference to the `class A` object, so that object can't be collected. This is what you probably want. As soon as the object is collected, its memory can be reused. But the thread still has a reference to it, so it can modify and read that memory. And whoever the GC handed that memory can modify and read it. In short, data corruption.
Re: Updates to the tsv-utils toolkit
On Wednesday, 22 February 2017 at 18:12:50 UTC, Jon Degenhardt wrote: It's not quite a year since the open-sourcing of eBay's tsv utilities. Since then there have been a number of additions and updates, and the tools form a more complete package. The tools assist with manipulation of tabular data files common in machine learning and data mining environments. They work alongside traditional Unix command line tools like 'cut', and 'sort'. They also fit well with data mining and stats packages like R and Pandas. [...] Nice writeup, somebody posting this to reddit or will that be done with a future blog post?
Re: nginx reverse proxy for vibe tutorial
谢谢!
Re: cost of calling class function
On Thursday, February 23, 2017 02:17:02 Jeremy DeHaan via Digitalmars-d wrote: > On Thursday, 23 February 2017 at 01:48:40 UTC, Seb wrote: > > AFAICT though it was approved, the switch to final by default > > has never happened. > > I believe Andrei made an executive decision to shut down final by > default. Yeah, the change that introduced virtual to start the change to making class member functions non-virtual by default was actually committed, and then Andrei found out about it and insisted that it be reverted. So, it was reverted, and we're never going to get non-virtual by default. - Jonathan M Davis
Re: cost of calling class function
On Thursday, 23 February 2017 at 01:48:40 UTC, Seb wrote: AFAICT though it was approved, the switch to final by default has never happened. I believe Andrei made an executive decision to shut down final by default.
Re: cost of calling class function
On Wednesday, 22 February 2017 at 23:49:43 UTC, Dušan Pavkov wrote: Hello, I have tried to measure how much would some simple task be faster in D than in C#. I ported some simple code from C# to D 1:1 almost without changes and C# code was faster. After eliminating causes one by one I have an example which shows where the problem is. If the function is outside of class code runs much faster. I'm obviously doing something wrong and would appreciate any help with this. I think I can provide a couple of pointers for one reason. The function isn't final and virtual calls are inefficient: https://dlang.org/spec/function.html#virtual-functions http://forum.dlang.org/post/mailman.840.1332033836.4860.digitalmar...@puremagic.com https://issues.dlang.org/show_bug.cgi?id=11616 http://wiki.dlang.org/DIP51 AFAICT though it was approved, the switch to final by default has never happened.
Re: Updates to the tsv-utils toolkit
On Wednesday, 22 February 2017 at 21:07:43 UTC, bpr wrote: On Wednesday, 22 February 2017 at 18:12:50 UTC, Jon Degenhardt wrote: ...snip... Repository: https://github.com/eBay/tsv-utils-dlang Performance benchmarks: https://github.com/eBay/tsv-utils-dlang/blob/master/docs/Performance.md --Jon This is very nice code, and a good result for D. I'll study this carefully. So much of data analysis is reading/transforming files... ...snip... Thanks! Both for the feedback and for any evaluation you might do. Any insights or thoughts you may have would be quite welcome. --Jon
cost of calling class function
Hello, I have tried to measure how much would some simple task be faster in D than in C#. I ported some simple code from C# to D 1:1 almost without changes and C# code was faster. After eliminating causes one by one I have an example which shows where the problem is. If the function is outside of class code runs much faster. I'm obviously doing something wrong and would appreciate any help with this. Here is the code: import std.stdio; import std.conv; import std.datetime; public float getTotal(string s, int add) { float result = add; for (int j = 0; j < s.length; j++) { result += s[j]; } return result; } class A { public float getTotal(string s, int add) { float result = add; for (int j = 0; j < s.length; j++) { result += s[j]; } return result; } } void main(string[] args) { StopWatch sw; sw.start(); int n = args.length == 2 ? to!int(args[1]) : 10; string inputA = "qwertyuiopasdfghjklzxcvbnm0123456789"; double total = 0; for (int i = 0; i < n; i++) { for (int ii = 0; ii < inputA.length; ii++) { total += getTotal(inputA, i); } } sw.stop(); writeln("direct call: "); writeln("total: ", total); writeln("elapsed: ", sw.peek().msecs, " [ms]"); writeln(); total = 0; auto a = new A(); sw.reset(); sw.start(); for (int i = 0; i < n; i++) { for (int ii = 0; ii < inputA.length; ii++) { total += a.getTotal(inputA, i); } } sw.stop(); writeln("func in class call: ", total); writeln("total: ", total); writeln("elapsed: ", sw.peek().msecs, " [ms]"); } here are the build configuration and execution times: C:\projects\D\benchmarks\reduced problem>dub run --config=application --arch=x86_64 --build=release-nobounds --compiler=ldc2 Performing "release-nobounds" build using ldc2 for x86_64. benchmark1 ~master: target for configuration "application" is up to date. To force a rebuild of up-to-date targets, run again with --force. Running .\benchmark1.exe direct call: total: 1.92137e+11 elapsed: 4 [ms] func in class call: 1.92137e+11 total: 1.92137e+11 elapsed: 138 [ms] Thanks in advance.
[Issue 16824] std.experimental.allocator.dispose leaks memory for arrays of more than 1 dimension
https://issues.dlang.org/show_bug.cgi?id=16824 --- Comment #12 from github-bugzi...@puremagic.com --- Commit pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/64a0814ae426749a70decc5382b2fb3365a52a3e Issue 16824: fix experimental makeMultidimensionalArray API --
Re: Snowflake Strings
Thanks, Mike!
DConf 2017 speaking proposals due Feb 28
Feb 28 is coming up fast!
Re: Checking, whether string contains only ascii.
On Wednesday, 22 February 2017 at 20:01:57 UTC, Adam D. Ruppe wrote: On Wednesday, 22 February 2017 at 19:26:15 UTC, berni wrote: herefore I'd like to make sure that the string the program read is only made up of ascii characters. Easiest: foreach(char ch; postscript) if(ch > 127) throw new Exception("non-ascii detected"); :)
Re: simple static if / traits question...
On Wednesday, 22 February 2017 at 21:27:47 UTC, WhatMeWorry wrote: I'm doing conditional compilation using static ifs like so: enum bool audio = true; // if audio flag is present and set to true, add to code build static if ( (__traits(compiles, audio)) && audio) playSound(soundSys, BLEEP ); This works, but I thought there might be a simpler way. For instance, after perusing std.traits, I thought I would find something like isPresent(audio) or isSymbol(audio) templates. Or am I being obtuse here? Thanks. You do realize that audio is a compile time constant? This means that in the binary, everything that depends on it is evaluated(as it can be, since it is known). This means that whatever app you are using will not be able to be able to "adapt" to the system changes. In this case, if the system has audio there is no way for the binary to use it because you compiled it out(if audio = false). In such a case you do not want to use a static or compile time variable unless you plan on creating multiple binaries. If your example above was just for demo then yes, you can do that but compiles is not what you want. Compiles only checks if the statement that follows is compilable as valid D code and it doesn't have anything to do with the value of the variables. There are a few options: 1. static if(audio) 2. version(audio) 3. if (audio) It looks like you are trying to create the version(audio) semantic(if exists then use, else don't). Ultimately, though, if you are trying to make a binary that can either use audio or not depending on where it is ran, you'll have to stick to using actual run time variables and probably be a bit more organized about it.
Re: Vibe.d: Listening to port 8080 on external device doesn't work
On Wednesday, 22 February 2017 at 00:53:53 UTC, krzaq wrote: On Wednesday, 22 February 2017 at 00:38:30 UTC, aberba wrote: Using vibe.d, I bind to port 8080 at 127.0.0.1 but I can't access server on my phone through hotspot using the external IP from ip addr on Linux. But 127.0.0 running Apache server works. Don't if its vibe.d or OS (ubuntu 14.04) How do I reached my vibe.d server in this case on my phone? Listen on "0.0.0.0". Thanks. Worked! Just realized both 127.0.0.1 and 0.0.0.0 cannot be both activated on the same port.
Re: Snowflake Strings
On 02/22/2017 02:26 PM, Ali Çehreli wrote: > - Assuming they are line numbers, the 2 and 3 below should be 3 and 4: > > (i < 3 || _d_assertp(TMP, 2)) > (j & 1 || _d_assertp(TMP, 3)) Ooh! I take it back. They are correct in the original source... Ali
Re: Snowflake Strings
On 02/22/2017 05:08 AM, Mike Parker wrote: Walter shares a little bit of compiler knowledge, explaining how DMD stuffs string literals into object files. Blog post: http://dlang.org/blog/2017/02/22/snowflake-strings/ Reddit: https://www.reddit.com/r/programming/comments/5viixe/snowflake_strings_walter_bright_on_how_the_dmd_d/ Thanks! Two improvements: - People outside of the D (and C++) community may not know who "Andrei" is. - Assuming they are line numbers, the 2 and 3 below should be 3 and 4: (i < 3 || _d_assertp(TMP, 2)) (j & 1 || _d_assertp(TMP, 3)) Ali
Re: simple static if / traits question...
On Wednesday, 22 February 2017 at 21:27:47 UTC, WhatMeWorry wrote: I'm doing conditional compilation using static ifs like so: enum bool audio = true; // if audio flag is present and set to true, add to code build static if ( (__traits(compiles, audio)) && audio) playSound(soundSys, BLEEP ); I think you're thinking too deeply on this. During optimization branches of if statements that always evaluate to false are compiled out.
Re: Call for arms: Arch Linux D package maintenance
On Thursday, 16 February 2017 at 19:58:47 UTC, Rory McGuire wrote: Hi, I am planning on asking to become TU for the dlang packages in community. I've been building and working with the current packages and making my own packages to make sure I know what I'm getting in to. LDC and GDC are matched with the system versions of llvm and gcc. If I can get TU approval I will put time in to these packages and hopefully make some Arch tools that use dlang to try and promote it more. To learn makepkg and nampac etc I built this [0], it is a set of PKGBUILD files that are loosely based on the way I use multiple official dmd compilers on my dev box. Some of my customers use older version of Vibe that do not build on current dmd. I actually normally use /usr/local/ and not /usr/lib for my dmd installation. It also has a little utility for switching between compilers versions, similar to archlinux-java. [0]: https://github.com/rjmcguire/archlinux-dmd Hi Ruby, I just saw that you pushed out new versions for LDC and Phobos - thanks a lot for doing this! Your work is highly appreciated :) If I can get TU approval I will put time in to these packages and hopefully make some Arch tools that use dlang to try and promote it more. Awesome! I am really looking forward to this! Please let us know if there's any way we can help you to make this process easier.
[Issue 4391] std.functional.curry is not a real curry
https://issues.dlang.org/show_bug.cgi?id=4391 Andrei Alexandrescuchanged: What|Removed |Added Keywords||bootcamp --- Comment #6 from Andrei Alexandrescu --- Put this up for bootcamp. --
[Issue 4391] std.functional.curry is not a real curry
https://issues.dlang.org/show_bug.cgi?id=4391 Andrei Alexandrescuchanged: What|Removed |Added Assignee|and...@erdani.com |nob...@puremagic.com --
Re: Checking, whether string contains only ascii.
On Wed, Feb 22, 2017 at 09:16:24PM +, kinke via Digitalmars-d-learn wrote: [...] > One more again as I couldn't believe noone went for 'any' yet: > > --- > import std.algorithm; > return !s.any!"a > 127"; // code-point level > --- You win 1 intarwebs for the shortest solution posted so far. ;-) Though, according to the OP, an exception is wanted, so it should be more along the lines of: enforce(!s.any!"a > 127"); T -- A bend in the road is not the end of the road unless you fail to make the turn. -- Brian White
simple static if / traits question...
I'm doing conditional compilation using static ifs like so: enum bool audio = true; // if audio flag is present and set to true, add to code build static if ( (__traits(compiles, audio)) && audio) playSound(soundSys, BLEEP ); This works, but I thought there might be a simpler way. For instance, after perusing std.traits, I thought I would find something like isPresent(audio) or isSymbol(audio) templates. Or am I being obtuse here? Thanks.
Re: Checking, whether string contains only ascii.
On Wednesday, 22 February 2017 at 20:07:34 UTC, Ali Çehreli wrote: One more: bool isAscii(string s) { import std.string : representation; import std.algorithm : canFind; return !s.representation.canFind!(c => c >= 0x80); } unittest { assert(isAscii("hello world")); assert(!isAscii("hellö wörld")); } Ali One more again as I couldn't believe noone went for 'any' yet: --- import std.algorithm; return !s.any!"a > 127"; // code-point level ---
Re: Updates to the tsv-utils toolkit
On Wednesday, 22 February 2017 at 18:12:50 UTC, Jon Degenhardt wrote: ...snip... Repository: https://github.com/eBay/tsv-utils-dlang Performance benchmarks: https://github.com/eBay/tsv-utils-dlang/blob/master/docs/Performance.md --Jon This is very nice code, and a good result for D. I'll study this carefully. So much of data analysis is reading/transforming files... I wish you didn't anonymize the specialty toolkits. I think I understand why you chose to do so, but it makes the comparison less valuable. Still, great work! Looking forward to a blogpost.
Re: Serializer class
Yes thank you it works.
Re: Threads not garbage collected ?
On Wednesday, 22 February 2017 at 15:23:59 UTC, Moritz Maxeiner wrote: It seems undesirable, as the thread can be many layers of encapsulation down, and they all need manual deletes. It's highly desirable to not have the program terminate when there's still work to be done on some critical non-main thread, so the druntime split into daemon vs non-daemon threads makes sense. Whether new threads should be daemonized by default (as opposed to preventing program termination by default) is an arbitrary decision. In your case, just set `isDaemon = true` for your threads and you should be good. [1] https://dlang.org/phobos/core_thread.html#.Thread.isDaemon Thanks, that is what I need.
Re: Checking, whether string contains only ascii.
On 02/22/2017 12:02 PM, ag0aep6g wrote: > On Wednesday, 22 February 2017 at 19:26:15 UTC, berni wrote: >> In my program, I read a postscript file. Normal postscript files >> should only be composed of ascii characters, but one never knows what >> users give us. Therefore I'd like to make sure that the string the >> program read is only made up of ascii characters. This simplifies the >> code thereafter, because I then can assume, that codeunit==codepoint. >> Is there a simple way to do so? >> >> Here a sketch of my function: >> >>> void foo(string postscript) >>> { >>>// throw Exception, if postscript is not all ascii >>>// other stuff, assuming codeunit=codepoint >>> } > > Making full use of the standard library: > > > import std.algorithm: all; > import std.ascii: isASCII; > import std.exception: enforce; > > enforce(postscript.all!isASCII); > > > That checks on the code point level (because strings are ranges of > dchars). If you want to be clever, you can avoid decoding and check on > the code unit level: > > > /* other imports as above */ > import std.utf: byCodeUnit; > > enforce(postscript.byCodeUnit.all!isASCII); > > > Or you can do it manually, avoiding all those imports: > > > foreach (char c; postscript) if (c > 0x7F) throw new Exception("not > ASCII"); > One more: bool isAscii(string s) { import std.string : representation; import std.algorithm : canFind; return !s.representation.canFind!(c => c >= 0x80); } unittest { assert(isAscii("hello world")); assert(!isAscii("hellö wörld")); } Ali
Re: Checking, whether string contains only ascii.
On Wednesday, 22 February 2017 at 19:26:15 UTC, berni wrote: In my program, I read a postscript file. Normal postscript files should only be composed of ascii characters, but one never knows what users give us. Therefore I'd like to make sure that the string the program read is only made up of ascii characters. This simplifies the code thereafter, because I then can assume, that codeunit==codepoint. Is there a simple way to do so? Here a sketch of my function: void foo(string postscript) { // throw Exception, if postscript is not all ascii // other stuff, assuming codeunit=codepoint } Making full use of the standard library: import std.algorithm: all; import std.ascii: isASCII; import std.exception: enforce; enforce(postscript.all!isASCII); That checks on the code point level (because strings are ranges of dchars). If you want to be clever, you can avoid decoding and check on the code unit level: /* other imports as above */ import std.utf: byCodeUnit; enforce(postscript.byCodeUnit.all!isASCII); Or you can do it manually, avoiding all those imports: foreach (char c; postscript) if (c > 0x7F) throw new Exception("not ASCII");
Re: Checking, whether string contains only ascii.
On Wednesday, 22 February 2017 at 19:26:15 UTC, berni wrote: herefore I'd like to make sure that the string the program read is only made up of ascii characters. Easiest: foreach(char ch; postscript) if(ch > 127) throw new Exception("non-ascii detected");
Re: how to pass stderr to core.stdc.stdio.fileno
On Wednesday, 22 February 2017 at 19:46:28 UTC, berni wrote: As I cannot find any PM-feature in this forum and don't know how to contact you else, I'm hijacking this thread to give you some feedback... You can always email me directly too, destructiona...@gmail.com Maybe you can figure out, why this is not included in the search result? It was a bug in the pagination, that function was on page two, which I don't show (my experience is if the search result isn't on page one, you're wasting your time anyway and should refine the terms)... but it should have been on page one. That's fixed, and I tweaked the score algorithm to give it a bonus because it is a free-standing function with a matching name instead of some member variable. So now it shows as the first result.
Re: Checking, whether string contains only ascii.
On Wednesday, 22 February 2017 at 19:57:22 UTC, jklm wrote: On Wednesday, 22 February 2017 at 19:26:15 UTC, berni wrote: In my program, I read a postscript file. Normal postscript files should only be composed of ascii characters, but one never knows what users give us. Therefore I'd like to make sure that the string the program read is only made up of ascii characters. This simplifies the code thereafter, because I then can assume, that codeunit==codepoint. Is there a simple way to do so? Here a sketch of my function: void foo(string postscript) { // throw Exception, if postscript is not all ascii // other stuff, assuming codeunit=codepoint } void foo(string postscript) { import std.ascii, astd.algorithm.ieration; if (!postscript.filter!(a => !isASCII(a)).empty) throw new Exception("bla"); } \s postscript args[0]
Re: Checking, whether string contains only ascii.
On Wednesday, 22 February 2017 at 19:26:15 UTC, berni wrote: In my program, I read a postscript file. Normal postscript files should only be composed of ascii characters, but one never knows what users give us. Therefore I'd like to make sure that the string the program read is only made up of ascii characters. This simplifies the code thereafter, because I then can assume, that codeunit==codepoint. Is there a simple way to do so? Here a sketch of my function: void foo(string postscript) { // throw Exception, if postscript is not all ascii // other stuff, assuming codeunit=codepoint } void foo(string postscript) { import std.ascii, astd.algorithm.ieration; if (!args[0].filter!(a => !isASCII(a)).empty) throw new Exception("bla"); }
Re: Checking, whether string contains only ascii.
On Wed, Feb 22, 2017 at 11:43:00AM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > import std.range.primitives; > > bool isAsciiOnly(R)(R input) > if (isInputRange!R && is(ElementType!R : dchar)) > { > import std.algorithm.iteration : fold; > return input.fold!((a, b) => a && b < 0x80)(true); > } > > unittest > { > assert(isAsciiOnly("abcdefg")); > assert(!isAsciiOnly("abcбвг")); > } [...] Ah, missing the Exception part: void foo(string input) { if (!input.isAsciiOnly) throw new Exception("..."); } T -- Why are you blatanly misspelling "blatant"? -- Branden Robinson
Re: Checking, whether string contains only ascii.
On Wed, Feb 22, 2017 at 07:26:15PM +, berni via Digitalmars-d-learn wrote: > In my program, I read a postscript file. Normal postscript files > should only be composed of ascii characters, but one never knows what > users give us. Therefore I'd like to make sure that the string the > program read is only made up of ascii characters. This simplifies the > code thereafter, because I then can assume, that codeunit==codepoint. > Is there a simple way to do so? [...] Hmm... What about: import std.range.primitives; bool isAsciiOnly(R)(R input) if (isInputRange!R && is(ElementType!R : dchar)) { import std.algorithm.iteration : fold; return input.fold!((a, b) => a && b < 0x80)(true); } unittest { assert(isAsciiOnly("abcdefg")); assert(!isAsciiOnly("abcбвг")); } Basically, it iterates over the string / range of characters and checks that every character is less than 0x80, since anything that's 0x80 or greater cannot be ASCII. T -- INTEL = Only half of "intelligence".
Re: how to pass stderr to core.stdc.stdio.fileno
As I cannot find any PM-feature in this forum and don't know how to contact you else, I'm hijacking this thread to give you some feedback... On Friday, 17 February 2017 at 19:16:44 UTC, Adam D. Ruppe wrote: Yes, that is my documentation fork, it has a search feature if you do dpldocs.info/some_term and it tries to be easier to read and navigate, let me know how you like it! I tried dpldocs.info/max looking for a function that gives the maximum of two or more values. I got a lot of results, but non of them was, what I was looking for. Meanwhile I found it, namely this one: http://dpldocs.info/experimental-docs/std.algorithm.comparison.max.html Maybe you can figure out, why this is not included in the search result?
Checking, whether string contains only ascii.
In my program, I read a postscript file. Normal postscript files should only be composed of ascii characters, but one never knows what users give us. Therefore I'd like to make sure that the string the program read is only made up of ascii characters. This simplifies the code thereafter, because I then can assume, that codeunit==codepoint. Is there a simple way to do so? Here a sketch of my function: void foo(string postscript) { // throw Exception, if postscript is not all ascii // other stuff, assuming codeunit=codepoint }
Re: New (page-per-artifact) standard library doc examples are now editable and runnable
On Tuesday, 21 February 2017 at 22:58:57 UTC, Seb wrote: Unfortunately it reverts the writeln magic as the false positive rate was too high - at some point we really should come up with something better :/ However the fact that ddoc and ddox emit different, fully built synax-highlighted HTML doesn't make it easier. Maybe the compiler can help out here (?) or we can run a libdparse-based formatter before running ddoc/ddox? (at least for ddox there is also the intermediate json output of DMD, but for now it seems that the switch to ddox doesn't happen as soon as anticipated) Okay I just couldn't let this sit on myself. So I went ahead and proposed a more "sophisticated" assert -> writeln rewrite tool that is based on Hackerpilot's excellent libdparse: https://github.com/dlang/dlang.org/pull/1582
Re: Updates to the tsv-utils toolkit
On Wednesday, 22 February 2017 at 18:43:57 UTC, Jack Stouffer wrote: On Wednesday, 22 February 2017 at 18:12:50 UTC, Jon Degenhardt wrote: Speed matters when processing large data files, and these tools are fast. I've published new benchmarks comparing the tools to similar tools written in several native compiled programming languages. The tools are the fastest on five of the six benchmarks run, generally by significant margins. It's a good result for the D programming language. Great news! Agreed, an outstanding result. I had not anticipated the deltas. The specialty toolkits have been anonymized in the tables below. The purpose of these benchmarks is to gauge performance of the D tools, not make comparisons between other toolkits. You're no fun ;) Yeah, I know. Not my style.
Re: Serializer class
On Wednesday, 22 February 2017 at 18:34:26 UTC, houdoux09 wrote: void Read(T)(T value) { foreach(i, mm; value.tupleof) { writeln(__traits(identifier, value.tupleof[i]), " = ", mm); if(isArray!(typeof(mm))) { Read(mm[0]); //Error } } } You need to use "static if" here inside foreach. Otherwise the body of your "if" gets compiled for all the different fields of "value" and of course fails for the fields that are not arrays.
Re: tanya library 0.2.0
On Wednesday, 22 February 2017 at 13:00:19 UTC, Kagamin wrote: On Sunday, 19 February 2017 at 11:41:44 UTC, Eugene Wissner wrote: realloc() can move memory and if an object of type A has references to other objects in the array, the objects will be corrupted. "A" should be a POD-type. Otherwise you have to allocate new memory, initialize it, copy the objects by one and deallocate the old memory. Now there is IAllocator.expand(). What's the difference between realloc+postblit and copy one by one? Postblit is called only after copy, it's not a constructor. The difference is that realloc will deallocate the old memory before postblit. For the sake of example: struct Sample { Sample* sample; this(this) { sample.sample = } } void main() { auto s = new Sample[2]; s[0].sample = [1]; s[1].sample = [0]; } Now suppose s[0] has the address 7fc8d2717000, s[1]: 7fc8d2717008. Realloc cannot reallocate in place and after the call to realloc s[0] has the address 7f27771e and s[1]: 7f27771e. It is too late to call the postblit here, Sample.sample refers to invalid memory.
Re: Updates to the tsv-utils toolkit
On Wednesday, 22 February 2017 at 18:12:50 UTC, Jon Degenhardt wrote: Speed matters when processing large data files, and these tools are fast. I've published new benchmarks comparing the tools to similar tools written in several native compiled programming languages. The tools are the fastest on five of the six benchmarks run, generally by significant margins. It's a good result for the D programming language. Great news! The specialty toolkits have been anonymized in the tables below. The purpose of these benchmarks is to gauge performance of the D tools, not make comparisons between other toolkits. You're no fun ;)
Re: Snowflake Strings
On Wednesday, 22 February 2017 at 13:08:13 UTC, Mike Parker wrote: Blog post: http://dlang.org/blog/2017/02/22/snowflake-strings/ Thanks for a wonder article. PS: The blog UI may need to be corrected for browsing from mobiles[1]. [1] http://imgur.com/a/7IPkm
Re: How do I use CTFE to generate an immutable associative array at compile time?
On Wed, Feb 22, 2017 at 06:17:14PM +, Stefan Koch via Digitalmars-d-learn wrote: > On Wednesday, 22 February 2017 at 17:05:17 UTC, H. S. Teoh wrote: > > On Wed, Feb 22, 2017 at 04:08:45PM +, Stefan Koch via > > Digitalmars-d-learn wrote: > > > [...] > > > > I'm not sure it's that simple. Just because AA's become CTFEable > > doesn't mean they will automatically be convertible to object code > > in the executable that allows runtime AA lookups. For instance, a > > CTFE pointer will have a value that has no correspondence with the > > object code in the executable, and neither will memory allocated > > during CTFE have any correspondence with the emitted object code > > (because this memory is allocated in the compiler, not in the object > > code). So if the CTFE AA implementation allocates nodes for storing > > key/value pairs, they will only exist in the CTFE engine, and > > pointers to them will only make sense within the CTFE engine. In > > order to make them work in the executable (so that you can do AA > > lookups to these computed nodes at runtime), you will need to > > somehow map them to object code. Just because AA's become CTFEable > > will not automatically solve this for you. > > > > [...] > > The CTFE allocated memory can be copied into the object file verbatim > because the structure is the same. Pointers are easy to fix up as > well, because by definition the have to point to static data that will > be in the object file. This will fail for cross-compilation. Unless you mean that the new CTFE engine is emulating the target machine directly? T -- Computers shouldn't beep through the keyhole.
Serializer class
Hello, i am new in D and i have a problem. I would like to retrieve the names of the variables and their value. But i can not retrieve the value of the array. class Test { public int a; public Test[] b; this() { a = 1; b = [new Test(), new Test()]; } } //== void Read(T)(T value) { foreach(i, mm; value.tupleof) { writeln(__traits(identifier, value.tupleof[i]), " = ", mm); if(isArray!(typeof(mm))) { Read(mm[0]); //Error } } } void main(string[] args) { Read(new Test()); } Thank you for your help.
Re: dmd -Wl=comma_separated_linker_flags (cf clang++ -Wl, comma_separated_linker_flags)
> You can pass multiple -L flags: > > dmd -L-lbar -L-Ldir -L--export-dynamic I know, but that's inconvenient. Would make things a lot easier if we had something like what i suggested: `-Wl=comma_separated_linker_flags` advantages: could seemlessly use `comma_separated_linker_flags` with either dmd or rdmd (compile + link in 1 stage) or 2 stages (compile w dmd followed by link w clang [or ld]) or make it easier to migrate code from build tools from C echosystem, or integrate seemlessly with ldc etc.
Re: D on the Weekends
> Am I reading it correctly that D is the second most popular general purpose > language (let's exclude GLSL form general purpose programming)?? And that the > volume of weekday commits, at least in GitHub, is dominated by niche and > legacy languages, plus Matlab? You're reading it wrong: it's sorted by ratio weekend/weekday, not by weekend (ie, not by volume). On Wed, Feb 22, 2017 at 3:42 AM, Ola Fosheim Grøstad via Digitalmars-dwrote: > On Wednesday, 22 February 2017 at 11:33:40 UTC, XavierAP wrote: >> >> purpose programming)?? And that the volume of weekday commits, at least in >> GitHub, is dominated by niche and legacy languages, plus Matlab? > > > I believe he tried to build a list of languages that are not used both on > weekdays and on weekends. Not sure what anyone would want to know anything > about that? > > Clickbait? > >
Re: How do I use CTFE to generate an immutable associative array at compile time?
On Wednesday, 22 February 2017 at 17:05:17 UTC, H. S. Teoh wrote: On Wed, Feb 22, 2017 at 04:08:45PM +, Stefan Koch via Digitalmars-d-learn wrote: [...] I'm not sure it's that simple. Just because AA's become CTFEable doesn't mean they will automatically be convertible to object code in the executable that allows runtime AA lookups. For instance, a CTFE pointer will have a value that has no correspondence with the object code in the executable, and neither will memory allocated during CTFE have any correspondence with the emitted object code (because this memory is allocated in the compiler, not in the object code). So if the CTFE AA implementation allocates nodes for storing key/value pairs, they will only exist in the CTFE engine, and pointers to them will only make sense within the CTFE engine. In order to make them work in the executable (so that you can do AA lookups to these computed nodes at runtime), you will need to somehow map them to object code. Just because AA's become CTFEable will not automatically solve this for you. [...] The CTFE allocated memory can be copied into the object file verbatim because the structure is the same. Pointers are easy to fix up as well, because by definition the have to point to static data that will be in the object file.
Updates to the tsv-utils toolkit
It's not quite a year since the open-sourcing of eBay's tsv utilities. Since then there have been a number of additions and updates, and the tools form a more complete package. The tools assist with manipulation of tabular data files common in machine learning and data mining environments. They work alongside traditional Unix command line tools like 'cut', and 'sort'. They also fit well with data mining and stats packages like R and Pandas. The tools include filtering, slicing, joins and other manipulation, sampling, and statistical calculations. If you find yourself working with large data files from a unix shell, you may like these tools. Speed matters when processing large data files, and these tools are fast. I've published new benchmarks comparing the tools to similar tools written in several native compiled programming languages. The tools are the fastest on five of the six benchmarks run, generally by significant margins. It's a good result for the D programming language. The benchmarks may be of interest regardless of your interest in the tools themselves. Repository: https://github.com/eBay/tsv-utils-dlang Performance benchmarks: https://github.com/eBay/tsv-utils-dlang/blob/master/docs/Performance.md --Jon
Re: About void[] and asockets
On Wednesday, 22 February 2017 at 17:57:31 UTC, Adam D. Ruppe wrote: On Wednesday, 22 February 2017 at 17:53:21 UTC, Jolly James wrote: No matter how I try, I am always getting: Error: none of the overloads of '__ctor' are callable using argument types (Data*), candidates are: (my-project) I don't know the library, so I'd have to see the Data class, but you might just be using when you should be using plain data. Silly me! Now I used Xamarin's Find-Usage-Feature, found one usage in ae and realized that there is no reason for using the keyword `new`, as Data is a struct (and so one does not need `new` unlike in C#) ...
Re: About void[] and asockets
On Wednesday, 22 February 2017 at 17:53:21 UTC, Jolly James wrote: No matter how I try, I am always getting: Error: none of the overloads of '__ctor' are callable using argument types (Data*), candidates are: (my-project) I don't know the library, so I'd have to see the Data class, but you might just be using when you should be using plain data.
Re: About void[] and asockets
On Wednesday, 22 February 2017 at 17:06:51 UTC, Jolly James wrote: On Wednesday, 22 February 2017 at 17:01:11 UTC, Adam D. Ruppe wrote: On Wednesday, 22 February 2017 at 16:55:03 UTC, Jolly James wrote: Well, what are these void-arrays for real? I mean, they contain data what does not make them really void, does it? They represent an array of anything; the user can pass ubyte[] to it, or int[] to it, or char[] to it, or anything else (even string if it is in void[] or const void[]). And how to I get received data out of Data.content[]? How to use TcpConnection.send()? E.g. for sending a string? Cast it to `const(ubyte)[]` then use it as a bag of bytes. That's almost always what you want to do inside. The function signature uses `in void[]` instead of `ubyte[]` because void will accept strings and other stuff too, whereas ubyte specifically requires it to be typed as bye. You want to use it INTERNALLY as bytes, but the external interface can accept almost anything. Thank you very much! Now it makes sense and I understand. But I have one problem: How to use the constructor of the Data class? No matter how I try, I am always getting: Error: none of the overloads of '__ctor' are callable using argument types (Data*), candidates are: (my-project)
Re: How do I use CTFE to generate an immutable associative array at compile time?
On Wed, Feb 22, 2017 at 04:08:45PM +, Stefan Koch via Digitalmars-d-learn wrote: > On Wednesday, 22 February 2017 at 15:27:22 UTC, H. S. Teoh wrote: > > (In fact, now I'm wondering if we could just hack dmd to emit the > > equivalent of this code as a lowering, whenever the user tries to > > declare a compile-time initialized AA.) > > All the problems disappear if the AA's are compiler visible and > CTFEable code. I'm not sure it's that simple. Just because AA's become CTFEable doesn't mean they will automatically be convertible to object code in the executable that allows runtime AA lookups. For instance, a CTFE pointer will have a value that has no correspondence with the object code in the executable, and neither will memory allocated during CTFE have any correspondence with the emitted object code (because this memory is allocated in the compiler, not in the object code). So if the CTFE AA implementation allocates nodes for storing key/value pairs, they will only exist in the CTFE engine, and pointers to them will only make sense within the CTFE engine. In order to make them work in the executable (so that you can do AA lookups to these computed nodes at runtime), you will need to somehow map them to object code. Just because AA's become CTFEable will not automatically solve this for you. > There is as far as I know a project by Martin Nowak that does that. > And uses templates for AA's rather then whacky TypeInfos. > > So in the future this problem will disappear. Oh I know, the problem is that this "future" has been taking a long time arriving. I was involved in an early (but unfortunately unsuccessful) effort to rewrite AA's as library code. But there was simply too much compiler magic involved with AA's that it couldn't work at the time. Much of this magic has been dispelled over the past few years, though, so we should be in better shape now for moving AA's completely into the library. I'm very much looking forward to Martin's implementation when it's ready. But in the meantime, lowering compile-time initialized AA's could have the above hack as a temporary workaround until we can get AA literals to be embeddable in object code. T -- GEEK = Gatherer of Extremely Enlightening Knowledge
Re: About void[] and asockets
On Wednesday, 22 February 2017 at 17:01:11 UTC, Adam D. Ruppe wrote: On Wednesday, 22 February 2017 at 16:55:03 UTC, Jolly James wrote: Well, what are these void-arrays for real? I mean, they contain data what does not make them really void, does it? They represent an array of anything; the user can pass ubyte[] to it, or int[] to it, or char[] to it, or anything else (even string if it is in void[] or const void[]). And how to I get received data out of Data.content[]? How to use TcpConnection.send()? E.g. for sending a string? Cast it to `const(ubyte)[]` then use it as a bag of bytes. That's almost always what you want to do inside. The function signature uses `in void[]` instead of `ubyte[]` because void will accept strings and other stuff too, whereas ubyte specifically requires it to be typed as bye. You want to use it INTERNALLY as bytes, but the external interface can accept almost anything. Thank you very much! Now it makes sense and I understand.
Re: About void[] and asockets
On Wednesday, 22 February 2017 at 16:55:03 UTC, Jolly James wrote: Well, what are these void-arrays for real? I mean, they contain data what does not make them really void, does it? They represent an array of anything; the user can pass ubyte[] to it, or int[] to it, or char[] to it, or anything else (even string if it is in void[] or const void[]). And how to I get received data out of Data.content[]? How to use TcpConnection.send()? E.g. for sending a string? Cast it to `const(ubyte)[]` then use it as a bag of bytes. That's almost always what you want to do inside. The function signature uses `in void[]` instead of `ubyte[]` because void will accept strings and other stuff too, whereas ubyte specifically requires it to be typed as bye. You want to use it INTERNALLY as bytes, but the external interface can accept almost anything.
Re: Class Order Style
On Tuesday, 21 February 2017 at 23:06:23 UTC, Jonathan M Davis wrote: On Tuesday, February 21, 2017 22:41:40 Lenny Lowood via Digitalmars-d-learn wrote: [...] It's completely a stylistic preference. There are a number of different ways to order your member variables and functions, and there are several different ways to apply attributes to them. [...] thank you!
About void[] and asockets
For sure, some might know ae. I am trying to use it as TcpServer. I got almost everything working fine concerning connection establishment and disconnecting. But there is one thing that makes it hard for me to understand, how to handle data. https://github.com/CyberShadow/ae/blob/master/net/asockets.d Well, what are these void-arrays for real? I mean, they contain data what does not make them really void, does it? And how to I get received data out of Data.content[]? How to use TcpConnection.send()? E.g. for sending a string?
Re: syntax sugar: std.path::buildPath instead of from!"std.path".buildPath
On 02/22/2017 06:53 AM, Atila Neves wrote: On Thursday, 16 February 2017 at 13:21:04 UTC, Andrei Alexandrescu wrote: On 2/16/17 7:11 AM, Atila Neves wrote: On Wednesday, 15 February 2017 at 17:10:26 UTC, Adam D. Ruppe wrote: On Wednesday, 15 February 2017 at 07:56:00 UTC, Jacob Carlborg wrote: Your documentation is an improvement but it doesn't help when reading the source code. Yeah, I think there's a few things we can do in the source too. We should find the common combinations and abstract them out, like I said before, isInputRangeOf is potentially useful. Though, like Andrei, I'm skeptical on doing too much of that, since the combinations can quickly explode and then you just have to search through more to figure out wtf they mean. That'd help the source and docs if we find the right balance. I submitted a Phobos PR for `isInputRangeOf`. It was nuked from orbit. I understand why: as you mention, the combinatorial explosion of names is an issue. But: it's a mess rangeifying code when this: void fun(Foo[] foos); // yay! readable becomes: void fun(R)(R foos) if(isInputRange!R && is(Unqual!(ElementType!R) == Foo); If you find a number of these, that would be good evidence. -- Andrei I found just over 70 similar lines, which is more than I expected given how generic Phobos is. The real issue is in client code though. I write less range-based code than I'd like, because it's a lot easier to make it a regular array and change it later if the function needs to be called with other ranges. If you submit a pull request that simplifies >70 constraints in Phobos and implicitly promises to simplify client-level constraints as much, that would have a good chance to be accepted. Destroy! -- Andrei
Re: How do I use CTFE to generate an immutable associative array at compile time?
On Wednesday, 22 February 2017 at 15:27:22 UTC, H. S. Teoh wrote: (In fact, now I'm wondering if we could just hack dmd to emit the equivalent of this code as a lowering, whenever the user tries to declare a compile-time initialized AA.) All the problems disappear if the AA's are compiler visible and CTFEable code. There is as far as I know a project by Martin Nowak that does that. And uses templates for AA's rather then whacky TypeInfos. So in the future this problem will disappear.
[Issue 16453] Missing @nogc annotations
https://issues.dlang.org/show_bug.cgi?id=16453 Jack Stoufferchanged: What|Removed |Added Status|NEW |RESOLVED CC||j...@jackstouffer.com Resolution|--- |FIXED --- Comment #2 from Jack Stouffer --- Several functions in core.thread are now marked @nogc. If you have other specific functions in mind, please make other issues for them. --
Re: How do I use CTFE to generate an immutable associative array at compile time?
On Wed, Feb 22, 2017 at 09:00:36AM +0100, Jacob Carlborg via Digitalmars-d-learn wrote: [...] > You can use an enum to declare the AA and then assign it to an > immutable variable using "static this". The you would only use to the > immutable variable and never the enum. > > enum aa = [1 : 2]; > > immutable int[int] iaa; > > static this() > { > iaa = aa; > } [...] Wow, this is miles better than the hacks that I've come up with! Also makes the no-static-AA issue much less of a problem that I thought it was. (In fact, now I'm wondering if we could just hack dmd to emit the equivalent of this code as a lowering, whenever the user tries to declare a compile-time initialized AA.) T -- Computers are like a jungle: they have monitor lizards, rams, mice, c-moss, binary trees... and bugs.
Re: Threads not garbage collected ?
On Wednesday, 22 February 2017 at 05:28:17 UTC, Alex wrote: [...] In both gdc and dmd I need to use manually delete this object or the program is blocked after main. Is by design ? Yes, it's documented here[1] (others have already replied on the GC subject, so I won't go into that). If you want a thread to be forcibly terminated instead of preventing program termination you need to set `thread.isDaemon = true`. It seems undesirable, as the thread can be many layers of encapsulation down, and they all need manual deletes. It's highly desirable to not have the program terminate when there's still work to be done on some critical non-main thread, so the druntime split into daemon vs non-daemon threads makes sense. Whether new threads should be daemonized by default (as opposed to preventing program termination by default) is an arbitrary decision. In your case, just set `isDaemon = true` for your threads and you should be good. [1] https://dlang.org/phobos/core_thread.html#.Thread.isDaemon
Re: Threads not garbage collected ?
On Wednesday, 22 February 2017 at 14:51:24 UTC, Guillaume Piolat wrote: https://p0nce.github.io/d-idioms/#The-trouble-with-class-destructors eh, I think this is less a destructor issue and just that the thread is still running and thus not eligible for collection anyway - there's still a reference to it elsewhere.
Re: Threads not garbage collected ?
On Wednesday, 22 February 2017 at 05:28:17 UTC, Alex wrote: void main() { auto a = new A; delete a; //need this or the program hangs } https://p0nce.github.io/d-idioms/#The-trouble-with-class-destructors
Re: Step into in debugging.
22.02.2017 17:32, ANtlord пишет: On Wednesday, 22 February 2017 at 14:23:02 UTC, ANtlord wrote: My bad again. It appears I have a smaller knowledge that I think. I'm ended up in typecons because `allocator` is made by template `scoped` returns instance of internal static struct `Scoped` and it has alias is asigned to method `Scoped_payload` and this is called on https://github.com/ANtlord/DCD/blob/master/src/server/autocomplete.d#L341. SOLVED And one more. Method `Scoped_payload` returns instance of type passed as template argument for template method `scoped`. As long as method `generateAutocompleteTrees` requires second argument must be instance of `IAllocator`, object `allocator` "transforms" to instance of class implements `IAllocator` by alias of `Scoped_payload` assigned to `this`. Thank you for sharing this!
Re: Step into in debugging.
On Wednesday, 22 February 2017 at 14:23:02 UTC, ANtlord wrote: My bad again. It appears I have a smaller knowledge that I think. I'm ended up in typecons because `allocator` is made by template `scoped` returns instance of internal static struct `Scoped` and it has alias is asigned to method `Scoped_payload` and this is called on https://github.com/ANtlord/DCD/blob/master/src/server/autocomplete.d#L341. SOLVED And one more. Method `Scoped_payload` returns instance of type passed as template argument for template method `scoped`. As long as method `generateAutocompleteTrees` requires second argument must be instance of `IAllocator`, object `allocator` "transforms" to instance of class implements `IAllocator` by alias of `Scoped_payload` assigned to `this`.
Re: Step into in debugging.
On Monday, 20 February 2017 at 13:55:57 UTC, ANtlord wrote: Hello! I care for project DCD. I've wanted to fix some issue in it very long time ago. But when I get a little bit of free time I encounter one big problem for me. I can't debug it using GDB. I can't go through call stack because I get a number of issues. Long story short I've decided to solve them one by one and I really need community's help. First of them. I can't make `step into` staying on this code line https://github.com/ANtlord/DCD/blob/master/src/server/autocomplete.d#L341. What I do: 1. I compile DCD project using dub with dmd `dub build --compiler=dmd --build=debug --config=server --parallel` 2. I run `gdb `. I do it from project root directory always `gdb dcd-server`. 3. Inside gdb. I do `break autocomplete.d:341` 4. Inside gdb. I do `run -p 6767` where `-p 6767` is DCD parameter. 5. I launch dcd-client with parameters for calling desirable code `dcd-client --port 6767 myfile.d -c 53`. File `myfile.d` consists of `void main(string[] args) { int[] asd = [4,2]; asd[0]. }`. Yes, it has one line. 6. Inside gdb. I stay on desirable line and I do `step`. 7. Inside gdb. I am ended up in `/usr/include/dlang/dmd/std/typecons.d:6097` instead function `generateAutocompleteTrees` called on the line. I attach this screenshot to be clear https://www.dropbox.com/s/6i2hmbvqwdvopur/Screenshot_20170220_214526.png?dl=0 Thanks. My bad again. It appears I have a smaller knowledge that I think. I'm ended up in typecons because `allocator` is made by template `scoped` returns instance of internal static struct `Scoped` and it has alias is asigned to method `Scoped_payload` and this is called on https://github.com/ANtlord/DCD/blob/master/src/server/autocomplete.d#L341. SOLVED
Re: FEM library?
On Wednesday, 22 February 2017 at 11:37:41 UTC, XavierAP wrote: @Nicholas yes such a FEM library to be developed would heavily depend on Mir. Ilya Yaroshenko pointed me to it in another thread. I didn't know about DlangScience, thanks. Looks like there is some overlap? I think mir used to be part of DlangScience, but I don't really know the history. Ilya and Seb are on both teams. From what I understand DlangScience is and aggregation of science related projects as well as some "in house" stuff see e.g. the stats stuff. @Dukc thanks! Whenever in the future I'm developing for a library project or following it... Looks like those development threads currently go in the General board? Wouldn't it be better to split them together into one board within the Development section? Looks like inside General, library/project threads get lost and buried too quickly. I know many/most people are using this via email though, but still. If you're looking for libraries (to use and/or to contribute) general is the place. If you're wondering how they work/ how to use them, learn is best, although it could go in general. If you've done something cool (like this!) put it on announce. If you're participating in the development of then you'll want to use whatever medium the other dev use e.g. gitter/github
Snowflake Strings
Walter shares a little bit of compiler knowledge, explaining how DMD stuffs string literals into object files. Blog post: http://dlang.org/blog/2017/02/22/snowflake-strings/ Reddit: https://www.reddit.com/r/programming/comments/5viixe/snowflake_strings_walter_bright_on_how_the_dmd_d/
Re: tanya library 0.2.0
On Sunday, 19 February 2017 at 11:41:44 UTC, Eugene Wissner wrote: realloc() can move memory and if an object of type A has references to other objects in the array, the objects will be corrupted. "A" should be a POD-type. Otherwise you have to allocate new memory, initialize it, copy the objects by one and deallocate the old memory. Now there is IAllocator.expand(). What's the difference between realloc+postblit and copy one by one? Postblit is called only after copy, it's not a constructor.
Re: Returning the address of a reference return value in @safe code - 2.072 regression?
On Monday, 20 February 2017 at 20:49:43 UTC, Johan Engelen wrote: The error is: "cannot take address of ref return of this.foo() in @safe function bar". Maybe a bugfix in safety system? Should it go through deprecation process?
Re: Threads not garbage collected ?
Alex wrote: The thread can then prevent the program from exiting on exception or otherwise. If the garbage collector doesn't kill threads, do I need to break all encapsulation to call some sort of finalise or destroy function on every object in case it has a thread object in it ? It would probably be better to have all core.thread.Threads registered in the run time so they can be killed when main exits. they are registered. but not exiting while at least one thread is alive is deliberate decision. you may take a look at std.concurrency instead of working with "raw" threads. besides providing services like message passing, it does terminate all the spawned threads if their owner dies. you may change that, of course, this is just a convenient default. but note that such termination will require calling `receive()` in a spawned thread. still, i think that message passing feature of std.concurrency is so useful that there is no reason to bypass it and invent your own. besides, you may just call `receiveTimeout()` with small timeout (not zero, there *was* a bug with zero == infinity) in your thread even if you aren't using standard message passing mechanics; it is completely harmless.
Re: syntax sugar: std.path::buildPath instead of from!"std.path".buildPath
On Thursday, 16 February 2017 at 13:21:04 UTC, Andrei Alexandrescu wrote: On 2/16/17 7:11 AM, Atila Neves wrote: On Wednesday, 15 February 2017 at 17:10:26 UTC, Adam D. Ruppe wrote: On Wednesday, 15 February 2017 at 07:56:00 UTC, Jacob Carlborg wrote: Your documentation is an improvement but it doesn't help when reading the source code. Yeah, I think there's a few things we can do in the source too. We should find the common combinations and abstract them out, like I said before, isInputRangeOf is potentially useful. Though, like Andrei, I'm skeptical on doing too much of that, since the combinations can quickly explode and then you just have to search through more to figure out wtf they mean. That'd help the source and docs if we find the right balance. I submitted a Phobos PR for `isInputRangeOf`. It was nuked from orbit. I understand why: as you mention, the combinatorial explosion of names is an issue. But: it's a mess rangeifying code when this: void fun(Foo[] foos); // yay! readable becomes: void fun(R)(R foos) if(isInputRange!R && is(Unqual!(ElementType!R) == Foo); If you find a number of these, that would be good evidence. -- Andrei I found just over 70 similar lines, which is more than I expected given how generic Phobos is. The real issue is in client code though. I write less range-based code than I'd like, because it's a lot easier to make it a regular array and change it later if the function needs to be called with other ranges. Atila
Re: D on the Weekends
On Wednesday, 22 February 2017 at 11:33:40 UTC, XavierAP wrote: purpose programming)?? And that the volume of weekday commits, at least in GitHub, is dominated by niche and legacy languages, plus Matlab? I believe he tried to build a list of languages that are not used both on weekdays and on weekends. Not sure what anyone would want to know anything about that? Clickbait?
Re: FEM library?
@Nicholas yes such a FEM library to be developed would heavily depend on Mir. Ilya Yaroshenko pointed me to it in another thread. I didn't know about DlangScience, thanks. Looks like there is some overlap? @Dukc thanks! Whenever in the future I'm developing for a library project or following it... Looks like those development threads currently go in the General board? Wouldn't it be better to split them together into one board within the Development section? Looks like inside General, library/project threads get lost and buried too quickly. I know many/most people are using this via email though, but still.
Re: D on the Weekends
On Sunday, 12 February 2017 at 05:50:09 UTC, Adam Wilson wrote: Somebody did some analytics on what languages get used on the weekends and D made the list. https://medium.com/@hoffa/the-top-weekend-languages-according-to-githubs-code-6022ea2e33e8#.2jmihhgb2 Am I reading it correctly that D is the second most popular general purpose language (let's exclude GLSL form general purpose programming)?? And that the volume of weekday commits, at least in GitHub, is dominated by niche and legacy languages, plus Matlab?
Re: Threads not garbage collected ?
On Wednesday, 22 February 2017 at 08:28:48 UTC, ketmar wrote: Alex wrote: import core.thread; class A { Thread mThread; bool mStopped; this() { mThread = new Thread(); mThread.start(); } void run() { while (!mStopped) { //do stuff } } ~this() { mStopped = true; mThread.join(); } } this code is invalid. when `~this()` is called, your `mThread` *may* already be dead -- this is how GC works. you *may* *not* access heap-allocated members in `~this()`, this is a bug. it may work sometimes, but it isn't guaranteed. Agreed, I don't want to have a ~this(), I have added it to prevent my program from hanging. As is often the case with these examples, it is a distillation of a much larger project. The point is that the thread object could be 20 layers of encapsulation down in a library. The thread could also be added 20 layers down long after the main function was written and tested. The thread can then prevent the program from exiting on exception or otherwise. If the garbage collector doesn't kill threads, do I need to break all encapsulation to call some sort of finalise or destroy function on every object in case it has a thread object in it ? It would probably be better to have all core.thread.Threads registered in the run time so they can be killed when main exits.
Re: Enough D to Make a Living?
On Wednesday, 22 February 2017 at 09:09:45 UTC, Russel Winder wrote: is also proven. However there is a caveat, that the new language must have a new computational model or at least a significant breaking change in something associated with the computational model. This is probably quite true, of course the more you get used to a particular model the more you feel that other languages are restraining your ability to express yourself... Learning C++, then D, then Rust for example will have benefit because there are new things there even though the core computational model is effectively the same – they have differences that matter. Maybe. I think "modern" C++ is a in class of it's own at this point. It is now quite detached from it's root: C with classes. Not so much for the computational model as for all the patterns you ought to follow and not nearly enough constraints from the compiler on what you should not do. With modern C++ you either have to go for being proficient or end up feeling miserable. Which is quite different from most imperative languages I think. Other than C++ I think most imperative Algol-like languages are in the same mold. The core difference is between system programming that requires hardware knowledge, but then the model is the hardware and not really the language. If you know 2-3 of them (e.g. C, TypeScript, Java) then getting into the others don't really require all that much.
Re: Threads not garbage collected ?
On Wednesday, 22 February 2017 at 05:39:50 UTC, rikki cattermole wrote: On 22/02/2017 6:28 PM, Alex wrote: import core.thread; class A { Thread mThread; bool mStopped; this() { mThread = new Thread(); mThread.start(); } void run() { while (!mStopped) { //do stuff } } ~this() { mStopped = true; mThread.join(); } } void main() { auto a = new A; delete a;//need this or the program hangs } In both gdc and dmd I need to use manually delete this object or the program is blocked after main. Is by design ? It seems undesirable, as the thread can be many layers of encapsulation down, and they all need manual deletes. Well, you never told the program to stop without delete. The thread that you start with (calls the main function) doesn't actually have to stay alive throughout the program running, surprise! Anyway, if you do want something that will stop try: import core.thread; import core.time; import std.stdio; class Foo : Thread { bool keepRunning; this() { keepRunning = true; super(); } private void run() { while(keepRunning) { sleep(1.seconds); writeln("iterate"); } } } void main() { Foo foo = new Foo; foo.start; Thread.sleep(3.seconds); foo.keepRunning = false; } That is interesting, I did not know that the main thread could exit without returning control to the calling process. Maybe this should be the case if we were writing in raw C against OS threading calls, but in this case I clearly have a thread Object not just an OS Handle, and I think most people would have an expectation that the garbage collector looks after deleting things in a garbage collected language when all the references are gone. I have also tested throwing an exception in main, and yes the program hangs. This is even more of a problem because this undesirable behaviour may only be observed under exceptional circumstances.
Re: Getting nice print of struct for debugging
On Tuesday, 21 February 2017 at 14:02:54 UTC, Jacob Carlborg wrote: [...] Yes, this works, I would say this is the simplest: MyStruct s; foreach (index, name ; FieldNameTuple!MyStruct) writefln("%s: %s", name, s.tupleof[index]); If you want something more close to "send" in Ruby, you need to use a string mixin, like this: foreach (name ; FieldNameTuple!MyStruct) writefln("%s: %s", name, mixin("s." ~ name)); The string mixin example works for methods, opDispatch and similar as well. The tupleof example, the first one, works only for fields. Exactly what I was looking for, **thank you!** Both ways of accessing the struct elements are very interesting, giving an impression what is possible with D. Is it possible to overwrite "toString" for all structs in one step? Regards mt.
Re: Moonshot: a DMD fork that outputs Lua
On Tuesday, 21 February 2017 at 21:32:51 UTC, pineapple wrote: On Tuesday, 21 February 2017 at 12:45:47 UTC, Mithun Hunsur wrote: Hi all, I've been working on a little project over the last month and a half, inspired by Adam's dtojs (https://github.com/adamdruppe/dtojs). I've always wanted a typed, powerful, embeddable scripting language, but found the contenders lacking - which is why I decided to hack up DMD to emit Lua. This is awesome. Great work! Is there an easy way to see compiler output for some example programs? I encourage you to submit a dconf talk - I know I'd like to hear more about this - just mind that the submission deadline is coming up in a few days. Thanks for the feedback! There's no easy way of seeing compiler output, but I've included a few samples here: https://gist.github.com/Philpax/79501f24c22f0b8582252d800bd28dbc. The codegen's pretty bad - there's been little effort to optimise it - but hopefully it will improve over time. I'm aware of the deadline; just wanted to make sure I had a chance to get feedback first.
Re: Hello, folks! Newbie to D, have some questions!
On Wednesday, 22 February 2017 at 07:48:42 UTC, Steve Biedermann wrote: On Tuesday, 21 February 2017 at 17:13:30 UTC, timmyjose wrote: I would upvote you if I could! :-) ... that's not only an interesting read, but also fodder for mini-projects of my own! If you need more details about a specific topic, just post it in the forum and we will try to help :) If you want some sourcecode to look at you can write me a mail and I can give you access to some of my tools. The ones which are stored on bitbucket are pretty simple to understand, but not quite ready for public release (no polishing etc.). Thanks, Steve. That'd be great! I will surely take you up on that offer. Right now I'm working through "Learning D", and loving every bit of it! From there I plan to get right down to coding on some small but interesting projects, and any help I can get would be most welcome! :-)
Re: Vibe.d: Listening to port 8080 on external device doesn't work
On Wednesday, 22 February 2017 at 00:38:30 UTC, aberba wrote: Using vibe.d, I bind to port 8080 at 127.0.0.1 but I can't access server on my phone through hotspot using the external IP from ip addr on Linux. But 127.0.0 running Apache server works. Don't if its vibe.d or OS (ubuntu 14.04) How do I reached my vibe.d server in this case on my phone? Not forget to open 8080 port of incoming connections.
Re: Enough D to Make a Living?
On Tue, 2017-02-21 at 13:32 -0500, Nick Sabalausky (Abscissa) via Digitalmars-d wrote: > On 02/21/2017 10:34 AM, Paul wrote: > > 3) Is there much value in taking programming classes that don't > > deal > > with D? > > Although HR folk never understand this, programming skills are > highly > transferable across languages. So yes, it's definitely worthwhile: > Getting better with one language will help you be a better programmer > in > other languages. The psychology of programming people have incontrovertible evidence that the very best programmers are able to work to a high level in many different programming languages (there are many references for this, see the work by Petre, Green, Sharp, etal.). The hypothesis that learning to a real working level a new language increases competence on all previously known language that you still have working knowledge of is also proven. However there is a caveat, that the new language must have a new computational model or at least a significant breaking change in something associated with the computational model. So if you know C then learning Haskell has great benefit. Then learning List has great benefit. But then learning Scheme will have little benefit. Learning C++, then D, then Rust for example will have benefit because there are new things there even though the core computational model is effectively the same – they have differences that matter. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: How do I use CTFE to generate an immutable associative array at compile time?
Yes this is how I mean it. Dne 22. 2. 2017 9:05 napsal uživatel "Jacob Carlborg via Digitalmars-d-learn": > On 2017-02-21 23:49, H. S. Teoh via Digitalmars-d-learn wrote: > > That may appear to work, but I would *strongly* recommend against it, >> because what happens when you use enum with an AA, is that the AA will >> be created *at runtime*, *every single time* it is referenced. (It is >> as if you copy-n-pasted the entire AA into the code each time you >> reference the enum.) Which will introduce ridiculous amounts of >> redundant work at runtime and cause a big performance penalty. >> > > You can use an enum to declare the AA and then assign it to an immutable > variable using "static this". The you would only use to the immutable > variable and never the enum. > > enum aa = [1 : 2]; > > immutable int[int] iaa; > > static this() > { > iaa = aa; > } > > -- > /Jacob Carlborg >
Re: Threads not garbage collected ?
On Wednesday, 22 February 2017 at 08:20:41 UTC, Jonathan M Davis wrote: Well, the OP's code wrapped the Thread object in another class and joined the thread in its finalizer, so you would think that the Thread would be joined before its finalizer was called, but thinking further on it, IIRC, there's no guarantee that the GC wouldn't try and collect the Thread object before calling the finalizer (since there are no other references to the Thread). So, I suppose that it could fail because of that. But if that doesn't happen, it should work, because the wrapper calls join rather than simply letting the Thread be destroyed. True – I was thinking of the subclassing example also shown above. In any case, I don't know if manually running a collection like I showed would work or not, but if not, I wouldn't expect calling join in a finalizer to work in general. Yes, it wouldn't work in general – mThread isn't guaranteed to be around any longer in ~this() for a normal object (although the thread lifetime relationship mentioned above complicates the analysis here somewhat, and if the thread is never stopped somewhere else, it might just as well work by accident). — David
Re: Threads not garbage collected ?
Alex wrote: import core.thread; class A { Thread mThread; bool mStopped; this() { mThread = new Thread(); mThread.start(); } void run() { while (!mStopped) { //do stuff } } ~this() { mStopped = true; mThread.join(); } } this code is invalid. when `~this()` is called, your `mThread` *may* already be dead -- this is how GC works. you *may* *not* access heap-allocated members in `~this()`, this is a bug. it may work sometimes, but it isn't guaranteed.
Re: Threads not garbage collected ?
On Wednesday, February 22, 2017 07:58:45 David Nadlinger via Digitalmars-d wrote: > On Wednesday, 22 February 2017 at 07:14:27 UTC, Jonathan M Davis > > wrote: > > In this particular case, the program would probably exit if you > > did > > > > void main() > > { > > > > { > > > > auto a = new A; > > > > } > > > > import core.memory; > > GC.collect(); > > > > } > > I very much doubt so. A Thread object isn't just a handle or > thread reference, but also encapsulates some of the > system/druntime state required to make threading work. Executing > Thread.~this() while a thread was still running would lead to a > crash. > > (The tricky part is to make sure the Thread object becomes > eligible for collection once a thread has actually finished.) Well, the OP's code wrapped the Thread object in another class and joined the thread in its finalizer, so you would think that the Thread would be joined before its finalizer was called, but thinking further on it, IIRC, there's no guarantee that the GC wouldn't try and collect the Thread object before calling the finalizer (since there are no other references to the Thread). So, I suppose that it could fail because of that. But if that doesn't happen, it should work, because the wrapper calls join rather than simply letting the Thread be destroyed. In any case, I don't know if manually running a collection like I showed would work or not, but if not, I wouldn't expect calling join in a finalizer to work in general. - Jonathan M Davis
Re: dmd -Wl=comma_separated_linker_flags (cf clang++ -Wl, comma_separated_linker_flags)
On 2017-02-21 03:53, Timothee Cour via Digitalmars-d wrote: relying on the shell (especially involving arrays) seems like a bad idea: not portable, easy to mess up: `dmd -L{-lbar,-Ldir,--export-dynamic}` works but what if it's stored in $lflags: lflags="-lbar,-Ldir,--export-dynamic" the function to convert $lflags to a dmd-appropriate flag is not so simple; what do you suggest for that case? You can pass multiple -L flags: dmd -L-lbar -L-Ldir -L--export-dynamic -- /Jacob Carlborg
Re: How do I use CTFE to generate an immutable associative array at compile time?
On 2017-02-21 23:49, H. S. Teoh via Digitalmars-d-learn wrote: That may appear to work, but I would *strongly* recommend against it, because what happens when you use enum with an AA, is that the AA will be created *at runtime*, *every single time* it is referenced. (It is as if you copy-n-pasted the entire AA into the code each time you reference the enum.) Which will introduce ridiculous amounts of redundant work at runtime and cause a big performance penalty. You can use an enum to declare the AA and then assign it to an immutable variable using "static this". The you would only use to the immutable variable and never the enum. enum aa = [1 : 2]; immutable int[int] iaa; static this() { iaa = aa; } -- /Jacob Carlborg
[Issue 17010] remove std.net.isemail
https://issues.dlang.org/show_bug.cgi?id=17010 Jacob Carlborgchanged: What|Removed |Added CC||d...@me.com --- Comment #2 from Jacob Carlborg --- (In reply to greenify from comment #0) > Very old module and only a port of the C module. > > This can be done a lot better via DUB packages, e.g. > > -> https://github.com/anton-dutov/mail > -> http://vibed.org/api/vibe.mail.smtp/Mail > > Proposed action: deprecate and move to undeaD It's actually ported from PHP, by request from Walter (or Andrei). --
Re: Threads not garbage collected ?
On Wednesday, 22 February 2017 at 07:14:27 UTC, Jonathan M Davis wrote: In this particular case, the program would probably exit if you did void main() { { auto a = new A; } import core.memory; GC.collect(); } I very much doubt so. A Thread object isn't just a handle or thread reference, but also encapsulates some of the system/druntime state required to make threading work. Executing Thread.~this() while a thread was still running would lead to a crash. (The tricky part is to make sure the Thread object becomes eligible for collection once a thread has actually finished.) — David