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: Best error msg ever

2017-02-11 Thread Profile Anaysis via Digitalmars-d
On Friday, 10 February 2017 at 03:07:28 UTC, Adam D. Ruppe wrote: On Friday, 10 February 2017 at 02:53:50 UTC, Era Scarecrow In cases like these i really wish the structure of the class/struct had a hash or something (based on source or struct layout or something) They do have different

Re: The extent of trust in errors and error handling

2017-02-05 Thread Profile Anaysis via Digitalmars-d
On Wednesday, 1 February 2017 at 19:25:07 UTC, Ali Çehreli wrote: tl;dr - Seeking thoughts on trusting a system that allows "handling" errors. One of my extra-curricular interests is the Mill CPU[1]. A recent discussion in that context reminded me of the Error-Exception distinction in

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?

array error msg improvement

2017-02-02 Thread Profile Anaysis via Digitalmars-d
Error Error: cannot append type int[] to type int[2][] This is because I tried to slice too small [0..1] when I was suppose to do [0..2](which passes). The error message is deceiving because it makes it look like the append can't happen when it can. Should be something

Re: Fix it for me!

2017-02-01 Thread Profile Anaysis via Digitalmars-d
On Tuesday, 31 January 2017 at 15:21:42 UTC, Vladimir Panteleev wrote: On Tuesday, 31 January 2017 at 13:11:22 UTC, Profile Anaysis wrote: The web interface could use a little work! 1. Tabs - I know that tabs are designed to move to different elements but you can override the default behavior

Fix it for me!

2017-01-31 Thread Profile Anaysis via Digitalmars-d
The web interface could use a little work! 1. Tabs - I know that tabs are designed to move to different elements but you can override the default behavior and make life quite a bit easier for most people(since most people have access to a mouse).

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

Re: A better way to deal with overloading?

2017-01-27 Thread Profile Anaysis via Digitalmars-d
On Friday, 27 January 2017 at 11:16:09 UTC, Patrick Schluter wrote: On Thursday, 26 January 2017 at 00:02:03 UTC, Profile Anaysis wrote: [...] It's funny (or sad) that C has compound types since C99 and that they are good. Your foo(|a,b,|c1,c2,3||,|e|,|f,g,c|) writes as

Re: A better way to deal with overloading?

2017-01-27 Thread Profile Anaysis via Digitalmars-d
On Friday, 27 January 2017 at 12:44:30 UTC, rjframe wrote: On Fri, 27 Jan 2017 10:38:53 +, Profile Anaysis wrote: Do you realize 1. That without change there can be no progress? ... If people with your mentality rules the world we would still be using sticks and stones. This is a

Re: A better way to deal with overloading?

2017-01-27 Thread Profile Anaysis via Digitalmars-d
On Friday, 27 January 2017 at 19:32:29 UTC, Jesse Phillips wrote: On Thursday, 26 January 2017 at 00:02:03 UTC, Profile Anaysis wrote: Many times we pass compound types(non-primitives) as arguments to functions. I don't understand what issue you are solving. I see an undefined syntax:

Re: A better way to deal with overloading?

2017-01-27 Thread Profile Anaysis via Digitalmars-d
On Friday, 27 January 2017 at 09:47:48 UTC, Bauss wrote: On Thursday, 26 January 2017 at 00:02:03 UTC, Profile Anaysis wrote: Many times we pass compound types(non-primitives) as arguments to functions. [...] This is going to be a no from me. It's just another syntactic sugar that doesn't

COMDAT error

2017-01-26 Thread Profile Anaysis via Digitalmars-d
test1.obj : fatal error LNK1179: invalid or corrupt file: duplicate COMDAT '_D4main4mainFAAyaZ16__T3recVii1TAAiZ3recMFNfAAiZv (@safe void main.main(immutable(char)[][]).rec!(1, int[][]).rec(int[][]))' code import std.stdio; import std.traits, std.meta, std.conv, std.string,

Allow static methods and fields for enum?

2017-01-25 Thread Profile Anaysis via Digitalmars-d
Why not make enum a comparable type to structs and classes? They are static so they can't contain any mutable fields but surely they can contain methods? And especially they should be able to contain static methods!?

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

A better way to deal with overloading?

2017-01-25 Thread Profile Anaysis via Digitalmars-d
Many times we pass compound types(non-primitives) as arguments to functions. e.g., void foo(T1 t1, T2 t2, T3, t3); But to call foo with new variables we have to create the arguments. This usually requires extra code to simply initialize the variables. (imagine foo being a constructor).

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

test.d(22): Error: cannot append type test.Path to type test.Path

2017-01-24 Thread Profile Anaysis via Digitalmars-d
test.d(22): Error: cannot append type test.Path to type test.Path This is due to the changing some code that was appending. Obviously we can't append a type to itself. Would be nice if the error message was more clear like: Type test.Path is not an array. Cannot append to itself.

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

Re: Writing a JFlex lexer for D - have an issue with cycles

2017-01-23 Thread Profile Anaysis via Digitalmars-d
On Monday, 23 January 2017 at 01:46:58 UTC, FatalCatharsis wrote: On Monday, 23 January 2017 at 00:46:30 UTC, Profile Anaysis wrote: The real issue is ambiguity. Any time you have a cycle you must be able to get out of it and so your rules must be organized so that one always checks to see if

Re: Writing a JFlex lexer for D - have an issue with cycles

2017-01-22 Thread Profile Anaysis via Digitalmars-d
On Sunday, 22 January 2017 at 22:11:08 UTC, FatalCatharsis wrote: I'm writing a flex lexer for D and I've hit a roadblock. It is almost working EXCEPT for one specific production. StringLiteral is cyclic and I don't know how to approach it. It is cyclic because: Token -> StringLiteral