Skip to content

Ctrl-d 无法退出 #546

@da-liii

Description

@da-liii
    ;; 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions