mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
examples/mini_calculator.v: handle ctrl-d gracefully
This commit is contained in:
parent
6201e78201
commit
b5f8a04778
@ -2,9 +2,7 @@
|
||||
// A: This is a mini "home-made" calculator. You may also regard it as a very elementary version of "interpreter".
|
||||
import os
|
||||
|
||||
const (
|
||||
numeric_char = [`0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `.`, `e`, `E`]
|
||||
)
|
||||
const numeric_char = [`0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `.`, `e`, `E`]
|
||||
|
||||
// Convert expression to Reverse Polish Notation.
|
||||
fn expr_to_rev_pol(expr string) ?[]string {
|
||||
@ -117,7 +115,10 @@ fn main() {
|
||||
mut expr_count := 0
|
||||
for {
|
||||
expr_count++
|
||||
expr := os.input('[$expr_count] ').trim_space()
|
||||
expr := os.input_opt('[$expr_count] ') or {
|
||||
println('')
|
||||
break
|
||||
}.trim_space()
|
||||
if expr in ['exit', 'EXIT'] {
|
||||
break
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user