This one weird trick allows you to capture loop variables.

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sun Oct 20 02:58:42 UTC 2024


On Saturday, October 19, 2024 8:29:53 PM MDT Walter Bright via Digitalmars-d 
wrote:
> I'm a bit sorry I implemented opApply. The conversion of the loop body to a
> lambda is a tricky beast, and in general such complex rewrites are not a
> good idea. The language should be straightforward.

Honestly, I've always found opApply to be very hard to understand. It's kind
of like it's turning the foreach loop inside out, and it just hurts my
brain. I'd probably understand it much better if I had to use it all the
time, but at this point, I'd only ever use it in cases where ranges didn't
make sense - and even then, I'd probably just elect to use a for loop
instead of trying to take advantage of foreach. foreach is nice, but writing
for loops isn't a big deal IMHO.

But for better or worse, we do have opApply, so I have to deal with it at
least once in a while when someone else has used it. But such is life.

- Jonathan M Davis





More information about the Digitalmars-d mailing list