Skip to content

Commit

Permalink
lec08
Browse files Browse the repository at this point in the history
  • Loading branch information
insou22 committed Mar 5, 2024
1 parent e3bdb9e commit 6e07bdf
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lec08/playing_around/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions lec08/playing_around/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "playing_around"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
51 changes: 51 additions & 0 deletions lec08/playing_around/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// struct student {
// char *stu_name;
// int stu_zid;
// double stu_wam;
// }
//
// fn prints_student(student: struct student) {
// // ...
// }

fn sum_vec(xs: Vec<i32>) -> i32 {
xs.into_iter().sum()
}

// fn (Rust)
// fun (Kotlin)
// func (Go)
// function (JS)
// def (Python)
// sub (Perl)
// <nothing> (Shell)
//
// int x = 42; --> <TYPE(int)> <VAR(x)> <EQ> <NUM(42)> <SEMICOLON>
// let x: i32 = 42; --> <LET> <VAR(x)> <TYPE(i32)> <EQ> <NUM(42)> <SEMICOLON>
// ^^^^ parser ??? assignment 01 ?????????

fn sum_array(xs: [i32; 3]) -> i32 {
xs.into_iter().sum()
}

fn sum_slice(xs: &[i32]) -> i32 {
xs.into_iter().sum()
}

// fn foo(x: i32) {
// println!("Foo with i32: {x}");
// }
//
// fn foo(x: &str) {
// println!("Foo with string: {x}");
// }

fn main() {
let v = vec![1, 2, 3];
let a = [1, 2, 3];

// ...

dbg!(sum_slice(&v));
dbg!(sum_slice(&a));
}

0 comments on commit 6e07bdf

Please sign in to comment.