Re: Detect the bug in the following code

2015-04-16 Thread Brian Schott via Digitalmars-d

On Thursday, 16 April 2015 at 22:48:53 UTC, Idan Arye wrote:

"%s %s".writefln = ("foo".tuple = "bar").expand;


Please make a pull request: 
https://github.com/Hackerpilot/Idiotmatic-D




Re: Detect the bug in the following code

2015-04-16 Thread Idan Arye via Digitalmars-d

On Thursday, 16 April 2015 at 21:37:39 UTC, deadalnix wrote:

On Thursday, 16 April 2015 at 13:52:32 UTC, ixid wrote:

writeln = "Now this is abused of the syntax."


The important question is, can you assign a tuple and get the 
auto unpacking to kick in ?


"%s %s".writefln = ("foo".tuple = "bar").expand;


Re: Detect the bug in the following code

2015-04-16 Thread deadalnix via Digitalmars-d

On Thursday, 16 April 2015 at 13:52:32 UTC, ixid wrote:

writeln = "Now this is abused of the syntax."


The important question is, can you assign a tuple and get the 
auto unpacking to kick in ?


Re: Detect the bug in the following code

2015-04-16 Thread ixid via Digitalmars-d
On Wednesday, 15 April 2015 at 15:17:32 UTC, Steven Schveighoffer 
wrote:

On 4/15/15 10:44 AM, Idan Arye wrote:

import std.stdio;

struct Foo {
bool registered = false;

void register(int x) {
writeln("Registering ", x);
register = true;
}
}

void main() {
Foo foo;
foo.register(10);
}


Easy, the bug is in DMD improperly accepting property 
assignment without @property annotation :P


-Steve


writeln = "Now this is abused of the syntax."


Re: Detect the bug in the following code

2015-04-15 Thread John Colvin via Digitalmars-d

On Wednesday, 15 April 2015 at 18:25:33 UTC, w0rp wrote:
On Wednesday, 15 April 2015 at 15:17:32 UTC, Steven 
Schveighoffer wrote:

On 4/15/15 10:44 AM, Idan Arye wrote:

import std.stdio;

struct Foo {
   bool registered = false;

   void register(int x) {
   writeln("Registering ", x);
   register = true;
   }
}

void main() {
   Foo foo;
   foo.register(10);
}


Easy, the bug is in DMD improperly accepting property 
assignment without @property annotation :P


-Steve


Yep. Push patches for DIP23. Get it in the compiler already. 
Make only x.foo legal without @property.


See 
http://forum.dlang.org/post/kesbfurmakedjqcql...@forum.dlang.org


Re: Detect the bug in the following code

2015-04-15 Thread w0rp via Digitalmars-d
On Wednesday, 15 April 2015 at 15:17:32 UTC, Steven Schveighoffer 
wrote:

On 4/15/15 10:44 AM, Idan Arye wrote:

import std.stdio;

struct Foo {
bool registered = false;

void register(int x) {
writeln("Registering ", x);
register = true;
}
}

void main() {
Foo foo;
foo.register(10);
}


Easy, the bug is in DMD improperly accepting property 
assignment without @property annotation :P


-Steve


Yep. Push patches for DIP23. Get it in the compiler already. Make 
only x.foo legal without @property.


Re: Detect the bug in the following code

2015-04-15 Thread Steven Schveighoffer via Digitalmars-d

On 4/15/15 1:44 PM, Caspar wrote:

On Wednesday, 15 April 2015 at 17:28:01 UTC, John Colvin wrote:

On Wednesday, 15 April 2015 at 14:44:48 UTC, Idan Arye wrote:

import std.stdio;

struct Foo {
   bool registered = false;

   void register(int x) {
   writeln("Registering ", x);
   register = true;
   }
}

void main() {
   Foo foo;
   foo.register(10);
}


Property assignment syntax for non-property functions is a horrible,
horrible thing.


Could someone please explain what is actually happening in that piece of
code to a D newbie?
I see what happens when I run the code but I don't get why it is happening.
In particular what "register = true;" actually does in that case.


