alias function this - limitations

2010-06-24 Thread Simen kjaeraas
struct Ref( T ) { T* payload; @property ref T getThis( ) { return *payload; } @property ref T getThis( ref T value ) { payload = value; return *payload; } alias getThis this; } void bar( ) { Ref!int f; int n; f = n; int b = f; } This code fails on the line 'int b

Re: Why assert is in the language?

2010-06-24 Thread Steven Schveighoffer
On Wed, 23 Jun 2010 16:06:48 -0400, Tomek Sowiński j...@ask.me wrote: Dnia 22-06-2010 o 23:55:29 Michal Minich michal.min...@gmail.com napisał(a): On Tue, 22 Jun 2010 17:30:23 -0400, Steven Schveighoffer wrote: On Tue, 22 Jun 2010 17:07:02 -0400, Tomek Sowiński j...@ask.me wrote: Yes,

Re: Multiple Alias this declarations?

2010-06-24 Thread Steven Schveighoffer
On Wed, 23 Jun 2010 19:20:00 -0400, JRM a...@b.com wrote: On page 231, TDPL states that a class can introduce any number of alias this declarations. http://www.digitalmars.com/d/2.0/class.html#AliasThis states that there is only one allowed per class. A quick test shows that dmd agrees with

Re: Program option command line

2010-06-24 Thread Steven Schveighoffer
On Tue, 22 Jun 2010 18:36:09 -0400, bioinfornatics bioinfornat...@gmail.com wrote: great :-) sorry for this sutpid question i want try one project with D and i think is hard to find the good information for D programming (yea i need buy a book too) big thanks Just a heads up, TDPL (the

Re: Cannot initialize associative array.

2010-06-24 Thread Andrej Mitrovic
Andrej Mitrovic Wrote: Bernard Helyer Wrote: On Wed, 23 Jun 2010 00:41:45 -0700, Ali Çehreli wrote: Ali Çehreli wrote: dcoder wrote: So, I moved the initialization to inside the main function, and now it works. Great. I think we need to put this question in the

Re: Cannot initialize associative array.

2010-06-24 Thread Andrej Mitrovic
Bernard Helyer Wrote: On Wed, 23 Jun 2010 00:41:45 -0700, Ali Çehreli wrote: Ali Çehreli wrote: dcoder wrote: So, I moved the initialization to inside the main function, and now it works. Great. I think we need to put this question in the FAQ. For future reference, if

Re: Best way to make Until! into string

2010-06-24 Thread div0
On 23/06/2010 23:14, bearophile wrote: div0: and now with 2.047 I've been bitten by the removal of struct initialisers. What do you mean? Bye, bearophile curly brace initialisers: struct c4 { float[4]_vals; } c4 dat = { [0,0,0,0] }; Needs to be changed to use a

Re: alias function this - limitations

2010-06-24 Thread div0
On 24/06/2010 13:52, Simen kjaeraas wrote: struct Ref( T ) { T* payload; @property ref T getThis( ) { return *payload; } @property ref T getThis( ref T value ) { payload = value; return *payload; } alias getThis this; } void bar( ) { Ref!int f; int n; f = n; int b = f; } This code fails on the

Re: alias function this - limitations

2010-06-24 Thread Simen kjaeraas
div0 d...@users.sourceforge.net wrote: This code fails on the line 'int b = f;'. Is it supposed to? I think so. 'alias this' is used to forward stuff that appears to the right of a dot onto the named member. Not only. Assignment of the wrapped type will also work. In c++ to get what

Re: Why assert is in the language?

2010-06-24 Thread Tomek Sowiński
Dnia 24-06-2010 o 01:39:35 Jonathan M Davis jmdavisp...@gmail.com napisał(a): Tomek Sowiński wrote: There's a better way: void assert_(string file = __FILE__, uint line = __LINE__)(bool pred, lazy string msg = null) { version(unittest) if (!pred) throw new

Re: alias function this - limitations

2010-06-24 Thread Steven Schveighoffer
On Thu, 24 Jun 2010 14:23:09 -0400, Simen kjaeraas simen.kja...@gmail.com wrote: It does not. In WalterAndrei.pdf, opImplicitCast(To|From) is mentioned, but it has not found its way into the language. Alias this is supposed to implement what opImplicitCast was supposed to implement.

Re: alias function this - limitations

2010-06-24 Thread div0
On 24/06/2010 19:23, Simen kjaeraas wrote: div0 d...@users.sourceforge.net wrote: This code fails on the line 'int b = f;'. Is it supposed to? I think so. 'alias this' is used to forward stuff that appears to the right of a dot onto the named member. Not only. Assignment of the wrapped

Re: alias function this - limitations

2010-06-24 Thread Simen kjaeraas
div0 d...@users.sourceforge.net wrote: I've been having a play and as far as I can tell it looks like aliasing this to a method just doesn't work at all; I think the alias this is being completely ignored. It would seem you're right. Just that assignment made me think it did work. Now why

Re: Multiple Alias this declarations?

2010-06-24 Thread JRM
On Thu, 24 Jun 2010 09:09:23 -0400, Steven Schveighoffer wrote: The book is right. It has to be, you can't change the book, but you can change dmd ;) But seriously, there are a number of features that are mentioned in TDPL that are not properly implemented in dmd. inout comes to mind...

Issue with Curry

2010-06-24 Thread sybrandy
Hello, I tried using the curry function last night and I ran into a compilation issue. Here's a simple example that demonstrates the issue: import std.functional; import std.stdio; void strwrite(string input) { writeln(input); } alias curry!(strwrite, foo) writefoo; void main() {

Re: Issue with Curry

2010-06-24 Thread sybrandy
On 06/24/2010 06:54 PM, sybrandy wrote: Hello, I tried using the curry function last night and I ran into a compilation issue. Here's a simple example that demonstrates the issue: import std.functional; import std.stdio; void strwrite(string input) { writeln(input); } alias curry!(strwrite,

import/modules

2010-06-24 Thread marksibly
Hi, D�newbie�here�with�a�few�import/module�related�questions. I�have�a�test�project�with�the�following�dir/file�layout: c:\test.d c:\testmod\test2.d The�modules�reference�each�other�via�imports�(very nice!)�and�it�all compiles�fine�as�long�as�I�specify�both�modules�on�the�dmd�command line,�eg:

Object removing own last reference.

2010-06-24 Thread strtr
void externalFunc(){} class C { .. int index_; int yay; void removeMe() { //remove last reference to this object objects[_index] = null; //other critical code memberFunc(); externalFunc(); } void memberFunc(){yay++} } Is there anything unsafe about his code?

Re: Object removing own last reference.

2010-06-24 Thread marksibly
Hi, Shouldn't be as 'this' will keep the object alive as long as necessary. Mark

Re: import/modules

2010-06-24 Thread bearophile
marksibly: D newbie here with a few import/module related questions. Welcome here :-) Are your questions relative to the latest D2 version or D1? Keep in mind that D1 and D2 module system has several bugs. ...doesn't work - can't find the second module. What am I doing wrong? Or is this just