I'm porting some code from lisp, but I got stuck at this part (apparently that's for mit-scheme)
(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)))
Of course I could just skip that and implement what the comments say it does, but just wanted to be sure there's no magic happening in the background. So... how does this function even work -- where is it actually reading the characters? Is it as ugly as I think and does it consume the characters as a side-effect in the last check in end-of-sentence?
? Or does the char-ready?
actually read something?
But then again - what does (end-of-sentence?) (c-g-iter (+ num 1))
mean, as I don't expect c-g-iter
to return a word.