Homework: 1. Implement and run the guessing example.
$ cat 0101-guessing-game/src/main.rs use rand::Rng; use std::cmp::Ordering; fn main() { let secret_number :u32 = rand::thread_rng().gen_range(1..=100); let mut guess = String::new(); loop { println!("Guess a number: "); guess.clear(); std::io::stdin().read_line(&mut guess).expect("error reading line"); let guess : u32 = match guess.trim().parse() { Ok(num) => num, Err(err) => { println!("{}", err); continue } }; match secret_number.cmp(&guess) { Ordering::Less => println!("Try lower."), Ordering::Greater => println!("Try higher."), Ordering::Equal => { println!("That's it: {}", secret_number); break; } } } } 2. Make a rust project that uses std::io to generate a .jl julia script
that performs and outputs the result of an arithmetic calculation.
file output: https://doc.rust-lang.org/stable/std/io/
I ended up using https://docs.rust-lang.org/stable/std/fs/ julia: see other thread with similar name
$ cat 0102-output-julia/src/main.rs use std::io::Write; fn main() { let mut f : std::fs::File = std::fs::File::create("output.jl").expect("failed to create output.jl"); f.write_all(b"x = 4\nprintln(\"4 + 4 = $(x + 4)\")\n").expect("failed to write lines"); } $ julia output.jl 4 + 4 = 8