aboutsummaryrefslogtreecommitdiff
path: root/rust/src/bin/step1_read_print.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src/bin/step1_read_print.rs')
-rw-r--r--rust/src/bin/step1_read_print.rs18
1 files changed, 6 insertions, 12 deletions
diff --git a/rust/src/bin/step1_read_print.rs b/rust/src/bin/step1_read_print.rs
index 8be7e0d..02b2da7 100644
--- a/rust/src/bin/step1_read_print.rs
+++ b/rust/src/bin/step1_read_print.rs
@@ -19,24 +19,18 @@ fn print(exp: MalVal) -> String {
exp.pr_str(true)
}
-fn rep(str: String) -> Result<String,MalError> {
- match read(str) {
- Err(e) => Err(e),
- Ok(ast) => {
- //println!("read: {}", ast);
- match eval(ast) {
- Err(e) => Err(e),
- Ok(exp) => Ok(print(exp)),
- }
- }
- }
+fn rep(str: &str) -> Result<String,MalError> {
+ let ast = try!(read(str.to_string()));
+ //println!("read: {}", ast);
+ let exp = try!(eval(ast));
+ Ok(print(exp))
}
fn main() {
loop {
let line = readline::mal_readline("user> ");
match line { None => break, _ => () }
- match rep(line.unwrap()) {
+ match rep(&line.unwrap()) {
Ok(str) => println!("{}", str),
Err(ErrMalVal(_)) => (), // Blank line
Err(ErrString(s)) => println!("Error: {}", s),