Rust
Implementation of programming language RustRust is the native and the only compiler available for Rust language. The initial version of the compiler was developed since 2006 in OCaml. In 2010 it was replaced with a compiler written in Rust itself.
The compiler is distributed under MIT license. It is crossplatform, supporting OS Windows and Linux at the moment.
Links:
Examples:
Hello, World!:
Example for versions Rust 0.1use std;
import std::io;
fn main() {
io::println("Hello, World!");
}
Factorial:
Example for versions Rust 0.1This example uses recursive factorial definition. Due to uint
overflow values of 13! and larger are calculated incorrectly.
use std;
import std::io;
fn factorial(x: int) -> uint {
if (x <= 1) {
ret 1u;
} else {
ret (x as uint) * factorial(x - 1);
}
}
fn main() {
let i = 0;
while i <= 16 {
io::println(#fmt("%d! = %u", i, factorial(i)));
i = i + 1;
}
}
Fibonacci numbers:
Example for versions Rust 0.1This example calculates Fibonacci numbers recursively.
use std;
import std::io;
fn fibonacci(x: int) -> int {
if (x <= 2) {
ret 1;
} else {
ret fibonacci(x - 1) + fibonacci(x - 2);
}
}
fn main() {
let i = 1;
while i <= 16 {
io::print(#fmt("%d, ", fibonacci(i)));
i = i + 1;
}
io::println("...");
}
Comments
]]>blog comments powered by Disqus
]]>