Re: arrays and foreach

2012-04-22 Thread Russel Winder
On Sun, 2012-04-22 at 06:59 +0100, Russel Winder wrote: On Sat, 2012-04-21 at 22:14 -0700, Ali Çehreli wrote: [...] That part is done: http://ddili.org/ders/d.en/hello_world.html Surely Hello World shows just a few, and definitely not all, of the essential concepts of a programming

Re: arrays and foreach

2012-04-22 Thread Russel Winder
On Sat, 2012-04-21 at 22:14 -0700, Ali Çehreli wrote: [...] That part is done: http://ddili.org/ders/d.en/hello_world.html As you are emphasizing use of dmd, and the initial programs will all be relatively small scripts, I wonder if using rdmd would be a good move. Shortening the

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

2012-04-22 Thread Jay Norwood
On Sunday, 22 April 2012 at 02:29:45 UTC, Jonathan M Davis wrote: Regardless of whether it's the Big(O) complexity or the constant factor that's the problem here, clearly there's enough additional overhead that it's causing problems for Jay's particular case. It's also the sort of thing that

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

2012-04-22 Thread Jonathan M Davis
On Sunday, April 22, 2012 08:20:13 Jay Norwood wrote: The comment below worries me a little bit about std.string.icmp. What if they are two 1MB strings that differ in he first character? Does it really convert both strings to lower case before comparing the first character?

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

2012-04-22 Thread Jay Norwood
On Sunday, 22 April 2012 at 06:26:42 UTC, Jonathan M Davis wrote: You can look at the code. It checks each of the characters in place. Unlike toLower, it doesn't need to generate a new string. But as far as the comparison goes, they're the same - hence that line in the docs. - Jonathan M

Re: Keyword to avoid not null references

2012-04-22 Thread Namespace
On Sunday, 22 April 2012 at 00:06:47 UTC, Adam D. Ruppe wrote: I just pushed an update to git with a few changes people have suggested. I removed one of the old opAssigns to keep a static type check. Added assumeNotNull and checkNotNull as entry points. Made the data member private. I think

Re: Regarding the more precise GC

2012-04-22 Thread Dmitry Olshansky
On 22.04.2012 4:28, bearophile wrote: In the main D newsgroup I have seen the two recent threads regarding a more precise GC in D. I have two questions about that, that seem more fit for D.learn. 1) I have not fully understood the performance and memory implications of the more precise GC. In

Re: Keyword to avoid not null references

2012-04-22 Thread Namespace
On Sunday, 22 April 2012 at 00:06:47 UTC, Adam D. Ruppe wrote: Made the data member private. But if the struct is in a separate module you get an error. So you must write T get() { return this._notNullData; } alias get this; instead alias _notNullData this; /// this is

Re: toLower() and Unicode are incomplete was: Re: avoid toLower in std.algorithm.sort compare alias

2012-04-22 Thread Dmitry Olshansky
On 22.04.2012 5:43, Ali Çehreli wrote: On 04/21/2012 04:24 PM, 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)

Re: Access violation using chain()

2012-04-22 Thread Brad Anderson
On Thursday, 19 April 2012 at 16:19:05 UTC, Brad Anderson wrote: On Thu, Apr 19, 2012 at 7:25 AM, Christophe trav...@phare.normalesup.orgwrote: Brad Anderson , dans le message (digitalmars.D.learn:34902), a écrit : Perhaps I'm just misunderstanding something about closures but the

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

2012-04-22 Thread Jacob Carlborg
On 2012-04-22 01:24, 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); It was terribly slow

Re: Keyword to avoid not null references

2012-04-22 Thread Namespace
On Sunday, 22 April 2012 at 00:06:47 UTC, Adam D. Ruppe wrote: I just pushed an update to git with a few changes people have suggested. I removed one of the old opAssigns to keep a static type check. Added assumeNotNull and checkNotNull as entry points. I didn't recognized this part until

