我移植从LISP一些代码,但我被困在这部分(显然这是麻省理工学院的方案)Lisp代码的解释
(define (end-of-sentence? word)
(and (or (char-exist-last? word '#\.)
(char-exist-last? word '#\!)
(char-exist-last? word '#\?))
(not (initial? word))
(or (eq? (peek-char) '#\Space) ;;peek- so test for linefeed isn't affected
(eq? (peek-char) '#\n) ;;note- test for space isn't neccessary
(eq? (read-char) '#\t))))
;;counts the number of sentences in a given file and
;;stops at the given number
;;returns true once at that position, returns error if eof
(define (goto-sentence? file stop)
(define (c-g-iter num)
(cond ((= num stop)
#t)
((end-of-sentence?)
(c-g-iter (+ num 1)))
((not (char-ready?))
(error "EOF reached, number to large in goto-sentence?: " stop))
(else
(c-g-iter num))))
(begin
(open-path file)
(c-g-iter 1)))
当然我可以只跳过和实施意见说什么它确实,但只是想确保背景中没有魔术发生。所以...这个功能如何工作 - 它实际上在哪里阅读角色?它是否和我想象的一样丑陋,是否会在end-of-sentence?
的最后一次检查中消耗字符作为副作用?还是char-ready?
实际上读了什么?
但是再次 - (end-of-sentence?) (c-g-iter (+ num 1))
是什么意思,因为我不期望c-g-iter
返回一个单词。