In D1, and in D2 (but we're trying to change it), assignment properties 
worked like this:


struct S
{
   void foo(int x);
}

S s;
s.foo = 1; // same as s.foo(1);

So what is happening is that:

register = true;

translates to:

register(true);

which then matches the call of register(int) because 'true' is treated as 1.

So while the caller really wanted to set the variable "registered" to 
true, he's recursively calling his own function.


Many of us think that this should not work, because we have a way to 
designate properties via:


@property void foo(int x);

So really only functions tagged with @property should be usable as 
setters. Getters, the distinction is less confusing, because the 
following aren't very different:


auto x = foo;
auto x = foo();

So the position myself and many of us here have is that normal functions 
can be used as getters, but only @property tagged functions should be 
usable as setters.


-Steve


Re: Detect the bug in the following code

2015-04-15 Thread Caspar via Digitalmars-d

On Wednesday, 15 April 2015 at 17:28:01 UTC, John Colvin wrote:

On Wednesday, 15 April 2015 at 14:44:48 UTC, Idan Arye wrote:

import std.stdio;

struct Foo {
   bool registered = false;

   void register(int x) {
   writeln("Registering ", x);
   register = true;
   }
}

void main() {
   Foo foo;
   foo.register(10);
}


Property assignment syntax for non-property functions is a 
horrible, horrible thing.


Could someone please explain what is actually happening in that 
piece of code to a D newbie?
I see what happens when I run the code but I don't get why it is 
happening.

In particular what "register = true;" actually does in that case.

Thanks,
Caspar


Re: Detect the bug in the following code

2015-04-15 Thread John Colvin via Digitalmars-d

On Wednesday, 15 April 2015 at 14:44:48 UTC, Idan Arye wrote:

import std.stdio;

struct Foo {
bool registered = false;

void register(int x) {
writeln("Registering ", x);
register = true;
}
}

void main() {
Foo foo;
foo.register(10);
}


Property assignment syntax for non-property functions is a 
horrible, horrible thing.


Re: Detect the bug in the following code

2015-04-15 Thread Brian Schott via Digitalmars-d
On Wednesday, 15 April 2015 at 15:17:32 UTC, Steven Schveighoffer 
wrote:
Easy, the bug is in DMD improperly accepting property 
assignment without @property annotation :P


We've found the winner!



Re: Detect the bug in the following code

2015-04-15 Thread Steven Schveighoffer via Digitalmars-d

On 4/15/15 10:44 AM, Idan Arye wrote:

import std.stdio;

struct Foo {
 bool registered = false;

 void register(int x) {
 writeln("Registering ", x);
 register = true;
 }
}

void main() {
 Foo foo;
 foo.register(10);
}


Easy, the bug is in DMD improperly accepting property assignment without 
@property annotation :P


-Steve


Re: Detect the bug in the following code

2015-04-15 Thread Idan Arye via Digitalmars-d

On Wednesday, 15 April 2015 at 14:46:56 UTC, Adam D. Ruppe wrote:

On Wednesday, 15 April 2015 at 14:44:48 UTC, Idan Arye wrote:

   register = true;


Easy, you assigned to the wrong variable, that'd quickly be 
obvious at runtime too with a stack overflow.


I think it sucks that true and false will implicitly convert to 
int though, that bites people somewhat often. I wonder how much 
annoyance it would be to remove that implicit conversion.


Yea, in this example it's quite obvious, but I've just before 
posting it I realized I did this mistake in a much larger 
project, and it was harder to detect(I was getting a double 
registration error in another module rather than a stack 
overflow).


At any rate, I don't think the problem is the implicit conversion 
as much as it is the property syntax...


Re: Detect the bug in the following code

2015-04-15 Thread Adam D. Ruppe via Digitalmars-d

On Wednesday, 15 April 2015 at 14:44:48 UTC, Idan Arye wrote:

register = true;


Easy, you assigned to the wrong variable, that'd quickly be 
obvious at runtime too with a stack overflow.


I think it sucks that true and false will implicitly convert to 
int though, that bites people somewhat often. I wonder how much 
annoyance it would be to remove that implicit conversion.


Re: Detect the bug in the following code

2015-04-15 Thread weaselcat via Digitalmars-d

On Wednesday, 15 April 2015 at 14:44:48 UTC, Idan Arye wrote:

import std.stdio;

struct Foo {
bool registered = false;

void register(int x) {
writeln("Registering ", x);
register = true;
}
}

void main() {
Foo foo;
foo.register(10);
}


register = true


Detect the bug in the following code

2015-04-15 Thread Idan Arye via Digitalmars-d

import std.stdio;

struct Foo {
bool registered = false;

void register(int x) {
writeln("Registering ", x);
register = true;
}
}

void main() {
Foo foo;
foo.register(10);
}