Range Redesign: Copy Semantics

Ben Jones fake at fake.fake
Mon Jan 22 05:54:59 UTC 2024


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.



More information about the Digitalmars-d mailing list