
A Quick Look at the Rust Programming Language - robin_reala
http://www.bluishcoder.co.nz/2011/03/31/a-quick-look-at-the-rust-programming-language.html
======
portmanteaufu
I'm glad that systems languages are getting a little more love these days.
However, I'm a little saddened to see that no one seems to want to write a
language that can also be used at the write-a-kernel level. Both Rust and
GoLang have expressly made this a non-goal[1][2].

[1] <https://github.com/graydon/rust/wiki/Project-FAQ>

[2] [http://groups.google.com/group/golang-
dev/browse_thread/thre...](http://groups.google.com/group/golang-
dev/browse_thread/thread/72c5c5c355cf1262/0e473006b386a185)

~~~
pcwalton
I think you could write a kernel in Rust (though you'd need to add unsafe
pointers, direct calls, and possibly other stuff to the language), it's just
not a _goal_ of the project. There's no reason why I wouldn't accept patches
to the language that would help in that effort as long as they didn't wildly
conflict with the main goals of the project.

~~~
portmanteaufu
+1, Thanks for making that distinction.

------
primodemus
Since Rust implements a typestate system, here is a link to the classic 1986
paper by Strom and Yemini which introduces the concept of typestate:
[http://www.cs.cmu.edu/~aldrich/papers/classic/tse12-typestat...](http://www.cs.cmu.edu/~aldrich/papers/classic/tse12-typestate.pdf)

LtU has a thread on Rust: <http://lambda-the-ultimate.org/node/4009>

------
perlgeek
> Multi-paradigm. pure-functional, concurrent-actor, imperative-procedural,
> OO.

Can sombody please explain how "pure-functional" (where I think that "pure"
means "without side effects") mixes with "imperative"?

Or do I misunderstand the "pure" part?

~~~
aerique
As long as you don't mix your functional code with imperative code you can
stay pure.

~~~
perlgeek
To me, multi-paradigm always was about mixing the styles, so this sounds a
like quite a radical restriction, and a bit weird.

~~~
dkersten
Well, _inside_ a function, you can have as much imperative code as you like,
with mutable local variables and what-not, the function overall is still pure
as long as it does not cause side-effects.

Eg, functional code could looks something like this:

    
    
        foo a b = if a < b then quux (map bar a) else b
    

while a pure imperative function could look something like this:

    
    
        int foo (string a, int b) { // since a is passed by value, mutating it below will not modify the original
            if (a < b) {
                for (int idx=0; idx<a.length; ++idx) {
                    a[idx] = bar(a[idx]);
                }
                return quux(a);
            } else {
                return b;
            }         
        }
    

Obviously this example is contrived and dumb, but both do the same thing and,
besides the syntax difference, the first is written in a functional style, the
second in an imperative style, but both are still _pure_ (as long as bar and
quux are also pure).

So you _can_ mix functional and imperative without making functions impure.

------
dkarl
I love destructors and RAII. They're more elegant than "with" constructs and
much safer (unless you have a fancy type system that warns you when you create
a resource object outside a "with.") They're the only thing about C++ that I
really miss in other languages.

~~~
sjs
If anyone else who doesn't know C++ is curious about RAII (Resource
Acquisition Is Initialization), the C2 wiki article was enlightening:
<http://c2.com/cgi/wiki?ResourceAcquisitionIsInitialization>

Keep this in mind (from the wiki article):

    
    
        One problem with the name Resource Acquisition Is Initialization
        is that it is inaccurate: it's not always about resources, and
        it is nothing to do with initialization -- what makes the idiom
        tick is finalization.

------
hanifvirani
For those who are interested, here's a 9 minute audio where Brendon Eich talks
about new programming languages and Rust:
<http://www.aminutewithbrendan.com/pages/20101206>.

------
singular
I hate to sound extremely petty, but I just can't stand a modern language that
insists on using semicolons. Just Don't Do It, please.

~~~
pcwalton
Rust developer here.

In Rust, the semicolon is the expression sequencing operator (like in ML), not
a statement terminator. "a;b" means "evaluate a, throw away the result, and
return the result of evaluating b". So the semicolon is more than just
boilerplate.

I guess we could do some sort of automatic semicolon insertion like
JavaScript, but I'm not sure that the benefits outweigh the complexity.

~~~
ajb
There was a longish discussion on the bitc language development list on
exactly this issue. I think this is the first message: [http://www.mail-
archive.com/bitc-dev@coyotos.org/msg02389.ht...](http://www.mail-
archive.com/bitc-dev@coyotos.org/msg02389.html). Looks like they ended up with
automatic insertion: <http://www.bitc-lang.org/docs/bitc/spec.html#layout>

~~~
singular
Cool; interesting to see how it's done elsewhere. In go:-

<http://code.google.com/p/go/source/browse/src/cmd/gc/go.y>

    
    
      /*
       * Go language grammar.
       *
       * The Go semicolon rules are:
       *
       *  1. all statements and declarations are terminated by semicolons.
       *  2. semicolons can be omitted before a closing ) or }.
       *  3. semicolons are inserted by the lexer before a newline
       *      following a specific list of tokens.
       *
       * Rules #1 and #2 are accomplished by writing the lists as
       * semicolon-separated lists with an optional trailing semicolon.
       * Rule #3 is implemented in yylex.
       */
    

But obviously this is very language-specific and given the case discussed
above likely not to work in quite the same way.

------
_sh
An line from a stacktrace:

    
    
      rt: d884:main:main: upcall fail '.t0 < 3u', ts2.rs:5
    

Yikes!

~~~
pcwalton
Yeah, rustboot's pretty printer leaves something to be desired. We have a much
better pretty printer in rustc (see src/comp/pretty/).

