Re: Reduce parameters [was pi program]
On Fri, 2015-09-25 at 12:54 +, John Colvin via Digitalmars-d-learn wrote: > […] > I vastly prefer the UFCS version, but unfortunately reduce has > its arguments the wrong way around for that if you use the > version that takes a seed... In which case the reduce parameter list is wrong, this is a bug and should be fixed. Is there a bug report for this I can connect with? -- 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
Can someone help me make a binary heap with std.container.binaryheap? It's not working... AssertError
Init: programResultsQ = heapify!(compareResults, Array!(Results!(O,I)))(Array!(Results!(O,I))([Results!(O,I)()]), 1); Decl: alias ProgramResultsQueue(O,I) = BinaryHeap!(Array!(Results!(O,I)), compareResults); Error: assert error in std.container.array.d (line 381) upon running. Compiles fine. I'd like to initialize the heap to empty if possible.
Re: ORM libraries for D
On 26/09/15 3:03 AM, John Colvin wrote: On Thursday, 24 September 2015 at 13:33:51 UTC, Rikki Cattermole wrote: On 25/09/15 1:30 AM, Edwin van Leeuwen wrote: On Thursday, 24 September 2015 at 13:24:14 UTC, Rikki Cattermole wrote: Dvorm is more or less feature complete :) I am the author of it, but unless issues come up I do not intend to continue working upon it. You could consider bumping it up to version 1.0.0 to highlight this. Put it this way, doing so would also bump it up on code.dlang.org. I have not even ran the unittests in like a year. So who knows if it compiles with 2.068. But nobody has complained so lets assume yes. TravisCI ? I would still want to rerun them for e.g. MongoDB provider. Who know's what has changed in vibe.d since.
Re: Threading Questions
Pretty please? :)
Re: What is the corect behavour for lazy in foreach variadic template
On 09/25/2015 09:38 AM, Artur Skawina via Digitalmars-d-learn wrote: On 09/25/15 17:47, Ali Çehreli via Digitalmars-d-learn wrote: Perhaps we need an enhancement that either works in your original code [...] His original code does work (`foreach` evaluates `args[N]` and assigns the result to `arg`). If he wanted to delay the evaluation, he would have written it like this: void test(T...)(lazy T args) { foreach(I, _; typeof(args)) { writeln("about to process arg"); writefln("processing arg %s",args[I]); } } artur Awesome! :) Ali
Re: Deduplicating Template Parameter List of std.variant.Algebraic
On Friday, 25 September 2015 at 18:11:51 UTC, Meta wrote: You can use http://dlang.org/phobos/std_meta.html#.NoDuplicates. I imagine this was an oversight in the implementation of Algebraic. Thanks
Re: Dub package with C code
Hello tired_eyes, tevDdl> Once again, I'm absolutely sure tha D should have an official tevDdl> blog! Forums can't replace blogs, forums are for discussions, not tevDdl> for content presentation. +1 on this. -- With best regards from Ukraine, Andre
Re: Capture characters from standard input without waiting for enter to be pressed
On 09/25/2015 09:04 AM, Martino wrote: As subject, I'm trying to read from stdin without waiting for enter to be pressed. How can I do? One solution: http://forum.dlang.org/post/mailman.2665.1300747084.4748.digitalmars-d-le...@puremagic.com Ali
Re: pi program
On Friday, 25 September 2015 at 12:51:17 UTC, Russel Winder wrote: Aha, bingo, spot on. Thanks. Amended now to: double reduce_string_loop() { return reduce!"a + 1.0 / (b * b)"(iota(1, 100)); } double reduce_function_loop() { return reduce!((t, n) => t + 1.0 / (n * n))(iota(1, 100)); } which both work as they should. I am sure I will be able to find a reason why I missed that reduce takes a function of two parameters not one. Interesting question on style is whether to use function application or method call: reduce!"a + 1.0 / (b * b)"(iota(1, 100)) vs. iota(1, 100).reduce!"a + 1.0 / (b * b)" The debate may well turn into a bikeshed one, but it would be good to know what the opinions are. The main difference is that "method call" style is more amenable to chaining (and IMO, it looks cleaner as you don't have nesting parentheses.
Re: Capture characters from standard input without waiting for enter to be pressed
On 9/25/15 12:04 PM, Martino wrote: As subject, I'm trying to read from stdin without waiting for enter to be pressed. How can I do? That is an issue with your terminal. You need to use a terminal configuration library to set it up to not buffer keystrokes until enter is pressed. I would not be the one to help you, the last time I did terminal control was about 20 years ago, but it probably hasn't changed much. And it's highly dependent on your environment. -Steve
Re: Can I check if a value is convertible to a valid value of an enum?
On Friday, 25 September 2015 at 03:20:24 UTC, Nicholas Wilson wrote: find + EnumMembers should do the trick if ( (EnumMembers!SomeType).canFind(value)) { // ... } Should be if (only(EnumMembers!SomeType).canFind(value)) { //... }
Re: Deduplicating Template Parameter List of std.variant.Algebraic
On Friday, 25 September 2015 at 16:08:41 UTC, Nordlöw wrote: How can a template parameter list be deduplicated or sorted? You can use http://dlang.org/phobos/std_meta.html#.NoDuplicates. I imagine this was an oversight in the implementation of Algebraic.
Re: What is the corect behavour for lazy in foreach variadic template
On 09/25/15 17:47, Ali Çehreli via Digitalmars-d-learn wrote: > Perhaps we need an enhancement that either works in your original code [...] His original code does work (`foreach` evaluates `args[N]` and assigns the result to `arg`). If he wanted to delay the evaluation, he would have written it like this: void test(T...)(lazy T args) { foreach(I, _; typeof(args)) { writeln("about to process arg"); writefln("processing arg %s",args[I]); } } artur
Re: Deduplicating Template Parameter List of std.variant.Algebraic
On Thursday, 24 September 2015 at 20:20:42 UTC, Nordlöw wrote: I just noticed that Algebraic doesn't deduplicate its types before construction because this compiles: import std.variant : Algebraic; auto x = Algebraic!(int, int)(5); Is this really sane? How can a template parameter list be deduplicated or sorted?
Capture characters from standard input without waiting for enter to be pressed
As subject, I'm trying to read from stdin without waiting for enter to be pressed. How can I do?
Re: What is the corect behavour for lazy in foreach variadic template
On 09/25/2015 05:56 AM, Sean Campbell wrote: Take the following code for example module test; import std.stdio; void test(T...)(lazy T args) I don't think that syntax is implemented. It looks valid to me though. There are many qualifier combinations that the compiler is silent about. I think this is one of those cases. Are you familiar with the 'Lazy variadic functions' feature? It works but as far as I understand it, all arguments must be of the same type: http://dlang.org/function.html As long as all 'int's are acceptable, the change to your code would be void test(int delegate()[] args...) There is the following related discussion: http://forum.dlang.org/post/ppcnyjpzcfptkoxkd...@forum.dlang.org I haven't tried it from but John Colvin's solution there probably has the same issue. Perhaps we need an enhancement that either works in your original code or lazy variadics to support something like the following: void test(T...)(T delegate()[] args...) Ali
Re: Dub package with C code
On Friday, 25 September 2015 at 12:25:52 UTC, tired_eyes wrote: I meant if there is already a place where I can upload my post to. Something like blog.dlang.org OT: Once again, I'm absolutely sure tha D should have an official blog! Forums can't replace blogs, forums are for discussions, not for content presentation. +1 It also encourages people to write guest pieces, because you know the work is not wasted as it reaches a broader audience. Also, as regards existing D blogs - Planet D was a great start but is a little bit tired. Some blogs are now defunct and haven't been updated for years. It would be great to still have a link to them, but they shouldn't be all mixed up - current and stale.
Re: Dub package with C code
On Friday, 25 September 2015 at 15:08:00 UTC, bachmeier wrote: On Friday, 25 September 2015 at 15:06:41 UTC, bachmeier wrote: First issue would be getting approval from Walter and Andrei. Second would be finding someone that knows how to do it. Should I create a new thread to open discussion on the topic? yes!
Threading Questions
Hey, I've got a few questions if anybody's got a minute. I'm trying to wrap my head around the threading situation in D. So far, things seem to be working as expected, but I want to verify my solutions. 1) Are the following two snippets exactly equivalent(not just in observable behaviour)? a) Mutex mut; mut.lock(); scope(exit) mut.unlock(); b) Mutex mut; synchronized(mut) { } Will 'synchronized' call 'lock' on the Mutex, or do something else(possibly related to the interface Object.Monitor)? 2) Phobos has 'Condition' which takes a Mutex in the constructor. The documentation doesn't exactly specify this, but should I assume it works the same as std::condition_variable in C++? For example, is this correct? Mutex mut; Condition cond = new Condition(mut); // mut must be locked before calling Condition.wait synchronized(mut) // depends on answer to (1) { // wait() unlocks the mutex and enters wait state // wait() must re-acquire the mutex before returning when cond is signalled cond.wait(); } 3) Why do I have to pass a "Mutex" to "Condition"? Why can't I just pass an "Object"? 4) Will D's Condition ever experience spurious wakeups? 5) Why doesn't D's Condition.wait take a predicate? I assume this is because the answer to (4) is no. 6) Does 'shared' actually have any effect on non-global variables beside the syntactic regulations? I know that all global variables are TLS unless explicitly marked as 'shared', but someone once told me something about 'shared' affecting member variables in that accessing them from a separate thread would return T.init instead of the actual value... or something like that. This seems to be wrong(thankfully). For example, I have created this simple Worker class which seems to work fine without a 'shared' keyword in sight(thankfully). I'm wondering though, if there would be any unexpected consequences of doing things this way. http://dpaste.com/2ZG2QZV Thanks! Bit
Re: Dub package with C code
On Friday, 25 September 2015 at 14:24:36 UTC, Adam D. Ruppe wrote: FYI, if you guys want to set something up for multiple contributors like a traditional blog, I'm willing to move TWID do it. I've been kinda wanting to do a blog thing but I just haven't brought myself to set anything up. That's a possibility too, but I like the idea of you continuing to do what you've been doing, and then on the blog there is an announcement of the new issue of TWID along with a short discussion and a link to the whole thing. d.announce is pretty busy these days. I've always felt those posts were more appropriate for an official blog. As would things like the subject of this thread, rather than letting it get buried in the forum. First issue would be getting approval from Walter and Andrei. Second would be finding someone that knows how to do it.
Re: Dub package with C code
On Friday, 25 September 2015 at 15:06:41 UTC, bachmeier wrote: First issue would be getting approval from Walter and Andrei. Second would be finding someone that knows how to do it. Should I create a new thread to open discussion on the topic?
Re: ORM libraries for D
On Thursday, 24 September 2015 at 13:33:51 UTC, Rikki Cattermole wrote: On 25/09/15 1:30 AM, Edwin van Leeuwen wrote: On Thursday, 24 September 2015 at 13:24:14 UTC, Rikki Cattermole wrote: Dvorm is more or less feature complete :) I am the author of it, but unless issues come up I do not intend to continue working upon it. You could consider bumping it up to version 1.0.0 to highlight this. Put it this way, doing so would also bump it up on code.dlang.org. I have not even ran the unittests in like a year. So who knows if it compiles with 2.068. But nobody has complained so lets assume yes. TravisCI ?
Re: ORM libraries for D
On Thursday, 24 September 2015 at 13:18:58 UTC, David Nadlinger wrote: Hi all, I'm having a look at ORM libraries in D right now. So far, I've come across hibernated and dvorm. Are there any other libraries that I should have a look at, particularly actively maintained ones? dvorm and hibernated seem to have received no work during the last couple of months. — David You can checkout dotter [1]. Also in this thread [2] Sebastiaan mentioned that he used at his work a custom built ORM solution. You can probably ask him for more details. [1]: https://github.com/rejectedsoftware/dotter [2]: http://forum.dlang.org/post/eixkzndqlqxxyjejb...@forum.dlang.org
Re: Dub package with C code
On Friday, 25 September 2015 at 14:15:20 UTC, bachmeier wrote: On Friday, 25 September 2015 at 12:25:52 UTC, tired_eyes wrote: Once again, I'm absolutely sure tha D should have an official blog! Forums can't replace blogs, forums are for discussions, not for content presentation. I've long agreed with that. Now that we have "This Week in D" we have a regular source for content. FYI, if you guys want to set something up for multiple contributors like a traditional blog, I'm willing to move TWID do it. I've been kinda wanting to do a blog thing but I just haven't brought myself to set anything up.
Re: Dub package with C code
On Friday, 25 September 2015 at 12:25:52 UTC, tired_eyes wrote: I meant if there is already a place where I can upload my post to. Something like blog.dlang.org OT: Once again, I'm absolutely sure tha D should have an official blog! Forums can't replace blogs, forums are for discussions, not for content presentation. I've long agreed with that. Now that we have "This Week in D" we have a regular source for content.
Re: final class & final methods
On Friday, 25 September 2015 at 10:28:56 UTC, ref2401 wrote: If I declare a class as `final` do I have to mark all methods of the class as `final` too? A final class can't be subclassed, so none of its methods can be overridden anyway.
What is the corect behavour for lazy in foreach variadic template
Take the following code for example module test; import std.stdio; void test(T...)(lazy T args) { foreach(arg;args) //bar is invoked here { writeln("about to process arg"); writefln("processing arg %s",arg); //but it should be invoked here, right? } } int bar() { writeln("bar invoked"); return 1; } void main() { test(bar()); } shouldn't bar be evaluated when writefln is called, not at the start of the loop.
Re: pi program
On Friday, 25 September 2015 at 12:51:17 UTC, Russel Winder wrote: On Fri, 2015-09-25 at 09:14 +, mzf via Digitalmars-d-learn wrote: [...] Aha, bingo, spot on. Thanks. Amended now to: double reduce_string_loop() { return reduce!"a + 1.0 / (b * b)"(iota(1, 100)); } double reduce_function_loop() { return reduce!((t, n) => t + 1.0 / (n * n))(iota(1, 100)); } which both work as they should. I am sure I will be able to find a reason why I missed that reduce takes a function of two parameters not one. Interesting question on style is whether to use function application or method call: reduce!"a + 1.0 / (b * b)"(iota(1, 100)) vs. iota(1, 100).reduce!"a + 1.0 / (b * b)" The debate may well turn into a bikeshed one, but it would be good to know what the opinions are. I vastly prefer the UFCS version, but unfortunately reduce has its arguments the wrong way around for that if you use the version that takes a seed...
Re: pi program
On Fri, 2015-09-25 at 09:14 +, mzf via Digitalmars-d-learn wrote: > > If we worry about the string form and instead try: > > > > double reduce_string_loop() { > > return reduce!"1.0 / (a * a)"(iota(1, 100)); > > } > > > > double reduce_function_loop() { > > return reduce!((n) => 1.0 / (n * n))(iota(1, 100)); > > } > > > > it should be write : > double reduce_loop() { >//return iota(1, 100).map!"1.0 / (a * a)".sum; >return iota(1, 100).reduce!"a + 1.0 / (b * b)"; > } Aha, bingo, spot on. Thanks. Amended now to: double reduce_string_loop() { return reduce!"a + 1.0 / (b * b)"(iota(1, 100)); } double reduce_function_loop() { return reduce!((t, n) => t + 1.0 / (n * n))(iota(1, 100)); } which both work as they should. I am sure I will be able to find a reason why I missed that reduce takes a function of two parameters not one. Interesting question on style is whether to use function application or method call: reduce!"a + 1.0 / (b * b)"(iota(1, 100)) vs. iota(1, 100).reduce!"a + 1.0 / (b * b)" The debate may well turn into a bikeshed one, but it would be good to know what the opinions are. -- 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: Dub package with C code
I meant if there is already a place where I can upload my post to. Something like blog.dlang.org OT: Once again, I'm absolutely sure tha D should have an official blog! Forums can't replace blogs, forums are for discussions, not for content presentation.
Re: final class & final methods
Am Fri, 25 Sep 2015 10:28:54 + schrieb ref2401 : > If I declare a class as `final` do I have to mark all methods of > the class as `final` too? No. -- Marco
final class & final methods
If I declare a class as `final` do I have to mark all methods of the class as `final` too?
Re: Dub package with C code
On Thursday, 24 September 2015 at 18:19:49 UTC, Laeeth Isharc wrote: On Thursday, 24 September 2015 at 02:43:20 UTC, Sebastiaan Koppe wrote: I have just created bindings for libxlsxwriter, an c library for creating excel files. Used the htod tool to do most of the work, and only had to adjust some things - mainly because libxlsxwriter uses data structures written in macro's. Right now I am making a dub package and I would like to aim for convenience for end-users (read: me). Therefor I decided to include the compiled static library inside the package. I only use Linux 64-bit myself, but this is obviously limiting for other people. The other option I had was to include the whole c code, depend on gcc or clang, and have dub (somehow) first build libxlsxwriter. But that seemed a bit too much... Another option would be to require end-users to build libxlsxwriter themselves. What do you guys recommend? nice work! worth a little blog post on the experience so others can be inspired by and benefit from yours? It seems this would be good content for the wiki. If we put this sort of thing there, others will start to look at the wiki, and Google will send them there. That wouldn't prevent anyone from also posting the same content on their own blog.
Re: pi program
If we worry about the string form and instead try: double reduce_string_loop() { return reduce!"1.0 / (a * a)"(iota(1, 100)); } double reduce_function_loop() { return reduce!((n) => 1.0 / (n * n))(iota(1, 100)); } it should be write : double reduce_loop() { //return iota(1, 100).map!"1.0 / (a * a)".sum; return iota(1, 100).reduce!"a + 1.0 / (b * b)"; }
Re: pi program
On Fri, 2015-09-25 at 06:02 +, Nicholas Wilson via Digitalmars-d -learn wrote: > On Friday, 25 September 2015 at 05:50:58 UTC, Charanjit Singh > wrote: > > import std.stdio; > > import std.math; > > void main() > > > > { > > float sum,pi,t; > > int n=1; > > sum=0; > > while (n<100 ) > > { > > t=1/( n*n); > > n=n+1; > > sum=sum+t; > > > > > >} > > writeln("value of PI= " , (sum*6)^^.5); > > that is pi program as > > (pi^2)/6= 1/1+ 1/4 + 1/9 + 1/16 + 1/25 > > but output of my program is 2.44 This looks a bit like K&R C transliterated to D. Much better to write more idiomatic D… > t=1/( n*n); //< > Is doing integer division so is zero for n > 1 hence sqrt(1*6) = > 2.449... > > change that to a > t=1.0/( n*n); That certainly solves the immediate problem. Taking the original code and making it more D-like, you get something like: double while_loop() { auto n = 1; auto sum = 0.0; while (n < 100) { sum += 1.0 / (n * n); n++; } return sum; } but this is bounded iteration not unbounded iteration, so let us use a far more idiomatic form: double foreach_loop() { auto sum = 0.0; foreach (n; 1..100) { sum += 1.0 / (n * n); } return sum; } but this is still very explicit iteration and we have moved on to the era of implicit iteration and declarative rather than imperative expression: double reduce_loop() { return reduce!"1.0 / (a * a)"(iota(1, 100)); } Unfortunately I have clearly done something silly here as: double take_root(double x) { return (x * 6)^^0.5; } void main() { writeln("while = " , take_root(while_loop())); writeln("foreach = " , take_root(foreach_loop())); writeln("reduce = " , take_root(reduce_loop())); } results in: while = 3.13198 foreach = 3.13198 reduce = 2.44949 If we worry about the string form and instead try: double reduce_string_loop() { return reduce!"1.0 / (a * a)"(iota(1, 100)); } double reduce_function_loop() { return reduce!((n) => 1.0 / (n * n))(iota(1, 100)); } then we end up with: /usr/include/dmd/phobos/std/algorithm/iteration.d(2565): Error: template pi_sumInverseSquares.reduce_function_loop.__lambda1 cannot deduce function from argument types !()(int, int), candidates are: pi_sumInverseSquares.d(28): pi_sumInverseSquares.reduce_function_loop.__lambda1 /usr/include/dmd/phobos/std/meta.d(546): Error: template instance pi_sumInverseSquares.reduce_function_loop.F!(__lambda1) error instantiating /usr/include/dmd/phobos/std/algorithm/iteration.d(2473):instantiated from here: staticMap!(ReduceSeedType, __lambda1) pi_sumInverseSquares.d(28):instantiated from here: reduce!(Result) pi_sumInverseSquares.d(28): Error: template std.algorithm.iteration.reduce cannot deduce function from argument types !((n) => 1.0 / (n * n))(Result), candidates are: /usr/include/dmd/phobos/std/algorithm/iteration.d(2447): std.algorithm.iteration.reduce(fun...) if (fun.length >= 1) Failed: ["dmd", "-v", "-o-", "pi_sumInverseSquares.d", "-I."] which is sort of annoying. -- 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: Dub package with C code
On Friday, 25 September 2015 at 06:04:09 UTC, Laeeth Isharc wrote: Blog platform - I guess nothing wrong with wordpress etc. I am between platforms right now. I just don't want to deal with wordpress any more, and haven't yet picked something I like better. Something like Nikola and dicebot's mood with an nginx proxy seems appealing. Mood is v nice but not quite mature / stable yet. I like idea of everything in D so it's easy to understand and extend as you wish. I meant if there is already a place where I can upload my post to. Something like blog.dlang.org I might go with mood. But I would probably dockerize it and run it behind jwilder/nginx-proxy.