Re: shared attrribute

2013-03-14 Thread Jack Applegame
Thanks. I's much more clear now.

Re: Is this range behaviour correct?

2013-03-14 Thread Ali Çehreli
On 03/14/2013 04:58 PM, Jesse Phillips wrote: On Thursday, 14 March 2013 at 21:40:34 UTC, Ali Çehreli wrote: I had toyed with the idea of making a ForwardRange from an InputRange by caching the elements. Without any guarantees, :) here is the code: http://forum.dlang.org/thread/ifg5ei$2qc7$1...

Re: nice how D's pieces fit together

2013-03-14 Thread Jonathan M Davis
On Friday, March 15, 2013 03:41:14 anonymous wrote: > On Friday, 15 March 2013 at 02:31:32 UTC, anonymous wrote: > > Then it struck me: > > The compiler doesn't know that f's return value is unknown to > > the rest of the world, because f isn't marked pure. > > And, indeed, make f pure and it just

Re: nice how D's pieces fit together

2013-03-14 Thread bearophile
anonymous: The compiler doesn't know that f's return value is unknown to the rest of the world, because f isn't marked pure. And, indeed, make f pure and it just works: int[] f() pure {return [1, 2, 3];} immutable v = f(); Awesome! "purity" seems a simple idea, but if you try to implement i

Re: nice how D's pieces fit together

2013-03-14 Thread anonymous
On Friday, 15 March 2013 at 02:31:32 UTC, anonymous wrote: Then it struck me: The compiler doesn't know that f's return value is unknown to the rest of the world, because f isn't marked pure. And, indeed, make f pure and it just works: int[] f() pure {return [1, 2, 3];} immutable v = f(); Awe

nice how D's pieces fit together

2013-03-14 Thread anonymous
Just a little newbie aha moment I'd like to share. I was about to post this: int[] f() {return [1, 2, 3];} As far as I understand, f returns a fresh array on each call, and therefore, it should be safe to store the result in an immutable variable. Unfortunately, this fails: immutable v = f

Re: D locking strategies

2013-03-14 Thread estew
Ok, I did a bit more reading of TDPL and decided to go with the following pattern: synchronized class A{ private string[] _values; void setValue(size_t i, string val) {_values[i] = val;} string getValue(size_t i) const {return _values[i];} } Works fine, my problem solved :) Ag

Re: Array operation with boolean operator

2013-03-14 Thread bearophile
Marco Leise: This is "just" a syntax ambiguity. a[] takes the complete slice of the array 'a'. And a dynamic array in D is a slice. So if you use a or a[] in an expression doesn't make much of a difference. Yet in D the only accepted syntax to perform a vector op sum is to use add square brac

Re: Array operation with boolean operator

2013-03-14 Thread Marco Leise
Am Thu, 14 Mar 2013 22:15:11 +0100 schrieb "bearophile" : > Andrea Fontana: > > > But does sort!"a > See the difference in syntax: > > a < b > a[] < b[] > > Bye, > bearophile This is "just" a syntax ambiguity. a[] takes the complete slice of the array 'a'. And a dynamic array in D is a slice.

D locking strategies

2013-03-14 Thread estew
Hi All, I'm getting myself confused with thread-safety and locking. I have a class something like the following small example: class A{ private string[] _values; void setValue(size_t i, string val) {_values[i] = val;} string getValue(size_t i) conts {return _values[i];} const(

Re: Is this range behaviour correct?

2013-03-14 Thread Jesse Phillips
On Thursday, 14 March 2013 at 21:40:34 UTC, Ali Çehreli wrote: I had toyed with the idea of making a ForwardRange from an InputRange by caching the elements. Without any guarantees, :) here is the code: http://forum.dlang.org/thread/ifg5ei$2qc7$1...@digitalmars.com Ali I attempted to crea

Re: Lexer in D

2013-03-14 Thread Dmitry Olshansky
15-Mar-2013 01:17, Artur Skawina пишет: On 03/14/13 18:24, Dmitry Olshansky wrote: 14-Mar-2013 21:20, Namespace пишет: Yes, and it's really fun. :) By the way, the code can be found here: https://github.com/Dgame/Puzzle/blob/master/DLexer.d Maybe some of you have an idea how I could improve any

Re: Array operation with boolean operator

2013-03-14 Thread bearophile
Andrea Fontana: But does sort!"a See the difference in syntax: a < b a[] < b[] Bye, bearophile

Re: Lexer in D

2013-03-14 Thread Artur Skawina
On 03/14/13 18:24, Dmitry Olshansky wrote: > 14-Mar-2013 21:20, Namespace пишет: >> Yes, and it's really fun. :) >> By the way, the code can be found here: >> https://github.com/Dgame/Puzzle/blob/master/DLexer.d >> Maybe some of you have an idea how I could improve anything. >> Last trace.log is al

Re: Variadic function not recognizing static array length

2013-03-14 Thread Zach the Mystic
On Thursday, 14 March 2013 at 20:59:38 UTC, Zach the Mystic wrote: On Wednesday, 13 March 2013 at 22:14:26 UTC, Timon Gehr wrote: On 03/12/2013 10:47 PM, Zach the Mystic wrote: void func(string[2] a) {} void func2(T...)(T args) { static assert(is(typeof(args[0]) == string[2])); } void func3

Re: Variadic function not recognizing static array length

2013-03-14 Thread Zach the Mystic
On Wednesday, 13 March 2013 at 22:14:26 UTC, Timon Gehr wrote: On 03/12/2013 10:47 PM, Zach the Mystic wrote: void func(string[2] a) {} void func2(T...)(T args) { static assert(is(typeof(args[0]) == string[2])); } void func3(T...)(T args) { static assert(args[0].length == 2); } func([""

Re: Array operation with boolean operator

2013-03-14 Thread Andrea Fontana
On Thursday, 14 March 2013 at 18:41:25 UTC, bearophile wrote: Andrea Fontana: I always think X < Y return a single bool, Having a practice with NumPy and the like, I think X < Y as returning as many bools as the length of X and Y: from numpy import * a = array([1, 5, 1]) b = array([1, 1,

Re: Array operation with boolean operator

2013-03-14 Thread bearophile
Andrea Fontana: I always think X < Y return a single bool, Having a practice with NumPy and the like, I think X < Y as returning as many bools as the length of X and Y: from numpy import * a = array([1, 5, 1]) b = array([1, 1, 5]) a < b array([False, False, True], dtype=bool) Programme

Re: Array operation with boolean operator

2013-03-14 Thread Andrea Fontana
On Thursday, 14 March 2013 at 17:56:07 UTC, Ali Çehreli wrote: On 03/14/2013 10:45 AM, Andrea Fontana wrote: > You see? Your code do this: > > a[] = (b[] < c[]); I thought the same thing at first but note the brackets after b and c. Those should make this an array-wise operation. For all ele

Re: Array operation with boolean operator

2013-03-14 Thread Ali Çehreli
On 03/14/2013 10:45 AM, Andrea Fontana wrote: > You see? Your code do this: > > a[] = (b[] < c[]); I thought the same thing at first but note the brackets after b and c. Those should make this an array-wise operation. For all elements of a to be the same value, one would not write the bracke

Re: Array operation with boolean operator

2013-03-14 Thread Andrea Fontana
On Thursday, 14 March 2013 at 13:58:45 UTC, n00b wrote: I tried to use a boolean operator for an array operation : a[] = b[] < c[]; It compiles but seems to only fill a[] with the result of b[0] < c[0]. Is there any "rational" reason to that? Yes i think there is a rational reason. Check th

Re: Lexer in D

2013-03-14 Thread Dmitry Olshansky
14-Mar-2013 21:20, Namespace пишет: Yes, and it's really fun. :) By the way, the code can be found here: https://github.com/Dgame/Puzzle/blob/master/DLexer.d Maybe some of you have an idea how I could improve anything. Last trace.log is also there: https://github.com/Dgame/Puzzle/blob/master/trac

Re: Lexer in D

2013-03-14 Thread Namespace
Yes, and it's really fun. :) By the way, the code can be found here: https://github.com/Dgame/Puzzle/blob/master/DLexer.d Maybe some of you have an idea how I could improve anything. Last trace.log is also there: https://github.com/Dgame/Puzzle/blob/master/trace.log My goal is about 20 msecs.

Re: Lexer in D

2013-03-14 Thread Dmitry Olshansky
14-Mar-2013 21:20, Namespace пишет: Yes, and it's really fun. :) By the way, the code can be found here: https://github.com/Dgame/Puzzle/blob/master/DLexer.d Maybe some of you have an idea how I could improve anything. Last trace.log is also there: https://github.com/Dgame/Puzzle/blob/master/trac

Re: Array operation with boolean operator

2013-03-14 Thread Andrea Fontana
On Thursday, 14 March 2013 at 13:58:45 UTC, n00b wrote: I tried to use a boolean operator for an array operation : a[] = b[] < c[]; It compiles but seems to only fill a[] with the result of b[0] < c[0]. Is there any "rational" reason to that? And is there any way to use boolean operator for a

Re: Lexer in D

2013-03-14 Thread Dmitry Olshansky
14-Mar-2013 01:19, Namespace пишет: Array has an horrible code... I decided to start from scratch. So I took a close look at the lexer of dmd and took over the basic functionality. Result for std.datetime (without profiling so far): It's getting better! Total time (

Re: -cov doesn't check templated code

2013-03-14 Thread simendsjo
On Thursday, 14 March 2013 at 16:26:21 UTC, bearophile wrote: simendsjo: Would be nice to easily see that the templates are being tested more properly though. Then add an enhancement request in bugzilla. Maybe there is a way to implement it. I remember someone asking for a compiler switch

Re: -cov doesn't check templated code

2013-03-14 Thread bearophile
simendsjo: Would be nice to easily see that the templates are being tested more properly though. Then add an enhancement request in bugzilla. Maybe there is a way to implement it. I remember someone asking for a compiler switch that lists all the implemented templates... Bye, bearophile

Re: -cov doesn't check templated code

2013-03-14 Thread simendsjo
On Thursday, 14 March 2013 at 16:09:01 UTC, bearophile wrote: simendsjo: Code coverage doesn't work with templates. Is this by design? A code coverage tells how many time a line of code is run at run-time. But your template contains no code that is run at run-time. So you are looking for a

Re: Variadic function not recognizing static array length

2013-03-14 Thread Steven Schveighoffer
On Tue, 12 Mar 2013 17:47:00 -0400, Zach the Mystic wrote: void func(string[2] a) {} void func2(T...)(T args) { static assert(is(typeof(args[0]) == string[2])); } void func3(T...)(T args) { static assert(args[0].length == 2); } func(["",""]); // Okay func2(["",""]); // Error: (is(

Re: -cov doesn't check templated code

2013-03-14 Thread bearophile
simendsjo: Code coverage doesn't work with templates. Is this by design? A code coverage tells how many time a line of code is run at run-time. But your template contains no code that is run at run-time. So you are looking for a different kind of counter. Bye, bearophile

Re: Array operation with boolean operator

2013-03-14 Thread n00b
This has already been reported http://d.puremagic.com/issues/show_bug.cgi?id=5636

-cov doesn't check templated code

2013-03-14 Thread simendsjo
Code coverage doesn't work with templates. Is this by design? t.d: module t; template t(T) { static if(is(T == int)) alias int t; else static if(is(T == short)) alias short t; } unittest { t!int a = 10; assert(a == 10); }

Re: Array operation with boolean operator

2013-03-14 Thread bearophile
n00b: Is there any "rational" reason to that? It's not implemented (and it's a bug that it returns something different). Take a look in Bugzilla if it's already there. And is there any way to use boolean operator for array operations? I think the only supported boolean vec operation is

Re: Using D-object with C-executable

2013-03-14 Thread stas
Thanks Adam! You saved my day ;)

Re: shared attrribute

2013-03-14 Thread John Colvin
On Thursday, 14 March 2013 at 10:39:11 UTC, Jack Applegame wrote: What does mean attribute shared exactly for non global variables? Is it safe to cast to/from shared? For example, let us assume all data are synchronized properly. Is following code safe? import core.atomic; class A { int v

Re: Overhead when using a C library

2013-03-14 Thread John Colvin
On Thursday, 14 March 2013 at 00:52:41 UTC, Timon Gehr wrote: On 03/14/2013 01:48 AM, Jeremy DeHaan wrote: Hey guys! I am working on a binding for D, and am almost finished! I started to think of some things I might like to work on to improve the binding after I get everything working, and on

Re: Array operation with boolean operator

2013-03-14 Thread John Colvin
On Thursday, 14 March 2013 at 13:58:45 UTC, n00b wrote: I tried to use a boolean operator for an array operation : a[] = b[] < c[]; It compiles but seems to only fill a[] with the result of b[0] < c[0]. Is there any "rational" reason to that? And is there any way to use boolean operator for a

Re: Using D-object with C-executable

2013-03-14 Thread Adam D. Ruppe
gotta init the d runtime first extern (C) void startd() { Runtime.initialize(); } adn then in C, before using any other D, call startd();

Re: Is this range behaviour correct?

2013-03-14 Thread monarch_dodra
On Thursday, 14 March 2013 at 14:29:59 UTC, Andrea Fontana wrote: On Thursday, 14 March 2013 at 13:58:56 UTC, monarch_dodra wrote: On Thursday, 14 March 2013 at 13:20:51 UTC, Andrea Fontana wrote: On Thursday, 14 March 2013 at 12:29:26 UTC, Andrei Alexandrescu wrote: On 3/14/13 6:45 AM, Andrea

Using D-object with C-executable

2013-03-14 Thread stas
Hi guys! I'm trying to write D module for existing C/C++ project with no success :( What I'm doing: [code] dmd -g -w -c test.d gcc -g -Wall -Werror test.c test.o -ldruntime -lphobos2 -lrt -pthread -o test-app [/code] Executable is linked successfully, but fails with "Segmentation fault".

Re: Is this range behaviour correct?

2013-03-14 Thread Andrea Fontana
On Thursday, 14 March 2013 at 13:58:56 UTC, monarch_dodra wrote: On Thursday, 14 March 2013 at 13:20:51 UTC, Andrea Fontana wrote: On Thursday, 14 March 2013 at 12:29:26 UTC, Andrei Alexandrescu wrote: On 3/14/13 6:45 AM, Andrea Fontana wrote: On Thursday, 14 March 2013 at 10:08:53 UTC, Andrea

Re: Is this range behaviour correct?

2013-03-14 Thread monarch_dodra
On Thursday, 14 March 2013 at 13:20:51 UTC, Andrea Fontana wrote: On Thursday, 14 March 2013 at 12:29:26 UTC, Andrei Alexandrescu wrote: On 3/14/13 6:45 AM, Andrea Fontana wrote: On Thursday, 14 March 2013 at 10:08:53 UTC, Andrea Fontana wrote: I'm trying to implement a db cursor as simple Inpu

Array operation with boolean operator

2013-03-14 Thread n00b
I tried to use a boolean operator for an array operation : a[] = b[] < c[]; It compiles but seems to only fill a[] with the result of b[0] < c[0]. Is there any "rational" reason to that? And is there any way to use boolean operator for array operations?

Re: Is this range behaviour correct?

2013-03-14 Thread Andrea Fontana
On Thursday, 14 March 2013 at 12:29:26 UTC, Andrei Alexandrescu wrote: On 3/14/13 6:45 AM, Andrea Fontana wrote: On Thursday, 14 March 2013 at 10:08:53 UTC, Andrea Fontana wrote: I'm trying to implement a db cursor as simple InputRange. I can't implement as forward range because using c-api I c

Re: Is this range behaviour correct?

2013-03-14 Thread Andrei Alexandrescu
On 3/14/13 6:45 AM, Andrea Fontana wrote: On Thursday, 14 March 2013 at 10:08:53 UTC, Andrea Fontana wrote: I'm trying to implement a db cursor as simple InputRange. I can't implement as forward range because using c-api I can't clone/save cursor. I wrote popFront() front() and empty() method a

Re: Overhead when using a C library

2013-03-14 Thread Artur Skawina
On 03/14/13 01:52, Timon Gehr wrote: > On 03/14/2013 01:48 AM, Jeremy DeHaan wrote: >> >> I am working on a binding for D, and am almost finished! I started to >> think of some things I might like to work on to improve the binding >> after I get everything working, and one of the things I thought o

Re: Is this range behaviour correct?

2013-03-14 Thread Andrea Fontana
On Thursday, 14 March 2013 at 10:08:53 UTC, Andrea Fontana wrote: I'm trying to implement a db cursor as simple InputRange. I can't implement as forward range because using c-api I can't clone/save cursor. I wrote popFront() front() and empty() method and my range works fine. Using on a for

Re: Is this range behaviour correct?

2013-03-14 Thread Jonathan M Davis
On Thursday, March 14, 2013 11:08:52 Andrea Fontana wrote: > I'm trying to implement a db cursor as simple InputRange. I can't > implement as forward range because using c-api I can't clone/save > cursor. > > I wrote popFront() front() and empty() method and my range works > fine. > > Using on a

shared attrribute

2013-03-14 Thread Jack Applegame
What does mean attribute shared exactly for non global variables? Is it safe to cast to/from shared? For example, let us assume all data are synchronized properly. Is following code safe? import core.atomic; class A { int value; } struct B { A node; } void main() { shared B data; A

Is this range behaviour correct?

2013-03-14 Thread Andrea Fontana
I'm trying to implement a db cursor as simple InputRange. I can't implement as forward range because using c-api I can't clone/save cursor. I wrote popFront() front() and empty() method and my range works fine. Using on a foreach() it browses all elements inside range until range is exausth

Re: Overhead when using a C library

2013-03-14 Thread Andrea Fontana
On Thursday, 14 March 2013 at 00:48:53 UTC, Jeremy DeHaan wrote: Hey guys! I am working on a binding for D, and am almost finished! Are you going to publish this binding? Which library?

Re: What do you use to generate documentation?

2013-03-14 Thread Andrea Fontana
On Wednesday, 13 March 2013 at 15:47:29 UTC, Jonathan M Davis wrote: On Wednesday, March 13, 2013 11:59:52 Andrea Fontana wrote: On Wednesday, 13 March 2013 at 10:11:51 UTC, simendsjo wrote: > You can redefine the DDOC macro to use a stylesheet. Add your > base ddoc file on the command line with