Re: [fpc-devel] [] property overloads
On Thu, 20 Jun 2019, Ryan Joseph wrote: On Jun 20, 2019, at 4:59 PM, Sven Barth via fpc-devel wrote: It will need to be be allowed for Delphi compatibility anyway: https://bugs.freepascal.org/view.php?id=29056 Well that settles it. ;) Indeed. You can be sure that patches for this will be accepted :) Michael. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] [] property overloads
> On Jun 20, 2019, at 4:59 PM, Sven Barth via fpc-devel > wrote: > > It will need to be be allowed for Delphi compatibility anyway: > https://bugs.freepascal.org/view.php?id=29056 > Well that settles it. ;) Regards, Ryan Joseph ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] [] property overloads
Michael Van Canneyt schrieb am Do., 20. Juni 2019, 22:05: > But maybe the compiler people can see a reason why this should not be > allowed. > It will need to be be allowed for Delphi compatibility anyway: https://bugs.freepascal.org/view.php?id=29056 Regards, Sven > ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] [] property overloads
> On Jun 20, 2019, at 3:58 PM, Michael Van Canneyt > wrote: > > The point is that there is in my example only 'Values' which is a unique > name. Making that 'Default' just means that the 'Values' keyword can be left > out. > making the 'Values' array the single default. Got it. The default is “values”. > I always felt it silly that I must do > > MyStrings.Items[0] > and > MyStrings.Values['Name'] > > when the compiler could perfectly see what overload to use when I type > > MyStrings.items[0] MyStrings.items['Name'] > And, by extension > MyStrings[0] MyStrings['Name'] > > Still you must be careful, because what is meant by > MyStrings['0'] ... is it a type error or is actually the name meant ? It’s basically the same as any other overloaded method so I don’t see where the problem could be. Regards, Ryan Joseph ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] [] property overloads
On Thu, 20 Jun 2019, Ryan Joseph wrote: On Jun 20, 2019, at 2:17 PM, Michael Van Canneyt wrote: IMHO this goes contrary to what the word 'default' means. There can be only 1 default. I think the name of “default” was probably a mistake and it should have been “nameless” or something similar. Not sure why it was chosen but it’s going to be giving us problems. That said, allowing overloading of array properties based on index type has been on my wish list since a long time. So property Values[index: integer]: TValue read GetValue; property Values[index: string]: TValue read GetValue; would be a nice addition. Since the Values array is then uniquely named, 'Default' makes sense again. The values array is uniquely named? Looks the same to me. The point is that there is in my example only 'Values' which is a unique name. Making that 'Default' just means that the 'Values' keyword can be left out. making the 'Values' array the single default. Properties don’t support duplicate identifiers though and the real issue is being able to do c[0] or c[‘key’] without the property name. I am aware of what you're trying to do. It feels to me like we’re being held back by the choice of the word default. How can we get around that? Seems like a silly thing to be getting in our way. Allowing multiple index types for array properties should solve the matter nicely, even combined with "default". Since there are always getters and setters for such an array property, the normal overloading rules apply. So you can do C.Values[0]; C.Values['key']; or C[0]; C['key'] ; I always felt it silly that I must do MyStrings.Items[0] and MyStrings.Values['Name'] when the compiler could perfectly see what overload to use when I type MyStrings.items[0] MyStrings.items['Name'] And, by extension MyStrings[0] MyStrings['Name'] Still you must be careful, because what is meant by MyStrings['0'] ... is it a type error or is actually the name meant ? But maybe the compiler people can see a reason why this should not be allowed. Michael.___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] [] property overloads
> On Jun 20, 2019, at 2:17 PM, Michael Van Canneyt > wrote: > > IMHO this goes contrary to what the word 'default' means. There can be only > 1 default. I think the name of “default” was probably a mistake and it should have been “nameless” or something similar. Not sure why it was chosen but it’s going to be giving us problems. > > That said, allowing overloading of array properties based on index type has > been on my wish list since a long time. > > So > property Values[index: integer]: TValue read GetValue; > property Values[index: string]: TValue read GetValue; would be a nice > addition. > > Since the Values array is then uniquely named, 'Default' makes sense again. The values array is uniquely named? Looks the same to me. Properties don’t support duplicate identifiers though and the real issue is being able to do c[0] or c[‘key’] without the property name. It feels to me like we’re being held back by the choice of the word default. How can we get around that? Seems like a silly thing to be getting in our way. Regards, Ryan Joseph ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] [] property overloads
On Thu, 20 Jun 2019, Ryan Joseph wrote: I just had some plans for a cool JSON class thwarted because apparently [] properties don’t allow overloading of the parameters. Can we allow multiple default properties as long as their parameters are different? I know there’s not overloading of property names but at least the parameters could be overloadable so the correct property is chosen depending on what the args are. type TMyClass = class function GetValueWithInt(index: integer): TValue; function GetValueWithString(index: string): TValue; property IndexI[index: integer]: TValue read GetValueWithInt; default; property IndexS[index: string]: TValue read GetValueWithString; default; end; o := c[index]; // IndexI wins o := c[‘key’]; // IndexS wins IMHO this goes contrary to what the word 'default' means. There can be only 1 default. That said, allowing overloading of array properties based on index type has been on my wish list since a long time. So property Values[index: integer]: TValue read GetValue; property Values[index: string]: TValue read GetValue; would be a nice addition. Since the Values array is then uniquely named, 'Default' makes sense again. Michael.___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
[fpc-devel] [] property overloads
I just had some plans for a cool JSON class thwarted because apparently [] properties don’t allow overloading of the parameters. Can we allow multiple default properties as long as their parameters are different? I know there’s not overloading of property names but at least the parameters could be overloadable so the correct property is chosen depending on what the args are. type TMyClass = class function GetValueWithInt(index: integer): TValue; function GetValueWithString(index: string): TValue; property IndexI[index: integer]: TValue read GetValueWithInt; default; property IndexS[index: string]: TValue read GetValueWithString; default; end; o := c[index]; // IndexI wins o := c[‘key’]; // IndexS wins Regards, Ryan Joseph ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel