News for hackers. Stuff that matters.
Re:Programming languages should have a tree traversal primitive by bawolff on Tuesday April 29, 2025 @05:48PM (#43838437)
I kind of agree, but at the same time, for loops are just a fancy control structure that any student should be able to implement with goto.
Re:Programming languages should have a tree traversal primitive by IshKebab on Tuesday April 29, 2025 @05:53PM (#43838467)
I mean people do use iterator instead of for loops quite a lot.

IMO the thing that would be really nice is if control flow like `for` was actually the same as using an iterator. This would really help in Rust too where handling errors inside iterator callbacks is a right pain.

I've seen a few languages try this but it seems to not be very popular. I think it can get a bit confusing how control flow keywords like `return` and `break` work if you turn `if` into syntactic sugar for a function call taking a closure etc.

Re:Programming languages should have a tree traversal primitive by charrondev on Tuesday April 29, 2025 @07:19PM (#43839213)
In what way is for different than an iterator?

In PHP you loop through an iterator with the foreach control structure.

In JavaScript you use for of.

In rust it’s for in.

What am I missing?

Re:Programming languages should have a tree traversal primitive by IshKebab on Wednesday April 30, 2025 @12:21PM (#43847399)
You're missing that I am an idiot and was mixing up iterators with functional style programming :D
Re:Programming languages should have a tree traversal primitive by bawolff on Tuesday April 29, 2025 @09:44PM (#43840300)
That's why i said "goto". Iterators are already a high level cintrol structure.