Module zlib cannot be read

2012-04-22 Thread Joseph Rushton Wakeling
Hello all, I currently have a self-compiled and installed dmd, druntime, phobos and rdmd on Ubuntu 12.04. I get the following error message whenever I try to use rdmd or equivalently dmd -run: /usr/local/include/d2/std/zlib.d(26): Error: module zlib is in file 'etc/c/zlib.d' which cannot

Re: Keyword to avoid not null references

2012-04-22 Thread Jesse Phillips
On Saturday, 21 April 2012 at 22:18:02 UTC, Adam D. Ruppe wrote: We can do not null in the library reasonably well. I have a basic one in github: https://github.com/D-Programming-Language/phobos/pull/477 I'm thinking those interested in not null will want something similar to the maybe type.

Re: Module zlib cannot be read

2012-04-22 Thread Jesse Phillips
On Sunday, 22 April 2012 at 15:26:34 UTC, Joseph Rushton Wakeling wrote: /usr/local/include/d2/std/zlib.d(26): Error: module zlib is in file 'etc/c/zlib.d' which cannot be read import path[0] = /usr/local/include/d2/ Do you see the file: /usr/local/include/d2/etc/c/zlib.d ? If not, then

Re: Module zlib cannot be read

2012-04-22 Thread Joseph Rushton Wakeling
On 22/04/12 19:18, Jesse Phillips wrote: On Sunday, 22 April 2012 at 15:26:34 UTC, Joseph Rushton Wakeling wrote: /usr/local/include/d2/std/zlib.d(26): Error: module zlib is in file 'etc/c/zlib.d' which cannot be read import path[0] = /usr/local/include/d2/ Do you see the file:

opPropDispatch

2012-04-22 Thread sclytrack
struct Dispatcher { @property void opDispatch(string name)(string val) { writeln(val); } @property string opDispatch(string name)() { return getter; } void opDispatch(string

Re: opPropDispatch

2012-04-22 Thread David
Am 22.04.2012 22:11, schrieb sclytrack: struct Dispatcher { @property void opDispatch(string name)(string val) { writeln(val); } @property string opDispatch(string name)() { return getter; } void opDispatch(string name)() { writeln(name); } } I can't seem to make a dispatcher that supports

Re: this() const

2012-04-22 Thread sclytrack
On 04/16/2012 09:27 PM, sclytrack wrote: On 04/16/2012 08:15 PM, sclytrack wrote: const numbers = new int[2]; const c = const(AB)(a, 20, numbers); writeln(c); } Bye, bearophile That's exactly what I needed, thanks. Seems to be forwarded to the constructor if there is one. (untested

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

2012-04-22 Thread SomeDude
On Saturday, 21 April 2012 at 23:24:57 UTC, 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)

What am I doing wrong ?

2012-04-22 Thread SomeDude
Sorry for the noob questions, but import std.stdio; struct Foo { int x; } void main() { auto array = new Foo[10]; auto i = array.length; foreach(Foo f; array) { f.x = --i; write(f.x);} writeln(); foreach(Foo f; array) { write(f.x);} } gives me: PS

Re: What am I doing wrong ?

