Re: trick to make throwing method @nogc

2017-02-25 Thread Profile Anaysis via Digitalmars-d-learn
On Saturday, 25 February 2017 at 19:59:29 UTC, ikod wrote: Hello, I have a method for range: struct Range { immutable(ubyte[]) _buffer; size_t _pos; @property void popFront() pure @safe { enforce(_pos < _buffer.length, "popFront from empty buffer");

Re: simple static if / traits question...

2017-02-23 Thread Profile Anaysis via Digitalmars-d-learn
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

Re: simple static if / traits question...

2017-02-22 Thread Profile Anaysis via Digitalmars-d-learn
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)

Re: scope with if

2017-02-17 Thread Profile Anaysis via Digitalmars-d-learn
On Friday, 17 February 2017 at 20:06:19 UTC, berni wrote: I wonder if it's possible to do something like this: import std.stdio; void main(string[] args) { if (args[1]=="a") { write("A"); scope (exit) write("B"); } write("C"); } I expected the output to be ACB not

Re: Can't iterate over range

2017-02-04 Thread Profile Anaysis via Digitalmars-d-learn
On Saturday, 4 February 2017 at 14:35:37 UTC, ag0aep6g wrote: On 02/04/2017 12:31 PM, Profile Anaysis wrote: I am trying to iterate over the combinations of a set using the code https://rosettacode.org/wiki/Power_set#D I have an array which I call powerSet on and I get a result of MapResult.

Can't iterate over range

2017-02-04 Thread Profile Anaysis via Digitalmars-d-learn
I am trying to iterate over the combinations of a set using the code https://rosettacode.org/wiki/Power_set#D I have an array which I call powerSet on and I get a result of MapResult. I have tried to foreach or front/popFront and even each() on it but I can never get the result as the same

module specification for variables

2017-02-04 Thread Profile Anaysis via Digitalmars-d-learn
I'd like to have a global variable in a module but it must be accessed by the module name outside of the module. Sort of like a static variable in a class. private blocks it completely and public will allow it to be imported in to the global scope. Haven't tried protected but I assume that

Re: Fiber overhead

2017-02-03 Thread Profile Anaysis via Digitalmars-d-learn
On Saturday, 4 February 2017 at 06:54:01 UTC, Ali Çehreli wrote: On 02/03/2017 08:47 PM, Profile Anaysis wrote: What is the overhead of using a fiber? The performance overhead of call() and yield() are comparable to function calls because it's simply a few register assignments in each case.

Fiber overhead

2017-02-03 Thread Profile Anaysis via Digitalmars-d-learn
What is the overhead of using a fiber?

Re: Yield from function?

2017-01-31 Thread Profile Anaysis via Digitalmars-d-learn
On Tuesday, 31 January 2017 at 11:31:28 UTC, Ali Çehreli wrote: On 01/31/2017 03:00 AM, Profile Anaysis wrote: > [...] [...] > [...] return type. Options: [...] Thanks again!

Re: Yield from function?

2017-01-31 Thread Profile Anaysis via Digitalmars-d-learn
On Tuesday, 31 January 2017 at 06:32:02 UTC, Ali Çehreli wrote: On 01/30/2017 08:12 PM, Profile Anaysis wrote: import std.stdio, std.concurrency, core.thread; class Search : Fiber { this() { super(); } int res = 0; void start() { Fiber.yield(); res = 1; } }

Re: Yield from function?

2017-01-31 Thread Profile Anaysis via Digitalmars-d-learn
On Tuesday, 31 January 2017 at 06:32:02 UTC, Ali Çehreli wrote: On 01/30/2017 08:12 PM, Profile Anaysis wrote: [...] That's because the fiber is not in a callable state. (You can check with search.state.) Here is one where the fiber function lives (too) long: import std.stdio,

Re: Yield from function?

2017-01-30 Thread Profile Anaysis via Digitalmars-d-learn
On Monday, 30 January 2017 at 18:48:10 UTC, Ali Çehreli wrote: On 01/30/2017 03:03 AM, Profile Anaysis wrote: > I need to yield from a complex recursive function too allow visualizing > what it is doing. > > e.g., if it is a tree searching algorithm, I'd like to yield for each > node so that the

Re: Yield from function?

2017-01-30 Thread Profile Anaysis via Digitalmars-d-learn
On Monday, 30 January 2017 at 22:34:11 UTC, TheFlyingFiddle wrote: On Monday, 30 January 2017 at 11:03:52 UTC, Profile Anaysis wrote: I need to yield from a complex recursive function too allow visualizing what it is doing. e.g., if it is a tree searching algorithm, I'd like to yield for

Yield from function?

2017-01-30 Thread Profile Anaysis via Digitalmars-d-learn
I need to yield from a complex recursive function too allow visualizing what it is doing. e.g., if it is a tree searching algorithm, I'd like to yield for each node so that the current state can be shown visually. I realize that there are several ways to do this but D a yield version

Bug in generator

2017-01-30 Thread Profile Anaysis via Digitalmars-d-learn
the code from https://dlang.org/library/std/concurrency/generator.html gives a seg fault at the end. import std.concurrency; import std.stdio; void main() { auto tid = spawn( { while (true) { writeln(receiveOnly!int()); } }); auto r = new

Min, max of enum

2017-01-25 Thread Profile Anaysis via Digitalmars-d-learn
Since we do not have attributes for enums, I use _ in front of the names for meta values. I need to get the non-meta values for the enum so I can iterate over it and use it properly. enum myEnum { _Meta1 = 0, A,B,C, _Meta3 = 43, D = 3, } The num, for all practical purposes

Re: Trying to understand multidimensional arrays in D

2017-01-25 Thread Profile Anaysis via Digitalmars-d-learn
On Thursday, 26 January 2017 at 03:02:32 UTC, Jonathan M Davis wrote: On Thursday, January 26, 2017 01:47:53 Profile Anaysis via Digitalmars-d- learn wrote: [...] Like in C/C++, types are mostly read outward from the variable name in D. In both C/C++ and D, [...] Actually, I think

Re: Trying to understand multidimensional arrays in D

2017-01-25 Thread Profile Anaysis via Digitalmars-d-learn
On Thursday, 26 January 2017 at 03:02:32 UTC, Jonathan M Davis wrote: On Thursday, January 26, 2017 01:47:53 Profile Anaysis via Digitalmars-d- learn wrote: [...] Like in C/C++, types are mostly read outward from the variable name in D. In both C/C++ and D, [...] Thanks. I'll just

Re: Trying to understand multidimensional arrays in D

2017-01-25 Thread Profile Anaysis via Digitalmars-d-learn
On Thursday, 26 January 2017 at 02:29:07 UTC, Ivan Kazmenko wrote: On Thursday, 26 January 2017 at 01:47:53 UTC, Profile Anaysis wrote: does this mean that have int[][4][4] matrix_history; backwards? int[4][4][] matrix_history; this creates even a more set of problems. In short,

Trying to understand multidimensional arrays in D

2017-01-25 Thread Profile Anaysis via Digitalmars-d-learn
I'm a bit confused by how D does arrays. I would like to create a array of matrices but I do not seem to get the correct behavior: int[][4][4] matrix_history; What I would like is to have a 4x4 matrix and have a history of it. Just n 4x4 matrices but each matrix is a fixed size but

Can compiler profile itself?

2017-01-24 Thread Profile Anaysis via Digitalmars-d-learn
I am trying to compile some code and it takes around 6 seconds. Even if I change one line in one module, it takes the same time. There are about 20 different d modules. I used to get around 1-2 second compile times several months ago on different projects. I did upgrade a few things and it

Re: Is it possible to "cache" results of compile-time executions between compiles?

2017-01-24 Thread Profile Anaysis via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 21:36:50 UTC, Profile Anaysis wrote: ... Maybe with all this talk of the new CTFE engine being developed, a similar mechanism can be used optionally? This could help with debugging also. In debug mode, the cfte mixin's are written to disk with hash, if they

Re: Is it possible to "cache" results of compile-time executions between compiles?

2017-01-24 Thread Profile Anaysis via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 16:49:03 UTC, TheFlyingFiddle wrote: On Tuesday, 24 January 2017 at 16:41:13 UTC, TheFlyingFiddle wrote: Everything turned out s much better than expected :) Added bonus is that mixin output can be viewed in the generated files :D Could you post your