Range Redesign: Copy Semantics

Quirin Schroll qs.il.paperinik at gmail.com
Tue Jan 23 17:05:40 UTC 2024


On Monday, 22 January 2024 at 05:54:59 UTC, Ben Jones wrote:
> On Sunday, 21 January 2024 at 22:40:55 UTC, Paul Backus wrote:
>> If your concern is aesthetics, dereferencing a pointer or 
>> unboxing a Nullable is far less ugly than passing a callback.
>
> I've been writing a fair amount of Kotlin (an a tiny bit of 
> Swift) and the trailing lambda syntax is very nice for making 
> these APIs look nice.  Bascially, if the last argument to a 
> function is a function, you can put it's curly braces after the 
> parentheses:  `range.map{ it*2}.filter{ it < 10}`
>
> The sauce that Kotlin has that D doesn't is that 1-arg lambdas 
> get an implicit parameter called `it` and explicit parameters 
> come after the opening curly brace: `{ p1, p2 -> body }`.  I'm 
> also not sure how it would work with templates.  Generally, I 
> think it's much easier to think about lifetime guarantees with 
> functional APIs, so something like that might make them more 
> palatable syntactically.

This is off-topic, but I want to mention that the implicit `it` 
confused the hell out of me when I learned Kotlin. The feature 
literally saves measly 6 keystrokes for `it -> `, 4 if you ignore 
spaces. In D, `map!(it => it * 2)` IMO, is pretty good (e.g. 
compared to C++). D’s lambdas have their flaws, but lack of 
brevity isn’t one.


More information about the Digitalmars-d mailing list