Input

  • Function: read-char read-line read

Output

  • Function: write-char write display newline

write会向端口写一个S表达式(机器可读),display不需要
write用双引号表示字符串,#\表示字符,display不用
newline会在输出端口输出一个换行符

File IO Port

  • Function: open-input-file call-with-input-file call-with-output-file
1
2
3
4
5
6
7
8
9
(define o (open-output-file "greeting.txt"))
(display "hello" o)

(call-with-input-file "hello.txt
(lambda (i)
(let* ((a (read-char i))
(b (read-char i))
(c (read-char i)))
(list a b c))))

String IO Port

  • Function: open-input-string open-output-string get-output-string
1
2
3
4
5
6
7
8
(define i (open-input-string "hello world"))
(read i)
; ==> hello

(define o (open-output-string))
(write 'hello o)
(get-output-string o)
; ==> "hello, world"

Load

laod可以加载Scheme文件的代码,针对S表达式进行求值