Live data from Hacker News

New for loops in Rust

brson.github.com

1–10 of 27 posts

Re: New for loops in Rust

#5

Why is there so much sugar?! Can't a keyword just be a keyword?

> Why is there so much sugar?! Can't a keyword just be a keyword?

Statements based on keywords are syntactic sugar. What I'm seeing here in Rust is the complete opposite, building an iteration statement from language built-ins. It does include some sugar in it (and "for" is a special keyword) but the semantics of the construct is based on lambda calculus and other lower level constructs in Rust.

In general, it's better that a language has as little special syntax that cannot be constructed from elementary blocks. The gaps are then bridged by adding a little sugar coating to make programming convenient (for humans) but keeping the core language clear and concise (for interpreters and compilers).

For example, in C, you cannot define your own loop structures and you're stuck with for, do and while (C macros are so crappy that they don't count). Haskell, on the other hand, does not have any special iteration statements in the language core but there's a handful of iteration functions that are regular functions and you are free to define your own. Same thing with Scheme (and other Lisps).

Re: New for loops in Rust

#6
I'm going to make a superficial comment and say that "cont" and "ret" are annoying and gratuitous differences. C/C++, Java, Python, JavaScript, and I think Perl/Ruby/Go all use "continue" and "break". It's just pointless to be different in this respect.

A different concept should use different syntax -- and it looks like Rust has several new concepts where they can invent whatever syntax they want. But the same concept should use the same syntax.

Re: New for loops in Rust

#7
> the new for will work on any higher-order function with the appropriate signature

In the end this makes Rust loops look like Ruby loops. May I restate that «widely used programming languages are modified until they resemble Ruby» (https://news.ycombinator.com/item?id=3448277) or CLispScript (https://news.ycombinator.com/item?id=3448826).

What I do not understand of the late "scripting" languages (Dart, Rust) is why they don't just modify Ruby to have a stricter type system and call it done? That or just abandon the scripting mindset and go for more purely functional languages with non-C-like syntaxes like Haskell or OCaml.

Re: New for loops in Rust

#8
post #6

I'm going to make a superficial comment and say that "cont" and "ret" are annoying and gratuitous differences. C/C++, Java, Python, JavaScript, and I think Perl/Ruby/Go all use "continue" and "break". It's just pointless to be different in this respect. A different concept should use different syntax -- and it looks like Rust has several new concepts where they can invent whatever syntax they want. But the same conce…

ruby uses the next keyword for continue

Re: New for loops in Rust

#9
post #4

Seems a bit...overly complex. Also, what is the appeal to '::' instead of just '.' Kill the semicolons with fire

Rust is inspired by C++ which use '::' to access names inside a namespace, here 'vec' and io are module/namespace not object, it's a static lookup.

'.' is still used for object lookup which is dynamic.

Re: New for loops in Rust

#10
post #6

I'm going to make a superficial comment and say that "cont" and "ret" are annoying and gratuitous differences. C/C++, Java, Python, JavaScript, and I think Perl/Ruby/Go all use "continue" and "break". It's just pointless to be different in this respect. A different concept should use different syntax -- and it looks like Rust has several new concepts where they can invent whatever syntax they want. But the same conce…

ruby uses the next keyword for continue

C++ and Java iterators use next as well.
Post reply on HN