@porperty problem..
Hi I have a forward reference pb in conjunction with @property. Err msg is : forward refrence to inferred return type of function call s1.servername. any ideas ? beside, where are the @property docs ? thanks, bjoern final class LoadBalancer { private static LoadBalancer lb; private Server[] servers; static this() { synchronized lb = new LoadBalancer; } private this() { Server s1 = new Server(); s1.servername = Server 1; // ERROR servers ~= s1; } public static LoadBalancer getLoadBalancer() { return lb; } @property nextServer() { return servers[0]; } class Server { private string _name, _id; @property servername(string name) { _name = name; } @property servername() { return _name; } } }
Re: @porperty problem..
On Mon, 28 Jun 2010 16:37:06 -0400, BLS windev...@hotmail.de wrote: Hi I have a forward reference pb in conjunction with @property. Err msg is : forward refrence to inferred return type of function call s1.servername. any ideas ? beside, where are the @property docs ? thanks, bjoern final class LoadBalancer { private static LoadBalancer lb; private Server[] servers; static this() { synchronized lb = new LoadBalancer; } private this() { Server s1 = new Server(); s1.servername = Server 1; // ERROR servers ~= s1; } public static LoadBalancer getLoadBalancer() { return lb; } @property nextServer() { Shouldn't this be @property Server nextServer() { ??? return servers[0]; } class Server { private string _name, _id; @property servername(string name) { _name = name; } @property servername() { return _name; } } } -Steve
Re: @porperty problem..
On Mon, 28 Jun 2010 22:37:06 +0200, BLS windev...@hotmail.de wrote: Hi I have a forward reference pb in conjunction with @property. Err msg is : forward refrence to inferred return type of function call s1.servername. any ideas ? beside, where are the @property docs ? thanks, bjoern final class LoadBalancer { private static LoadBalancer lb; private Server[] servers; static this() { synchronized lb = new LoadBalancer; } private this() { Server s1 = new Server(); s1.servername = Server 1; // ERROR servers ~= s1; } public static LoadBalancer getLoadBalancer() { return lb; } @property nextServer() { return servers[0]; } class Server { private string _name, _id; @property servername(string name) { _name = name; } @property servername() { return _name; } } } Only place I've seen @property docs is in TDPL
Re: @porperty problem..
On 06/28/2010 03:47 PM, Steven Schveighoffer wrote: On Mon, 28 Jun 2010 16:37:06 -0400, BLS windev...@hotmail.de wrote: @property nextServer() { Shouldn't this be @property Server nextServer() { ??? auto functions?
Re: @porperty problem..
On Mon, 28 Jun 2010 16:55:01 -0400, Ellery Newcomer ellery-newco...@utulsa.edu wrote: On 06/28/2010 03:47 PM, Steven Schveighoffer wrote: On Mon, 28 Jun 2010 16:37:06 -0400, BLS windev...@hotmail.de wrote: @property nextServer() { Shouldn't this be @property Server nextServer() { ??? auto functions? I wasn't aware that @property implies auto. I guess that makes sense, but I didn't consider it anything but a hint to the compiler about how it could be called, not that did anything with the type. But I guess it's similar to static... -Steve
Re: @porperty problem..
On 28/06/2010 22:47, Steven Schveighoffer wrote: houldn't this be @property Server nextServer() { Ouch, you are right.. Interesting enough that @property nextServer() { return ...} compiles without giving any error message.. Anyway it seems to be a forward reference bug. moving the inner Server() class in front of LoadBalancer eliminates the error msg. bjoern
Re: @porperty problem..
On Mon, 28 Jun 2010 16:55:44 -0400, Rory McGuire rmcgu...@neonova.co.za wrote: On Mon, 28 Jun 2010 22:37:06 +0200, BLS windev...@hotmail.de wrote: beside, where are the @property docs ? Only place I've seen @property docs is in TDPL http://www.digitalmars.com/d/2.0/function.html#property-functions -Steve
Re: @porperty problem..
On 06/28/2010 03:58 PM, Steven Schveighoffer wrote: On Mon, 28 Jun 2010 16:55:01 -0400, Ellery Newcomer ellery-newco...@utulsa.edu wrote: On 06/28/2010 03:47 PM, Steven Schveighoffer wrote: On Mon, 28 Jun 2010 16:37:06 -0400, BLS windev...@hotmail.de wrote: @property nextServer() { Shouldn't this be @property Server nextServer() { ??? auto functions? I wasn't aware that @property implies auto. I guess that makes sense, but I didn't consider it anything but a hint to the compiler about how it could be called, not that did anything with the type. But I guess it's similar to static... -Steve There are a bunch of modifiers that do. protection modifiers and maybe align and a few others don't, but pretty much everything else does
Re: @porperty problem..
On 28/06/2010 22:58, Steven Schveighoffer wrote: I wasn't aware that @property implies auto. I guess that makes sense, but I didn't consider it anything but a hint to the compiler about how it could be called, not that did anything with the type. Hm, this snippet does not compile : class Server { private string _name, _id; @property servername(string name) { _name = name; } @property string servername() { return _name; } } remove string from @property and it works. On the other hand .. @property Server nextServer() { return servers[0]; } compiles fine ! Guess we need the official documents... Bjoern
Re: @porperty problem..
On 28/06/2010 23:00, Steven Schveighoffer wrote: http://www.digitalmars.com/d/2.0/function.html#property-functions -Steve Makes sense :) thanks
Re: @porperty problem..
BLS windev...@hotmail.de wrote: Hm, this snippet does not compile : class Server { private string _name, _id; @property servername(string name) { _name = name; } @property string servername() { return _name; } } remove string from @property and it works. Maybe it's because you haven't added string to the setter? Just grasping at straws here. -- Simen
Re: @porperty problem..
On 29/06/2010 00:07, Simen kjaeraas wrote: Maybe it's because you haven't added string to the setter? Just grasping at straws here. -- Simen Hi Simen, yes, thats the prob. I just have not found the @property docs.. thanks for all the help.. This snippet works now as expected.. D properties are just fine. Bjoern import std.stdio; import std.random; void main(string[] args) { LoadBalancer b1 = LoadBalancer.getLoadBalancer(); LoadBalancer b2 = LoadBalancer.getLoadBalancer(); LoadBalancer b3 = LoadBalancer.getLoadBalancer(); // Confirm these are the same instance if (b1 == b2 b2 == b3 ) { writeln(Same instance\n); } // Next, load 15 requests for a server for (int i = 0; i 15; i++) { string serverName = b1.nextServer.servername; writeln(Dispatch request to: ~ serverName); } } // D2 thread safe ?? singleton final class LoadBalancer { private static LoadBalancer lb; private Server[] servers; static this() { synchronized lb = new LoadBalancer; } private this() { Server s1 = new Server(); s1.servername = Server 1; s1.id = ; Server s2 = new Server(); s2.servername = Server 2; servers ~= s1; servers ~= s2; } public static LoadBalancer getLoadBalancer() { return lb; } @property { Server nextServer() { return servers[ uniform(0, servers.length) ]; } } // inner class class Server { private string _name, _id; @property { string servername(string sn) { return _name = sn; } string servername() { return _name; } string id(string id) { return _id = id; } string id() { return _id; } } } }