Stack overflow / recursive expansion with alias this

2012-04-23 Thread Namespace
I have this code: import std.stdio; struct NotNull(T : Object) { private: T _value; public: @disable this(); // constructs with a runtime not null check (via assert()) this(T value) { assert(value !is null);

Re: Issue calling methods using std.concurrency

2012-04-23 Thread Stanislav Blinov
On Monday, 23 April 2012 at 18:44:37 UTC, Casey wrote: I actually did print out the value being passed successfully. It's just that when I used the queue methods (enqueue and dequeue), it get this error. The queue itself is shared, but none of the methods are expecting a shared value nor do

Re: Range of random numbers

2012-04-23 Thread bearophile
Count(5) is easy to replace with iota(5, int.max), This also means that for the OP problem, using repeat(0) is more correct than using count(), because count on default yields ints, that are limited to about 2 milliards. Bye, bearophile

Re: Range of random numbers

2012-04-23 Thread bearophile
jerro: Couldn't it just be iota with no parameters? The Count range has a helper count() function similar to this, that's meant to have an argument that defaults to zero: Count!T count(T)(T start=0) if (isIntegral!T) { return Count!T(start); } The argument allows it to start from another

Re: Range of random numbers

2012-04-23 Thread jerro
It's for a different purpose. So the count() I was proposing will need a different name. Couldn't it just be iota with no parameters?

Re: Issue calling methods using std.concurrency

2012-04-23 Thread Ali Çehreli
On 04/23/2012 11:44 AM, Casey wrote: > I actually did print out the value being passed successfully. It's just > that when I used the queue methods (enqueue and dequeue), it get this > error. The queue itself is shared, but none of the methods are expecting > a shared value nor do I believe they

Re: Issue calling methods using std.concurrency

2012-04-23 Thread Casey
On Monday, 23 April 2012 at 02:34:19 UTC, Ali Çehreli wrote: This works at least with 2.059 on 64-bit Linux: import std.stdio; import std.concurrency; import core.thread; class Foo { int i; } void workerFunc(Tid owner) { receive( (shared(Foo) foo) { writeln("Before:

Re: Range of random numbers

2012-04-23 Thread Ali Çehreli
On 04/23/2012 10:56 AM, Joseph Rushton Wakeling wrote: On 23/04/12 19:46, Joseph Rushton Wakeling wrote: On 23/04/12 18:56, bearophile wrote: jerro: return repeat(0).map!(_ => uniform(lower, upper))(); Yes, this works nicely. Thanks very much! Is this a new addition? With GDC I get a com

Re: Range of random numbers

2012-04-23 Thread Joseph Rushton Wakeling
On 23/04/12 19:46, Joseph Rushton Wakeling wrote: On 23/04/12 18:56, bearophile wrote: jerro: return repeat(0).map!(_ => uniform(lower, upper))(); Yes, this works nicely. Thanks very much! Is this a new addition? With GDC I get a compiler error: expression expected, not '>' ... sugge

Re: Keyword to avoid not null references

2012-04-23 Thread Namespace
On Monday, 23 April 2012 at 17:18:30 UTC, Namespace wrote: I thought that something like this // not_null_struct.d NotNull!(T) assumeNotNull(T : Object)(T t) { return NotNull!(T)(t); } @property NotNull!(T) makeNotNull(T : Object)() { T t = new T(); return assu

Re: Range of random numbers

2012-04-23 Thread Joseph Rushton Wakeling
On 23/04/12 18:56, bearophile wrote: jerro: return repeat(0).map!(_ => uniform(lower, upper))(); repeat(0) returns the same sequence as cycle([0]) and is as fast as it gets, since popFront does nothing and empty is an enum. Good idea. Yes, this works nicely. Thanks very much!

Re: Pacikage level access broken?

2012-04-23 Thread Jonathan M Davis
On Monday, April 23, 2012 13:42:36 Jacob Carlborg wrote: > On 2012-04-23 10:26, Era Scarecrow wrote: > > On Monday, 23 April 2012 at 06:19:12 UTC, Jacob Carlborg wrote: > >> "public" is the default access level. > > > > So it is... That explains why the tests came out backwards on the > > results.

Re: Keyword to avoid not null references

2012-04-23 Thread Namespace
I thought that something like this // not_null_struct.d NotNull!(T) assumeNotNull(T : Object)(T t) { return NotNull!(T)(t); } @property NotNull!(T) makeNotNull(T : Object)() { T t = new T(); return assumeNotNull(t); } // not_null.d which import not_null_struct.

Re: Are there any mixin tutorials?

2012-04-23 Thread bearophile
ixid: > Or any other appropriate methods to achieve things like: > > Loop unrolling > foreach(i;0..12) > //stuff involving the value See Iota!() I've written here: http://d.puremagic.com/issues/show_bug.cgi?id=4085 Bye, bearophile

Re: Range of random numbers

2012-04-23 Thread bearophile
jerro: > return repeat(0).map!(_ => uniform(lower, upper))(); > > repeat(0) returns the same sequence as cycle([0]) and is as fast > as it gets, since popFront does nothing and empty is an enum. Good idea. --- Dmitry Olshansky: > What's wrong with: > http://dlang.org/phobos/st

Re: using ntfs write_through option to create an efficient unzipped layout

2012-04-23 Thread Kagamin
I think, WRITE_THROUGH would cause problems on many small files.

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-23 Thread Steven Schveighoffer
On Mon, 23 Apr 2012 09:49:50 -0400, Jay Norwood wrote: On Monday, 23 April 2012 at 11:27:40 UTC, Steven Schveighoffer wrote: I think using std.string.icmp is the best solution. I would expect it to outperform even schwartz sort. -Steve icmp took longer... added about 1 sec vs 0.3 sec (

Confused about git state

2012-04-23 Thread H. S. Teoh
Not really specific to D, but since there are git experts here: recently while trying to determine when a D bug was introduced, I checked out old revisions of druntime/phobos (detached HEAD state). This morning, I ran git pull on both repos with --ff-only, and now git insists that I'm ahead of upst

Re: Keyword to avoid not null references

2012-04-23 Thread Namespace
On Monday, 23 April 2012 at 14:50:14 UTC, Adam D. Ruppe wrote: On Monday, 23 April 2012 at 14:31:05 UTC, Namespace wrote: Yes, that's what i wrote a site before. Otherwise you couldn't use it in other modules, that's right. yeah i'll fix that next time i work on it. I wouldn't write for all

Re: using ntfs write_through option to create an efficient unzipped layout

2012-04-23 Thread Kagamin
Did you try without WRITE_THROUGH and without sequential scan?

Re: Are there any mixin tutorials?

2012-04-23 Thread David
Am 23.04.2012 16:51, schrieb ixid: Or any other appropriate methods to achieve things like: Loop unrolling foreach(i;0..12) //stuff involving the value You can use this tuple-range, which is Compile-Time: template TupleRange(int from, int to) { alias TupleRangeImpl!(to-1, from) TupleRang

Re: Range of random numbers

2012-04-23 Thread jerro
What about (untested): auto uniformRange(T1 lower, T2 upper) { return count().map!(_ => uniform(lower, upper))(); } Where count() is just: http://d.puremagic.com/issues/show_bug.cgi?id=7839 In the meantime cycle([0]) is acceptable but slower (untested): return cycle([0]).map!(_ => uniform(

Re: Range of random numbers

2012-04-23 Thread Dmitry Olshansky
On 23.04.2012 17:52, bearophile wrote: Joseph Rushton Wakeling: struct UniformRange(T1, T2) { T1 _lower; T2 _upper; @property enum bool empty = false; this(T1 a, T2 b) { _lower = a; _upper = b; } @property auto ref front() { assert(!empty); return uniform(_lower, _upper); } void popFront()

Are there any mixin tutorials?

2012-04-23 Thread ixid
Or any other appropriate methods to achieve things like: Loop unrolling foreach(i;0..12) //stuff involving the value And making multiple functions with different values: func1(int a) {//stuff} func2(int a) {//stuff} func3(int a) {//stuff} where func 1 to 3 are all generated at compile ti

Re: Keyword to avoid not null references

2012-04-23 Thread Adam D. Ruppe
On Monday, 23 April 2012 at 14:31:05 UTC, Namespace wrote: Yes, that's what i wrote a site before. Otherwise you couldn't use it in other modules, that's right. yeah i'll fix that next time i work on it. I wouldn't write for all the objects which i would check "method_with_not_null_object(Con

Re: Keyword to avoid not null references

2012-04-23 Thread Namespace
On Monday, 23 April 2012 at 11:04:24 UTC, Benjamin Thaut wrote: Am 23.04.2012 09:14, schrieb Namespace: I made several tests with NotNull yesterday and actually they all passed. In special cases i didn't get a compiler error but then a runtime error is better then nothing. :) But there is sti

Re: Keyword to avoid not null references

2012-04-23 Thread Adam D. Ruppe
On Sunday, 22 April 2012 at 10:58:10 UTC, Namespace wrote: If i got you right on git, you wouldn't allow something like this: NotNull!(Foo) f = new Foo(); and instead you want that everybody writes NotNull!(Foo) f = assumeNotNull(new Foo); Is that correct? No, I think that's too annoying, tho

Re: Keyword to avoid not null references

2012-04-23 Thread Adam D. Ruppe
On Sunday, 22 April 2012 at 16:59:05 UTC, Jesse Phillips wrote: As such checkNotNull shoud be more than throwing an exception. I have tried this, but it should get some constraints. Also wouldn't the new lambda syntax look nice with null here: null => unsafe(a)? Yeah, I like this idea, though

Re: Range of random numbers

2012-04-23 Thread bearophile
Joseph Rushton Wakeling: struct UniformRange(T1, T2) { T1 _lower; T2 _upper; @property enum bool empty = false; this(T1 a, T2 b) { _lower = a; _upper = b; } @property auto ref front()

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-23 Thread Jay Norwood
On Monday, 23 April 2012 at 11:27:40 UTC, Steven Schveighoffer wrote: I think using std.string.icmp is the best solution. I would expect it to outperform even schwartz sort. -Steve icmp took longer... added about 1 sec vs 0.3 sec (for schwartzSort ) to the program execution time. bool myC

Range of random numbers

2012-04-23 Thread Joseph Rushton Wakeling
For some reason this got lost in the ether, so I'm resending. Related to my earlier question on passing a function -- I was wondering if there's a trivial way of generating a lazily-evaluated range of random numbers according to a given distribution and parameters. I wrote up the code below t

Re: Pacikage level access broken?

2012-04-23 Thread Jacob Carlborg
On 2012-04-23 10:26, Era Scarecrow wrote: On Monday, 23 April 2012 at 06:19:12 UTC, Jacob Carlborg wrote: "public" is the default access level. So it is... That explains why the tests came out backwards on the results Wasn't it private by default in C++? I honestly don't know sometimes.

Re: Allow empty field function arguments for default?

2012-04-23 Thread Jacob Carlborg
On 2012-04-23 10:05, Christophe wrote: Hum, an acceptable solution would be to give an error, asking to explicitely asking to fully qualify the name : void fun(int c = 0) {...} void main() { int c; fun(c=5); // error, ambiguous qualifier "c" fun(main.c = 5); // ok fun((c=5)); // ok

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-23 Thread Steven Schveighoffer
On Sat, 21 Apr 2012 19:24:56 -0400, Jay Norwood wrote: While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!("toLower(a.name) < toLower(b.name)",std.algorithm.SwapStrategy.stable)(entries)

Re: Pacikage level access broken?

2012-04-23 Thread simendsjo
On Mon, 23 Apr 2012 01:32:25 +0200, Jonathan M Davis wrote: On Monday, April 23, 2012 01:21:21 Era Scarecrow wrote: I think I have a misunderstanding of how 'package' is suppose to work. How I understand it, you will give access to the directory, unlike private which will hide it outside o

Re: Question about arrays

2012-04-23 Thread Steven Schveighoffer
On Sat, 21 Apr 2012 18:25:44 -0400, Ali Çehreli wrote: In D, arrays are what they should have been in C :). A pointer and a size. Something the equivalent of the following (for the int type): struct int_Array { int * elements; size_t number_of_elements; } Technically speaking, th

Re: Keyword to avoid not null references

2012-04-23 Thread Benjamin Thaut
Am 23.04.2012 09:14, schrieb Namespace: I made several tests with NotNull yesterday and actually they all passed. In special cases i didn't get a compiler error but then a runtime error is better then nothing. :) But there is still my problem with this: void foo(NotNull!(Foo) n) { } void bar(

Re: Keyword to avoid not null references

2012-04-23 Thread Namespace
On Monday, 23 April 2012 at 08:47:22 UTC, Simen Kjaeraas wrote: On Mon, 23 Apr 2012 10:38:27 +0200, Dmitry Olshansky wrote: On 23.04.2012 12:06, Simen Kjaeraas wrote: On Mon, 23 Apr 2012 09:14:12 +0200, Namespace wrote: I made several tests with NotNull yesterday and actually they all pa

Re: Keyword to avoid not null references

2012-04-23 Thread Simen Kjaeraas
On Mon, 23 Apr 2012 10:38:27 +0200, Dmitry Olshansky wrote: On 23.04.2012 12:06, Simen Kjaeraas wrote: On Mon, 23 Apr 2012 09:14:12 +0200, Namespace wrote: I made several tests with NotNull yesterday and actually they all passed. In special cases i didn't get a compiler error but then a

Re: Keyword to avoid not null references

2012-04-23 Thread Namespace
No. The whole point of NotNull is that it should enforce not being null. Allowing implicit casting from PossiblyNull to NotNull would break this. Then i'm further for a keyword that checks an object for not null. Or you check at runtime to avoid null, e.g. with assert or enforce.

Re: Keyword to avoid not null references

2012-04-23 Thread Dmitry Olshansky
On 23.04.2012 12:06, Simen Kjaeraas wrote: On Mon, 23 Apr 2012 09:14:12 +0200, Namespace wrote: I made several tests with NotNull yesterday and actually they all passed. In special cases i didn't get a compiler error but then a runtime error is better then nothing. :) But there is still my pr

Re: Pacikage level access broken?

2012-04-23 Thread Era Scarecrow
On Monday, 23 April 2012 at 06:19:12 UTC, Jacob Carlborg wrote: "public" is the default access level. So it is... That explains why the tests came out backwards on the results Wasn't it private by default in C++? I honestly don't know sometimes.

Re: Allow empty field function arguments for default?

2012-04-23 Thread Christophe
"Jakob Ovrum" , dans le message (digitalmars.D.learn:34971), a écrit : > That is exactly the problem though, it can silently change the > behaviour of existing code. It is the worst kind of breaking > change, hence I don't think it will ever be in D in this form, > much less the current iteratio

Re: Keyword to avoid not null references

2012-04-23 Thread Simen Kjaeraas
On Mon, 23 Apr 2012 09:14:12 +0200, Namespace wrote: I made several tests with NotNull yesterday and actually they all passed. In special cases i didn't get a compiler error but then a runtime error is better then nothing. :) But there is still my problem with this: void foo(NotNull!(Foo

Re: Keyword to avoid not null references

2012-04-23 Thread Namespace
I made several tests with NotNull yesterday and actually they all passed. In special cases i didn't get a compiler error but then a runtime error is better then nothing. :) But there is still my problem with this: void foo(NotNull!(Foo) n) { } void bar(Foo n) { } in my optinion it must exi