Why don't lazy parameters bind to delegates? Was: Feature to get or add value to an associative array.

Jonathan M Davis newsgroup.d at jmdavisprog.com
Fri Apr 20 22:21:13 UTC 2018


On Friday, April 20, 2018 22:03:04 Giles Bathgate via Digitalmars-d wrote:
> On Friday, 20 April 2018 at 20:35:43 UTC, Steven Schveighoffer
>
> wrote:
> > Let me say I was surprised that this doesn't actually work. An
> > in-line lambda will NOT work as a lazy parameter, even though
> > that's EXACTLY what a lazy parameter is implemented as! And
> > variadic lazy parameters are explicitly typed this way.
>
> I kind of expected it to work too. However, I just created a
> template to allow this to work with my PR.
>
> https://github.com/dlang/druntime/pull/2162/files#diff-a68e58fcf0de5aa198f
> caceafe4e8cf9R2344
>
> Getting it right took a few head-scratchers, but I put that down
> to my lack of experience with D ;)

Honestly, I think that it's a terrible idea to special-case it like that. If
we want to argue for making it work in the language, that's fine, but if we
special-case it like this, then it will work with some functions that have
lazy parameters and not others, and the result will be confusing. Besides,
all it takes to be able to pass a lamdba or delegate to a lazy parameter is
to actually call it when passing it. So, if you add parens after the braces,
it works. There's no need to go and add a special case for it to the
function.

- Jonathan M Davis



More information about the Digitalmars-d mailing list