我正在尝试创建一个循环,询问命令,执行命令,然后再循环.只有输入的命令是"退出"才会退出.我尝试了几个不同的东西,但是当我运行它们时,它们工作一次(read-line)读取#然后无限地执行此操作而不等待输入.我最初的尝试看起来像这样:
(define (inputLoop)
(define command "init")
(do()((equal? command "exit") (display "exited successfully..."))
(display "What would you like to do?(start,stop,exit)")
(set! command (read-line))
(cond [(equal? command "start") (start)]
[(equal? command "stop") (stop)]
[else (void)])))
Run Code Online (Sandbox Code Playgroud)
我的下一次尝试是类似的,但是如果命令不是"退出",它只是递归地调用名为inputLoop的函数而不是使用do循环.
以下是输出示例:
What would you like to do?(start,stop,exit)start
What would you like to do?(start,stop,exit)
What would you like to do?(start,stop,exit)
...<thousands-of-lines-here>
What would you like to do?(start,stop,exit)
What would you like to do?(start,stop,exit)
What would you like to do?(start,stop,exit)exit
exited successfully...
Run Code Online (Sandbox Code Playgroud) racket ×1