-
Notifications
You must be signed in to change notification settings - Fork 34
Ctrl-d 无法退出 #546
Copy link
Copy link
Closed
Description
;; calc-repl
;; 交互式计算循环
;;
;; 读取用户输入的表达式,计算并输出结果
(define (calc-repl)
(display "Goldfish Calc ")
(display CALC_VERSION)
(newline)
(display "高精度计算器,支持 + - * / 运算")
(newline)
(display "输入 'quit' 或 'exit' 退出")
(newline)
(newline)
(let loop ()
(display "> ")
(flush-output-port)
(let ((input (read-line)))
(cond
((eof-object? input)
(display "再见!")
(newline)
) ;
((string-null? (string-trim-both input))
(loop)
) ;
(else
(let ((trimmed (string-trim-both input)))
(if (or (string=? (string-downcase trimmed) "quit")
(string=? (string-downcase trimmed) "exit"))
(begin
(display "再见!")
(newline)
) ;begin
(let ((result (calc-eval (parse-infix input))))
(display "= ")
(display result)
(newline)
(loop)
) ;let
) ;if
) ;let
) ;else
) ;cond
) ;let
) ;let
) ;define
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels