1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

今年の言語はRust その4

Last updated at Posted at 2019-04-08

Rustを学びます

rustacean-orig-noshadow(1).png
http://rustacean.net/

参考

勉強ページは日本語ドキュメント

プログラミング言語Rust

Rustの日本語ドキュメント 2nd Edition
https://doc.rust-jp.rs/book/second-edition/

オリジナル
https://doc.rust-lang.org/book/

3. Common Programming Concepts

3.3 関数の動作法

関数名はPythonのようにスネークケース

fn main() {
    anoter_function(5, 10);    
    
}


fn anoter_function(x: i32, y: i32){
    println!("The value of x is: {}", x);
    println!("The value of y is: {}", y);
}

関数本体は、文と式を含む。

ちょっと何言っているかわからない。

Rustは「式指向言語」

文とは statement

文とは、なんらかの動作をして値を返さない命令です。

式とは expression

式は結果値に評価されます。

fn main() {
    
    let x = 999; // statement
    
    let y = {
        let x = 3;
        x + 1   // expression
    }; // statement
    
    println!("y is: {}", y);
    println!("x is: {}", x);
}

戻り値のある関数

fn main() {
    
    let x = five();
    
    println!("x is: {}", x);
}

fn five() -> i32{
    5
}

==
x is: 5

fn main(){

    let x = plus_one(5);
    
    println!("x is {}", x);
    
}

fn plus_one(x: i32) -> i32{
    x + 1
}

==
x is 6

特に特筆すべきはありませんでした。

次回はifです

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?