文件统计在计划中 [英] File Stats in Scheme
本文介绍了文件统计在计划中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
countup
,称为: file1)
看起来循环无限期运行。为什么,我该如何解决这个问题?
(define stats
$ b $从文件中读取字符的程序必须有这个条件: b
(lambda(srcf)
开始
(定义在(open-input-file srcf))
(let loop(
(l 0)
(w 0)
(c 0)
((#())
(char(read-char in)))
(case char
((#\ newline)
(loop(+ l 1)w(+ c 1) -char in)))
((#\space#\tab)
(loop l(+ w 1)(+ c 1)(read-char in)))
(else)(loop lw(+ c 1)(read-char in))))
)
(close-input-port in)
(display l)
$($$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b)
;; srcf =源文本文件
(define countup
(lambda(srcf lstf)
(stats srcf)
)
)
(cond((eof-object?the-char)
'finished)
...)
看看这个回答看到一个类似于你正在编写的程序,这可能是有帮助的。
I'll be upfront: this is Homework. The following code defines a function
countup
, called as:(countup "file1")
It appears that the loop is running indefinitely. Why, and how can I fix this?
(define stats (lambda (srcf) (begin (define in (open-input-file srcf)) (let loop ( (l 0) (w 0) (c 0) (char (read-char in))) (case char ((#\newline) (loop (+ l 1) w(+ c 1) (read-char in))) ((#\space #\tab) (loop l (+ w 1) (+ c 1) (read-char in))) (else (loop l w (+ c 1) (read-char in)))) ) (close-input-port in) (display l) (display " ") (display w) (display " ") (display c) (newline) '())) ) ;; srcf = source text file (define countup (lambda (srcf lstf) (stats srcf) ) )
解决方案A program that reads characters from a file must have this condition somewhere:
(cond ((eof-object? the-char) 'finished) ...)
Take a look at this answer to see a procedure similiar to the one you're writing, it might be helpful.
这篇关于文件统计在计划中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文