"- Calculator -".println "Type = to set the value to that number.".println "Type +, -, * or / to change the value.".println "Type exit or press CTRL+D to exit.".println current := 0.0 loop { ("[ ", current, " ]").concat.println ().read_line.try( (line) -> { input := line.trim num := (input, 1).substring.trim.parse_float.try( (val) -> val () -> 0.0 ) mode := input.substring(0, 1) if mode.eq("+") { ¤t = (current, num).sum } else if mode.eq("-") { ¤t = (current, (num, -1).product).sum } else if mode.eq("*") { ¤t = (current, num).product } else if mode.eq("/") { ¤t = (current, num).div } else if mode.eq("=") { ¤t = num } else if input.eq("exit") { (()) } else { "Expected one of +-*/= followed by a number".eprintln } } // CTRL+D () -> (()) ) }