我知道你可以使用(read)来获取用户输入的表达式,但是(read)只会得到第一个表达式,之后会对其进行评估.我想知道是否有任何方法可以读取整行用户输入,或许将所述行转换为列表?
(let ((input (read-user-line)))
;; user could type "cons 2 3" without quotes
;; input could contain '(cons 2 3)
(apply (car input) (cdr input)))
Run Code Online (Sandbox Code Playgroud)
谢谢!
If your Scheme is an R6RS implementation, you can use GET-LINE. If that same Scheme implements SRFI-13 as well, you can use STRING-TOKENIZE to turn it into a list.
One Scheme that qualifies is Ypsilon:
(import (srfi srfi-13))
(let ((input (get-line (current-input-port))))
(for-each (lambda (x) (display x) (newline))
(string-tokenize input)))
$ ypsilon try.scm the quick brown fox jumps over the lazy dog. the quick brown fox jumps over the lazy dog.
Otherwise you are on your own with whatever non-standard extensions your implementation provides.