From b5f8a0477826a25c4834aba7698e1d16f853ce9a Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 20 Aug 2021 10:07:41 +0300 Subject: [PATCH] examples/mini_calculator.v: handle ctrl-d gracefully --- examples/mini_calculator.v | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/mini_calculator.v b/examples/mini_calculator.v index 4663f4c54..0c22aa380 100644 --- a/examples/mini_calculator.v +++ b/examples/mini_calculator.v @@ -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 } -- 2.30.2