2012-04-22 Thread Dmitry Olshansky
On 23.04.2012 1:47, SomeDude wrote: Sorry for the noob questions, but import std.stdio; struct Foo { int x; } void main() { auto array = new Foo[10]; auto i = array.length; foreach(Foo f; array) { f.x = --i; write(f.x);} writeln(); foreach(Foo f; array) { write(f.x);} Here: Foo f is not a

Re: What am I doing wrong ?

2012-04-22 Thread Mike Wey
On 04/22/2012 11:47 PM, SomeDude wrote: Sorry for the noob questions, but import std.stdio; struct Foo { int x; } void main() { auto array = new Foo[10]; auto i = array.length; foreach(Foo f; array) { f.x = --i; write(f.x);} Use ref when you want to modify the original array, without ref you

Re: What am I doing wrong ?

2012-04-22 Thread SomeDude
On Sunday, 22 April 2012 at 21:50:32 UTC, Dmitry Olshansky wrote: Omagad, thank you, too much Java is bd for your brains.

Re: opPropDispatch

2012-04-22 Thread Jonathan M Davis
On Sunday, April 22, 2012 22:30:01 David wrote: For now you can do it *without* @property and compile *without* -property But that will not remain the case, so relying on that is not a good idea. Eventually -property will be the normal behavior. As for opPropDispatch, I don't think that it's

Re: Question about arrays

2012-04-22 Thread jerro
On Sunday, 22 April 2012 at 22:17:11 UTC, Stephen Jones wrote: Thanks for the replies. I am still uncertain about something. The documentation distinguishes between dynamic slices (int[5] a = new int[5]) which are managed by the runtime, and stack allocated arrays (int[5] b). The problem I

Re: opPropDispatch

2012-04-22 Thread Adam D. Ruppe
On Sunday, 22 April 2012 at 22:36:12 UTC, Jonathan M Davis wrote: Eventually -property will be the normal behavior. Note that -property adds zero value, much like the current implementation of @property, which fails to disambiguate cases: == import std.stdio; alias void delegate() callable;

Passing a function (with arguments) as function input

2012-04-22 Thread Joseph Rushton Wakeling
Is there a way in which to pass a function as input to another function, with the arguments of the first function already determined? The case I'm thinking of is one where I have a function which wants to take a random number generation scheme, and use it on several occasions, without having

Re: opPropDispatch

2012-04-22 Thread Jonathan M Davis
On Monday, April 23, 2012 01:01:48 Adam D. Ruppe wrote: On Sunday, 22 April 2012 at 22:36:12 UTC, Jonathan M Davis wrote: Eventually -property will be the normal behavior. Note that -property adds zero value, much like the current implementation of @property, which fails to disambiguate

Pacikage level access broken?

2012-04-22 Thread Era Scarecrow
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 of the same file. This problem comes up since a struct is declared inside a package (and even instantiated), however

Re: Passing a function (with arguments) as function input

2012-04-22 Thread Joseph Rushton Wakeling
On 23/04/12 01:19, Joseph Rushton Wakeling wrote: void main() { foreach(double upper; iota(1.0, 2.0, 0.2) ) { double delegate() rng = () { return uniform(0.0, 1.0); }; printRandomNumbers(rng,10); } } That was meant to be, double delegate() rng

Re: Question about arrays

2012-04-22 Thread jerro
On Sunday, 22 April 2012 at 23:01:26 UTC, jerro wrote: On Sunday, 22 April 2012 at 22:17:11 UTC, Stephen Jones wrote: Thanks for the replies. I am still uncertain about something. The documentation distinguishes between dynamic slices (int[5] a = new int[5]) which are managed by the runtime,

Re: Pacikage level access broken?

2012-04-22 Thread Jonathan M Davis
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 of the same file. 1. Package access is _very_ broken:

Re: opPropDispatch

2012-04-22 Thread Adam D. Ruppe
On Sunday, 22 April 2012 at 23:21:57 UTC, Jonathan M Davis wrote: Well, I completely disagree with you on @property. Note: my problem is with -property, not @property. If @property was correctly implemented, it'd serve a very nice purpose. The reason I'm aware of the bug is this is something

Re: opPropDispatch

2012-04-22 Thread Jonathan M Davis
On Monday, April 23, 2012 01:39:44 Adam D. Ruppe wrote: On Sunday, 22 April 2012 at 23:21:57 UTC, Jonathan M Davis wrote: Well, I completely disagree with you on @property. Note: my problem is with -property, not @property. If @property was correctly implemented, it'd serve a very nice

Re: Package level access broken?

2012-04-22 Thread Era Scarecrow
On Sunday, 22 April 2012 at 23:32:40 UTC, Jonathan M Davis wrote: 1. Package access is _very_ broken: http://d.puremagic.com/issues/show_bug.cgi?id=143 Fun... So it's not just me... Guess for the 1-2 places I 'll need package level access instead I gotta either do public or get some getters

Re: Package level access broken?

2012-04-22 Thread Jonathan M Davis
On Monday, April 23, 2012 01:59:15 Era Scarecrow wrote: On Sunday, 22 April 2012 at 23:32:40 UTC, Jonathan M Davis wrote: 1. Package access is _very_ broken: http://d.puremagic.com/issues/show_bug.cgi?id=143 Fun... So it's not just me... Guess for the 1-2 places I 'll need package level

Re: opPropDispatch

2012-04-22 Thread Adam D. Ruppe
On Sunday, 22 April 2012 at 23:54:17 UTC, Jonathan M Davis wrote: Well, strict enforcement is how @property was designed in the first place (and is how it's described in TDPL). That doesn't affect my argument at all, People actually use the implementation as it is, which is a superset of the

Re: opPropDispatch

2012-04-22 Thread Jonathan M Davis
On Monday, April 23, 2012 02:40:42 Adam D. Ruppe wrote: On Sunday, 22 April 2012 at 23:54:17 UTC, Jonathan M Davis wrote: Well, strict enforcement is how @property was designed in the first place (and is how it's described in TDPL). That doesn't affect my argument at all, People

Re: Question about arrays

2012-04-22 Thread Ali Çehreli
On 04/22/2012 03:17 PM, Stephen Jones wrote: Thanks for the replies. I am still uncertain about something. The documentation distinguishes between dynamic slices (int[5] a = new int[5]) The documentation may be incorrect because int[5] is never a slice. It is a fixed-length array. As an

Issue calling methods using std.concurrency

2012-04-22 Thread Casey
Hello, I'm getting some errors when I wrap a struct that I've written with another struct. Here are the errors I'm getting: tqueue.d(14): Error: function queue.Queue!(int).Queue.enqueue (int value) is not callable using argument types (int) shared tqueue.d(15): Error: function

Re: Issue calling methods using std.concurrency

2012-04-22 Thread Ali Çehreli
On 04/22/2012 07:15 PM, Casey wrote: Hello, I'm getting some errors when I wrap a struct that I've written with another struct. Here are the errors I'm getting: tqueue.d(14): Error: function queue.Queue!(int).Queue.enqueue (int value) is not callable using argument types (int) shared

Re: Passing a function (with arguments) as function input

2012-04-22 Thread Ali Çehreli
On 04/22/2012 04:19 PM, Joseph Rushton Wakeling wrote: Is there a way in which to pass a function as input to another function, with the arguments of the first function already determined? The case I'm thinking of is one where I have a function which wants to take a random number generation

Re: Passing a function (with arguments) as function input

2012-04-22 Thread Joseph Rushton Wakeling
On 23/04/12 06:10, Ali Çehreli wrote: You just need to call the delegate with the function call syntax: writeln(rng()); ... but what I get in my code is that printRandomNumbers then prints out n times the _same number_, instead of 5 different ones. i.e. when the delegate is passed its

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

2012-04-22 Thread Jay Norwood
On Sunday, 22 April 2012 at 00:36:19 UTC, bearophile wrote: Performing the toLower every time the cmp function is called doesn't change the O complexity. In Phobos there is an alternative sorting (Schwartzian sorting routime) that applies a function to each item before sorting them, usually is

Re: Passing a function (with arguments) as function input

2012-04-22 Thread Jakob Ovrum
On Sunday, 22 April 2012 at 23:19:52 UTC, Joseph Rushton Wakeling wrote: import std.random, std.range, std.stdio; void printRandomNumbers(RandomNumberGenerator)(RandomNumberGenerator rng, size_t n) { foreach(i; 0..n)