Re: faster "stringification"
On Sunday, 11 December 2016 at 02:09:41 UTC, Orut wrote: D nub here. I have a Python script that I'd like to implement in D. For certain parts, the D equivalent was slower than Python's. For example, Python code: #dummy code s = ["abc", "fjkd", "L", "qwa", "r", "uw", "tiro", "bc", "sg", "k", "jds", "yd"]; for i in range(1000): # a lot of array to string conversions '-'.join(s)# not assigning this to a variable to simplify comparison D code: import std.stdio; import std.array; void main(string[] args){ string[] s = ["abc", "fjkd", "L", "qwa", "r", "uw", "tiro", "bc", "sg", "k", "jds", "yd"]; for(int i; i<10_000_000; i++) s.join("-"); //see Python comments } Python was 2x faster. How should I implement this in D? join performs allocations which is probably the reason for its slowness. There is joiner (in std.algorithm.iterations) that lazily performs the join, (though in the case of this "benchmark" will be cheating because you don't do anything with the result, print it to get a more fair comparison) avoiding allocation. see also appender (in std.array) for fast concatenation.
Re: faster "stringification"
On Sunday, 11 December 2016 at 02:09:41 UTC, Orut wrote: D nub here. I have a Python script that I'd like to implement in D. For certain parts, the D equivalent was slower than Python's. For example, Python code: #dummy code s = ["abc", "fjkd", "L", "qwa", "r", "uw", "tiro", "bc", "sg", "k", "jds", "yd"]; for i in range(1000): # a lot of array to string conversions '-'.join(s)# not assigning this to a variable to simplify comparison D code: import std.stdio; import std.array; void main(string[] args){ string[] s = ["abc", "fjkd", "L", "qwa", "r", "uw", "tiro", "bc", "sg", "k", "jds", "yd"]; for(int i; i<10_000_000; i++) s.join("-"); //see Python comments } Python was 2x faster. How should I implement this in D? Preallocate a static array for your result.
faster "stringification"
D nub here. I have a Python script that I'd like to implement in D. For certain parts, the D equivalent was slower than Python's. For example, Python code: #dummy code s = ["abc", "fjkd", "L", "qwa", "r", "uw", "tiro", "bc", "sg", "k", "jds", "yd"]; for i in range(1000): # a lot of array to string conversions '-'.join(s)# not assigning this to a variable to simplify comparison D code: import std.stdio; import std.array; void main(string[] args){ string[] s = ["abc", "fjkd", "L", "qwa", "r", "uw", "tiro", "bc", "sg", "k", "jds", "yd"]; for(int i; i<10_000_000; i++) s.join("-"); //see Python comments } Python was 2x faster. How should I implement this in D?
Re: Hosting vibe.d on OpenShift
On Saturday, 10 December 2016 at 17:54:58 UTC, aberba wrote: On Thursday, 8 December 2016 at 20:37:23 UTC, Tiberiu Gal wrote: On Thursday, 8 December 2016 at 14:03:35 UTC, aberba wrote: I would like to try vibe.d with mongoDB on OpenShit. I managed to do that on Heroku. Do I need a buildpack like vibe.d? Any help will be really appreciated. I've tried to create a vibe cartridge but cannot because of memory limitations. The easiest way: You should build locally and deploy the executable Aawsh!! Cartridges are for OpenShift v2 and earlier, I would highly recommend trying OpenShift v3 instead. OpenShift v3 switched to using Docker (as well as Kubernetes) so if there is a vibe.d docker package or you can get it packaged in docker yourself it should run in OpenShift just fine. Note that v3 is in developer preview for Online, however I'd suggest using either Red Hat's CDK (https://developers.redhat.com/products/cdk/overview/) or Minishift (https://github.com/minishift/minishift) as an easy way to play around with it.
Re: mkdir; remove; under Windows throw Exception
On Saturday, 10 December 2016 at 18:30:53 UTC, Adam D. Ruppe wrote: On Saturday, 10 December 2016 at 18:09:43 UTC, unDEFER wrote: I know, but why it works in Linux by Linux documentation? Coincidence. That detail is undefined in the D documentation which means the implementation is free to do whatever is easier for it in a platform-specific manner. OH, OK. Undocumented behavior is undocumented behavior...
Re: [Semi-OT] I don't want to leave this language!
On Monday, 5 December 2016 at 20:25:00 UTC, Ilya Yaroshenko wrote: Hi e-y-e, The main problem with D for production is its runtime. GC, DRuntime, Phobos is big constraint for real world software production. The almost only thing I do is real world software production (basically math and optimized math methods). D with it's GC, DRuntime and Phobos makes it what I really like and need for. I do my own libs for my own needs. Perhaps some day I will use Mir, but I don't care if it is with or without D's standard libs. Igor Shirkalin.
Re: mkdir; remove; under Windows throw Exception
On Saturday, 10 December 2016 at 18:09:43 UTC, unDEFER wrote: I know, but why it works in Linux by Linux documentation? Coincidence. That detail is undefined in the D documentation which means the implementation is free to do whatever is easier for it in a platform-specific manner.
Re: mkdir; remove; under Windows throw Exception
On Saturday, 10 December 2016 at 14:10:15 UTC, ag0aep6g wrote: On 12/10/2016 04:39 AM, unDEFER wrote: man remove: remove - remove a file or directory That's documentation for C, not for D. I know, but why it works in Linux by Linux documentation?
Re: Separate IP parts
On Saturday, 10 December 2016 at 13:25:13 UTC, Nicholas Wilson wrote: On Saturday, 10 December 2016 at 13:21:40 UTC, notna wrote: On Saturday, 10 December 2016 at 08:03:00 UTC, biozic wrote: [...] Well, you know, that's one of the not so great things about Dlang... you cannot even trust the provided examples, if there are any: [...] Those statements need to be inside a function. I guess that's the reputation complaints here a building up :)
Re: Hosting vibe.d on OpenShift
On Thursday, 8 December 2016 at 20:37:23 UTC, Tiberiu Gal wrote: On Thursday, 8 December 2016 at 14:03:35 UTC, aberba wrote: I would like to try vibe.d with mongoDB on OpenShit. I managed to do that on Heroku. Do I need a buildpack like vibe.d? Any help will be really appreciated. I've tried to create a vibe cartridge but cannot because of memory limitations. The easiest way: You should build locally and deploy the executable Aawsh!!
Re: mkdir; remove; under Windows throw Exception
On 12/10/2016 04:39 AM, unDEFER wrote: man remove: remove - remove a file or directory That's documentation for C, not for D. The function which removes only files named unlink. The D must guarantee the same behaviour of remove on all OSes. D has no obligation to follow C in function naming.
Re: Separate IP parts
On Saturday, 10 December 2016 at 13:21:40 UTC, notna wrote: On Saturday, 10 December 2016 at 08:03:00 UTC, biozic wrote: [...] Well, you know, that's one of the not so great things about Dlang... you cannot even trust the provided examples, if there are any: [...] Those statements need to be inside a function.
Re: Separate IP parts
On Saturday, 10 December 2016 at 08:03:00 UTC, biozic wrote: This would do the same. I wouldn't say it's a trick. import std.format : formattedRead; import std.stdio : writefln; string ipAddr = "192.168.1.54"; int a, b, c, d; formattedRead(ipAddr, "%d.%d.%d.%d", &a, &b, &c, &d); writefln("%s %s %s %s", a, b, c, d); Well, you know, that's one of the not so great things about Dlang... you cannot even trust the provided examples, if there are any: C:\Temp\D>more formattedReadIps.d import std.format; string s = "hello!124:34.5"; string a; int b; double c; formattedRead(s, "%s!%s:%s", &a, &b, &c); assert(a == "hello" && b == 124 && c == 34.5); C:\Temp\D>dmd -v formattedReadIps.d binaryC:\D\dmd2\windows\bin\dmd.exe version v2.072.1 configC:\D\dmd2\windows\bin\sc.ini parse formattedReadIps formattedReadIps.d(6): Error: unexpected ( in declarator formattedReadIps.d(6): Error: basic type expected, not "%s!%s:%s" formattedReadIps.d(6): Error: found '"%s!%s:%s"' when expecting ')' formattedReadIps.d(6): Error: no identifier for declarator formattedRead(s, _error_) formattedReadIps.d(6): Error: semicolon expected following function declaration formattedReadIps.d(6): Error: declaration expected, not ',' formattedReadIps.d(7): Error: declaration expected, not 'assert'
Re: function is not callable using argument types ()
On Saturday, 10 December 2016 at 08:41:56 UTC, Suliman wrote: import std.stdio; import std.concurrency; void main() { void sp(int i) { receive((int i) { writeln("i: ", i); }); } auto r = new Generator!int( { foreach(i; 1 .. 10) yield(i); }); foreach(e;r) { sp.send(e); //Error: function app.main.sp (int i) is not callable using argument types () } } What I am doing wrong? How "receive" can be named? Is it's method or what? Why it's without return type? Sp is not in global scope but defined in main. Therefore it does not participate in UFCS.
function is not callable using argument types ()
import std.stdio; import std.concurrency; void main() { void sp(int i) { receive((int i) { writeln("i: ", i); }); } auto r = new Generator!int( { foreach(i; 1 .. 10) yield(i); }); foreach(e;r) { sp.send(e); //Error: function app.main.sp (int i) is not callable using argument types () } } What I am doing wrong? How "receive" can be named? Is it's method or what? Why it's without return type?
Re: Separate IP parts
On Saturday, 10 December 2016 at 03:51:34 UTC, brocolis wrote: How do I separate IP parts with dlang? I found this very cool trick, with C++: http://stackoverflow.com/a/5328190 std::string ip ="192.168.1.54"; std::stringstream s(ip); int a,b,c,d; //to store the 4 ints char ch; //to temporarily store the '.' s >> a >> ch >> b >> ch >> c >> ch >> d; std::cout << a << " " << b << " " << c << " "<< d; I wonder what's the equivalent D code. This would do the same. I wouldn't say it's a trick. import std.format : formattedRead; import std.stdio : writefln; string ipAddr = "192.168.1.54"; int a, b, c, d; formattedRead(ipAddr, "%d.%d.%d.%d", &a, &b, &c, &d); writefln("%s %s %s %s", a, b, c, d);
Re: staticIota is easy
On Saturday, 10 December 2016 at 01:48:24 UTC, Ali Çehreli wrote: On 12/09/2016 05:34 PM, Stefan Koch wrote: On Friday, 9 December 2016 at 18:52:59 UTC, Ali Çehreli wrote: I thought I needed something like staticIota in a unittest to effect static foreach over a number range and I found one in druntime's implementation: https://github.com/dlang/druntime/blob/master/src/core/internal/traits.d#L106 (I wonder why that one is implemented in divide-and-conquer fashion. Perhaps due to faster compilation that way?) Yes it is. n log n instead of n^2 Makes sense. I was stopping my counting at n: both looked O(n) to me. :) How about my staticIota()? Is it n^2 inside the compiler? Ali it's O(n log n)*((n!)/some_really_large_number) Because the template-subsystem is it not really build for a abuse like AliasSeq. After a cut-off point the factorial factor will dominate.