【发布时间】:2016-04-05 14:00:42
【问题描述】:
Racket 似乎无法从 STDIN 读取字符串。
$ racket
Welcome to Racket v6.4.
-> (define (s) (read-line))
好的,s 是调用 read-line 的别名。
-> (printf "You entered: ~a\n" s)
You entered:
失败:打印字符串,但 Racket 不等待按键/STDIN/EOF/EOL。
-> (define n (read))
a
-> n
'a
失败:这会调用 read 并等待 EOF / EOL,然后分配给 n,但 n 被分配了符号 'a 不是 字符串文字 a。
-> (read-line)
""
失败:调用read-line 不等待STDIN,只返回空字符串。
-> (read-string 5)
asdasdasdasd
"\nasda"
; sdasdasd: undefined;
; cannot reference undefined identifier
; [,bt for context]
失败:只读取了 5 个字节的 STDIN,显然是 evals 的其余部分...?
-> (read-string 500000)
asdasd
asdasdaas
a
asdasd
asdasd
asdasd
失败:在准确读取 500000 个字节之前不会返回,并且不会在 EOL 时返回。
有点像 Python 的input(),它在找到EOL 时返回一个字符串,或者Factor 的readln,它的作用相同,我如何从current-input-port 读取原始数据?
【问题讨论】: