6 ms·
A Quick Look at the Rust Programming Language
- perlgeek 16y ago> 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 16y agoAs long as you don't mix your functional code with imperative code you can stay pure.
- perlgeek 16y agoTo me, multi-paradigm always was about mixing the styles, so this sounds a like quite a radical restriction, and a bit weird.
- dkersten 16y agoWell, 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.
- aerique 16y agoYes, but you don't have to mix them each and every time. It's just that you have the option to do so and aren't constrained to a single language designer's favourite style.
- doublec 16y agoA function has an effect. It can be annotated as 'impure' or 'unsafe'. Any function that is not annotated in that way is considered pure. Pure functions that return a boolean value can be used in the typestate system (ie. typestate calls must not have side effects). 'pure' functions cannot call 'impure' functions, etc. I'm guessing that's what the quoted sentence refers too.
- hanifvirani 16y agoFor 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 http://www.aminutewithbrendan.com/pages/20101206.
- portmanteaufu 16y agoI'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 https://github.com/graydon/rust/wiki/Project-FAQ [2] http://groups.google.com/group/golang-dev/browse_thread/thread/72c5c5c355cf1262/0e473006b386a185 http://groups.google.com/group/golang-dev/browse_thread/thre...
- doublec 16y agoI consider ATS [1] a systems language and it can be used at the write-a-kernel level. It can be used without a garbage collector using linear types to ensure memory is deallocated. One of the contributed examples is some kernel development [2]. [1] http://www.ats-lang.org/ http://www.ats-lang.org/ [2] http://ats-lang.svn.sourceforge.net/viewvc/ats-lang/trunk/contrib/linux/ http://ats-lang.svn.sourceforge.net/viewvc/ats-lang/trunk/co...
- Kototama 16y agoThere is the BitC language: http://www.bitc-lang.org/ http://www.bitc-lang.org/ Sadly they dropped the Lisp syntax.
- Queue29 16y agoNo love for the D programming language? There is a WIP (although not much activity since 2010?) kernel being written in D[1]. [1] https://github.com/xomboverlord/xomb https://github.com/xomboverlord/xomb
- portmanteaufu 16y agoY'know, it's funny. For no good reason I've failed to give D any consideration. I guess I've had it in my head that it wasn't as small or speedy as C/C++, but I'm pretty sure that's unfounded prejudice talking. I think I'll give it a try. Thanks!
- gnuvince 16y ago
- primodemus 16y agoSince 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-typestate.pdf http://www.cs.cmu.edu/~aldrich/papers/classic/tse12-typestat... LtU has a thread on Rust: http://lambda-the-ultimate.org/node/4009 http://lambda-the-ultimate.org/node/4009
- singular 16y agoI 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 16y agoRust 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.
- singular 16y agoHey - I know this is trivial, but I just find it takes away from the clarity of the code when you must terminate lines with a semicolon. It's obviously very useful to use ';' in the scenario you mention, I think a good comparison is F# which doesn't force semicolons but does permit usage like that. I guess, e.g.:- foo bar baz implies foo |> ignore; bar |> ignore; baz Oh, and just to make it very clear, I am talking about something really rather petty, I do not mean to do down rust in any serious way - I'm a wannabe-language designer myself, so major respect to you guys :)
- ajb 16y agoThere 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.html http://www.mail-archive.com/bitc-dev@coyotos.org/msg02389.ht.... Looks like they ended up with automatic insertion: http://www.bitc-lang.org/docs/bitc/spec.html#layout http://www.bitc-lang.org/docs/bitc/spec.html#layout
- singular 16y agoCool; interesting to see how it's done elsewhere. In go:- http://code.google.com/p/go/source/browse/src/cmd/gc/go.y 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.
- dkarl 16y agoI 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 16y agoIf 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 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.
- _sh 16y agoAn line from a stacktrace: rt: d884:main:main: upcall fail '.t0 < 3u', ts2.rs:5 Yikes!
- pcwalton 16y agoYeah, rustboot's pretty printer leaves something to be desired. We have a much better pretty printer in rustc (see src/comp/pretty/).