tailの実装
Posted feedbacks - Smalltalk
Squeak Smalltalk で、それっぽい動きをするものを。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | | filename file numOfLines isFollowMode lineCount savedPosition |
filename := 'in.txt'.
numOfLines := 10.
isFollowMode := false.
file := FileStream fileNamed: filename.
file setToEnd.
file binary.
lineCount := 0.
[file position > 0 and: [lineCount < numOfLines]]
whileTrue: [file back = 13 ifTrue: [lineCount := lineCount + 1]].
file ascii.
World findATranscript: nil.
Transcript cr; show: file upToEnd.
savedPosition := file position.
file close.
isFollowMode ifTrue: [
[Sensor keyboardPressed] whileFalse: [
(Delay forSeconds: 5) wait.
file reopen; position: savedPosition.
Transcript show: file upToEnd.
savedPosition := file position.
file close]]
|


takeru #6818() Rating-9/11=-0.82
'tail'を実装してください。
巨大なファイルでも効率的に動作するようにしてください。
最低限必要な機能は、
です。
[ reply ]