byKey and byValue: properties or methods?

Jonathan M Davis jmdavisProg at gmx.com
Wed Jan 18 16:52:15 PST 2012


On Thursday, January 19, 2012 01:38:23 Alex Rønne Petersen wrote:
> But couldn't that be considered leaking an implementation detail of lazy
> values? Or is this intentional design?

The language requires that lazy parameters be accessed with (). That leaks the 
fact that the variable is lazy into the function body, but whether it leaks 
how lazy parameters are implemented is debatable. The same syntax could be 
used with a different implementation underneath the hood.

But the fact that you have to use double parens on a lazy delegate isn't 
leaking any kind of implemenatation detail. It's the natural extension of the 
syntax for lazy. var() gives you the value of the lazy parameter var, and so 
if you want to call var (or use opCall or it), then you need another set of 
parens - var()().

Whether requiring parens on lazy parameters is a good design decision is 
debatable, but I don't see any leaking of implementation details in it. The 
syntax chosen was probably chosen because it's implemented with a delegate, 
but the fact that it's implemented with a delegate is still an implementation 
detail which could theoretically be changed.

- Jonathan M Davis


More information about the Digitalmars-d mailing list