Re: Weird const behavior

2018-12-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 20 December 2018 at 01:37:59 UTC, Simón Oroño wrote: The only difference (code-wise) is the `const` keyword. I've tried with both `ldc` and `dmd` with same result. Why is the output different when the variable is `const`? A const range cannot be iterated by a generic template

Weird const behavior

2018-12-19 Thread Simón Oroño via Digitalmars-d-learn
I have the following piece of code: `` #!/bin/env dub /+ dub.sdl: name: day2 +/ import std.algorithm.iteration : group; import std.stdio; void main() { const auto a = group("simon"); auto b = group("simon"); writeln(a == b); writeln(); writeln(a);

Re: chunkBy array at compile time

2018-12-19 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 19, 2018 at 02:01:28PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 12/19/18 1:30 PM, H. S. Teoh wrote: [...] > > For CTFE, though, we don't really care about calling popFront twice, > > so I surmise that we should be able to just use the original > > non-RefCounted

Re: chunkBy array at compile time

2018-12-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/19/18 1:30 PM, H. S. Teoh wrote: On Wed, Dec 19, 2018 at 01:19:28PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: On 12/19/18 12:20 PM, H. S. Teoh wrote: [...] It was originally a simple wrapper when I first submitted it, but Andrei requested to use RefCounted in order to

Re: chunkBy array at compile time

2018-12-19 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 19, 2018 at 01:19:28PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 12/19/18 12:20 PM, H. S. Teoh wrote: [...] > > It was originally a simple wrapper when I first submitted it, but > > Andrei requested to use RefCounted in order to work around the > > subrange

Re: chunkBy array at compile time

2018-12-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/19/18 12:20 PM, H. S. Teoh wrote: On Wed, Dec 19, 2018 at 10:38:06AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] Looking at the code for chunkBy, it seems to me that the implementation is quite complex for what in my head should be a simple wrapper... [...] It was

Re: chunkBy array at compile time

2018-12-19 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 19, 2018 at 10:38:06AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > Looking at the code for chunkBy, it seems to me that the > implementation is quite complex for what in my head should be a simple > wrapper... [...] It was originally a simple wrapper when I

Re: using dub to compile plugins

2018-12-19 Thread Codifies via Digitalmars-d-learn
On Wednesday, 19 December 2018 at 16:31:57 UTC, Andre Pany wrote: On Wednesday, 19 December 2018 at 14:08:10 UTC, Codifies wrote: On Wednesday, 19 December 2018 at 13:14:20 UTC, Andre Pany wrote: On Wednesday, 19 December 2018 at 12:57:14 UTC, Codifies wrote: [...] You can use dub sub

Re: Bug in shifting

2018-12-19 Thread Patrick Schluter via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 20:33:43 UTC, Rainer Schuetze wrote: On 14/12/2018 02:56, Steven Schveighoffer wrote: On 12/13/18 7:16 PM, Michelle Long wrote: byte x = 0xF; ulong y = x >> 60; Surely you meant x << 60? As x >> 60 is going to be 0, even with a ulong. It doesn't work as

Re: using dub to compile plugins

2018-12-19 Thread Andre Pany via Digitalmars-d-learn
On Wednesday, 19 December 2018 at 14:08:10 UTC, Codifies wrote: On Wednesday, 19 December 2018 at 13:14:20 UTC, Andre Pany wrote: On Wednesday, 19 December 2018 at 12:57:14 UTC, Codifies wrote: [...] You can use dub sub packages. Each plugin will be a dub package with its own dub descriptor

Re: Temporary @trusted scope

2018-12-19 Thread rikki cattermole via Digitalmars-d-learn
On 20/12/2018 5:02 AM, Jonathan M Davis wrote: On Wednesday, December 19, 2018 1:19:42 AM MST rikki cattermole via Digitalmars-d-learn wrote: On 19/12/2018 7:11 PM, Jonathan M Davis wrote: Really? I would have thought that that would be a pretty obvious optimization (especially if inlining is

Re: Temporary @trusted scope

2018-12-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, December 19, 2018 1:19:42 AM MST rikki cattermole via Digitalmars-d-learn wrote: > On 19/12/2018 7:11 PM, Jonathan M Davis wrote: > > Really? I would have thought that that would be a pretty obvious > > optimization (especially if inlining is enabled). > > Assembly doesn't lie. I'm

Re: Temporary @trusted scope

2018-12-19 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 13:52:29 UTC, Steven Schveighoffer wrote: On 12/18/18 6:29 AM, Simen Kjærås wrote: @safe unittest {     unsafe!({     fun(2);     });     unsafe!fun(2); } Wow, I really like this. The only real problem is that one generally searches for @trusted when

Re: Mixin operator 'if' directly

2018-12-19 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 19 Dec 2018 15:12:14 +, bauss wrote: > That's assuming that it's compile-time data though. > > If not then you can't do what you want to do. > > What you can do is wrap it in a function in the mixin template which you > just call after instantiating it. Or while instantiating it:

Re: chunkBy array at compile time

2018-12-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/19/18 3:20 AM, Andrey wrote: Hi, I have got this code: import std.array : array; import std.algorithm.mutation; import std.algorithm.iteration; import std.stdio; void main() {     string input = "sieviaghp";     enum data = ["emo", "emoze", "emow", "emuo", "evuo", "ete", "ie", "vuo",

Re: Mixin operator 'if' directly

2018-12-19 Thread bauss via Digitalmars-d-learn
On Wednesday, 19 December 2018 at 15:09:47 UTC, bauss wrote: On Wednesday, 19 December 2018 at 13:37:17 UTC, Andrey wrote: Hi, Here is a template mixin: mixin template create(alias input, uint index, alias data) { if(input.length < index) return; // ... some code } When I try to

Re: Mixin operator 'if' directly

2018-12-19 Thread bauss via Digitalmars-d-learn
On Wednesday, 19 December 2018 at 13:37:17 UTC, Andrey wrote: Hi, Here is a template mixin: mixin template create(alias input, uint index, alias data) { if(input.length < index) return; // ... some code } When I try to compile it, I get: Error: declaration expected, not if Is it

Re: using dub to compile plugins

2018-12-19 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 19 Dec 2018 12:57:14 +, Codifies wrote: > I could do this with a few simple rules in a Makefile, but I have no > clue how to achieve this using dub. If you need dub, you can create a wrapper script that generates the dub file for the plugins directory. Make is a lot better for this

Re: using dub to compile plugins

2018-12-19 Thread Codifies via Digitalmars-d-learn
On Wednesday, 19 December 2018 at 13:14:20 UTC, Andre Pany wrote: On Wednesday, 19 December 2018 at 12:57:14 UTC, Codifies wrote: [...] You can use dub sub packages. Each plugin will be a dub package with its own dub descriptor (sdl) file. For your main dub sdl you set targetType to None.

Re: Mixin operator 'if' directly

2018-12-19 Thread rikki cattermole via Digitalmars-d-learn
Mixin templates don't work on statements only declarations like structs.

Mixin operator 'if' directly

2018-12-19 Thread Andrey via Digitalmars-d-learn
Hi, Here is a template mixin: mixin template create(alias input, uint index, alias data) { if(input.length < index) return; // ... some code } When I try to compile it, I get: Error: declaration expected, not if Is it possible to mixin operator 'if' directly inside my template

Re: using dub to compile plugins

2018-12-19 Thread Andre Pany via Digitalmars-d-learn
On Wednesday, 19 December 2018 at 12:57:14 UTC, Codifies wrote: I am currently using this dub.sdl name"runz80" targetType "executable" lflags "libz80/libz80.a" however I will be creating a number of plugins, each plugin will consist of a single source file, I'd like the plugin

Re: using dub to compile plugins

2018-12-19 Thread Codifies via Digitalmars-d-learn
oh forgot to add just for extra pain while the main application won't need gtk, most of the plugins will...

using dub to compile plugins

2018-12-19 Thread Codifies via Digitalmars-d-learn
I am currently using this dub.sdl name"runz80" targetType "executable" lflags "libz80/libz80.a" however I will be creating a number of plugins, each plugin will consist of a single source file, I'd like the plugin source directory to be separate from main source directory and

Re: Doubt about this book: The D Programming Language

2018-12-19 Thread XavierAP via Digitalmars-d-learn
On Sunday, 16 December 2018 at 18:37:15 UTC, Marko wrote: On Amazon The D Programming Language has good reviews but it's 8 years old. So is this book still relevant today? Yes, I would recommend it. It is meant to be comprehensive but introductory, so many language or library changes since

chunkBy array at compile time

2018-12-19 Thread Andrey via Digitalmars-d-learn
Hi, I have got this code: import std.array : array; import std.algorithm.mutation; import std.algorithm.iteration; import std.stdio; void main() { string input = "sieviaghp"; enum data = ["emo", "emoze", "emow", "emuo", "evuo", "ete", "ie", "vuo", "sie", "w"]; enum index = 3;

Re: Temporary @trusted scope

2018-12-19 Thread rikki cattermole via Digitalmars-d-learn
On 19/12/2018 7:11 PM, Jonathan M Davis wrote: Really? I would have thought that that would be a pretty obvious optimization (especially if inlining is enabled). Assembly doesn't lie.

Re: Temporary @trusted scope

2018-12-19 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 19 December 2018 at 06:11:48 UTC, Jonathan M Davis wrote: Really? I would have thought that that would be a pretty obvious optimization (especially if inlining is enabled). I suppose that it doesn't entirely surprise me if dmd does a poor job of it, but I would have expected ldc

Re: Temporary @trusted scope

2018-12-19 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 12:42:12 UTC, rikki cattermole wrote: Yes except for ldc with -O3. ldc with -O2 generates the same code.