Re: relative benefit of .reserve and .length
On Friday, 29 April 2016 at 10:10:26 UTC, sigod wrote: How about `assumeSafeAppend`? Does it have any positive impact on performance? assumeSafeAppend made it even slower ... about 20x instead of 10x worse than the indexed assign. Release build, win32.
Re: Print a triangle
[snip] On Friday, 29 April 2016 at 13:20:47 UTC, Michael Coulombe wrote: Try this: iota(1,11).each!(a => writeln("#".replicate(a))) Yes, this is what I was looking for! It's my birthday today.
Re: D GUI Toolkit Comparison
On Friday, 29 April 2016 at 13:52:59 UTC, Nordlöw wrote: Could somebody briefly outline the different GUI toolkits available in D and how they differ especially in terms of cleverly the make use of all idioms available in the language aswell as in Phobos. For instance: DlangUI and Adams D Ruppe's `simpledisplay` https://wiki.dlang.org/GUI_Libraries I'm the author of Tkd[1] and wrote it to learn D in more depth and really enjoyed the flexibility of generic classes/functions/interfaces and mixins. Because Tkd is based on Tcl/Tk it was really hard to map the Tcl language and Tk toolkit to a sensible type hierarchy using inheritance. Using D gave me the opportunity to think a bit differently and compose types more simply while modeling the problem in a more intelligent way. I'm bias, but I love the simplicity of the finished code. A pattern I used throughout was this: class Foo : Bar { public auto baz(this T)(...) { ... return cast(T) this; } } Which allows chaining of methods with those of parent and child types, i.e: import tkd.tkdapplication; class Application : TkdApplication { private void exitCommand(CommandArgs args) { this.exit(); } override protected void initInterface() { auto frame = new Frame(2, ReliefStyle.groove) .pack(10); auto label = new Label(frame, "Hello World!") .pack(10); auto exitButton = new Button(frame, "Exit") .setCommand(&this.exitCommand) .pack(10); } } void main(string[] args) { auto app = new Application(); app.run(); } [1]: https://github.com/nomad-software/tkd
Re: Print a triangle
On Fri, Apr 29, 2016 at 11:45:39AM -0700, H. S. Teoh via Digitalmars-d-learn wrote: [...] > Unfortunately, due to some silly autodecoding issues in Phobos, > byCodeUnit is a necessary hack to make this work. I'll file a bug for > this. [...] https://issues.dlang.org/show_bug.cgi?id=15972 T -- Skill without imagination is craftsmanship and gives us many useful objects such as wickerwork picnic baskets. Imagination without skill gives us modern art. -- Tom Stoppard
Re: Print a triangle
On Fri, Apr 29, 2016 at 12:01:19PM +, Joel via Digitalmars-d-learn wrote: > On Friday, 29 April 2016 at 11:31:51 UTC, rikki cattermole wrote: > >Not entirely the goal I'm guessing output wise, but this works. > > > >import std.range : repeat; > >foreach(line; 1 .. 11) { > > writeln('#'.repeat(line)); > >} > > That is shorter than my foreach version, but I want one that doesn't > use foreach in it at all. Try this: auto triangle(int i) { import std.algorithm.iteration : map, joiner; import std.range : iota, repeat; import std.utf : byCodeUnit; // this is a hack return iota(i).map!(i => '#'.repeat(i)) .joiner("\n".byCodeUnit); } void main() { import std.stdio : writeln; writeln(triangle(10)); } Unfortunately, due to some silly autodecoding issues in Phobos, byCodeUnit is a necessary hack to make this work. I'll file a bug for this. T -- Today's society is one of specialization: as you grow, you learn more and more about less and less. Eventually, you know everything about nothing.
Re: D GUI Toolkit Comparison
On Friday, 29 April 2016 at 13:52:59 UTC, Nordlöw wrote: Could somebody briefly outline the different GUI toolkits available in D and how they differ especially in terms of cleverly the make use of all idioms available in the language aswell as in Phobos. For instance: DlangUI and Adams D Ruppe's `simpledisplay` simpledisplay isn't a gui toolkit really, it just does basic things like creating windows, handling events, and other associated foundation like clipboard access. You can access the native handles for it to expand though (and my minigui.d does that, but I'm still not happy with it). So simpledisplay is more like SDL than GTK. simpledisplay also makes zero effort to be clever, it is meant to be simple and tries not to use Phobos at all (avoiding phobos in a foundation library like this means faster compile times and smaller binaries if you stick to system libraries).
D GUI Toolkit Comparison
Could somebody briefly outline the different GUI toolkits available in D and how they differ especially in terms of cleverly the make use of all idioms available in the language aswell as in Phobos. For instance: DlangUI and Adams D Ruppe's `simpledisplay`
Re: Print a triangle
On Friday, 29 April 2016 at 12:01:19 UTC, Joel wrote: On Friday, 29 April 2016 at 11:31:51 UTC, rikki cattermole wrote: Not entirely the goal I'm guessing output wise, but this works. import std.range : repeat; foreach(line; 1 .. 11) { writeln('#'.repeat(line)); } That is shorter than my foreach version, but I want one that doesn't use foreach in it at all. Try this: iota(1,11).each!(a => writeln("#".replicate(a)))
Re: C header file: tagged enumerations
On Thursday, 28 April 2016 at 22:54:10 UTC, Jesse Phillips wrote: This one doesn't get the values right for the different versions. The other problem is functions are written as: void* something(INSTALLMESSAGE arg); So I could make all the functions take an int/uint or such, but that is a lot of change for the header along with less documenting. Different values depending on target version? That's weird, never seen anything like that in windows headers. enum { // 12 others ... INSTALLMESSAGE_INITIALIZE , INSTALLMESSAGE_TERMINATE , INSTALLMESSAGE_SHOWDIALOG } static if(_WIN32_MSI >= 500) enum { INSTALLMESSAGE_PERFORMANCE=15, INSTALLMESSAGE_RMFILESINUSE } else static if(_WIN32_MSI >= 400) enum INSTALLMESSAGE_RMFILESINUSE=15; static if(_WIN32_MSI >= 450) enum { INSTALLMESSAGE_INSTALLSTART=INSTALLMESSAGE_RMFILESINUSE+1, INSTALLMESSAGE_INSTALLEND } alias INSTALLMESSAGE=int;
Re: Print a triangle
On Friday, 29 April 2016 at 11:31:51 UTC, rikki cattermole wrote: Not entirely the goal I'm guessing output wise, but this works. import std.range : repeat; foreach(line; 1 .. 11) { writeln('#'.repeat(line)); } That is shorter than my foreach version, but I want one that doesn't use foreach in it at all.
Re: Print a triangle
On 29/04/2016 11:23 PM, Joel wrote: What is a quick way to print a triangle? I'm thinking without foreach, not like I have here. foreach(line; iota(1, 10 + 1)) { writeln("#".replicate(line)); } These don't work: iota(1, 10 + 1). tee!((a) => { writeln("#".replicate(a)); }); string result; iota(1, 10 + 1). tee!((a) => result ~= "#".replicate(a) ~ "\n"); writeln(result); Not entirely the goal I'm guessing output wise, but this works. import std.range : repeat; foreach(line; 1 .. 11) { writeln('#'.repeat(line)); }
Print a triangle
What is a quick way to print a triangle? I'm thinking without foreach, not like I have here. foreach(line; iota(1, 10 + 1)) { writeln("#".replicate(line)); } These don't work: iota(1, 10 + 1). tee!((a) => { writeln("#".replicate(a)); }); string result; iota(1, 10 + 1). tee!((a) => result ~= "#".replicate(a) ~ "\n"); writeln(result);
Re: relative benefit of .reserve and .length
On Thursday, 28 April 2016 at 14:08:26 UTC, Steven Schveighoffer wrote: On 4/28/16 8:56 AM, Jay Norwood wrote: [...] .reserve should make an improvement for large amount of appending, since you pre-allocate the data. [...] How about `assumeSafeAppend`? Does it have any positive impact on performance?
std.signals Can not connect a delegate without in Object
import std.signals; import std.stdio; class hh { mixin Signal!(); void haha(){emit();} } class ff { void show() { writeln("ff show"); } } void main() { auto h = new hh(); void show() { writeln("main show"); } auto f = new ff(); // h.connect(&f.show); // It is ok to work h.connect(&show); // will Segmentation fault 。 h.haha(); }