19/03/21 11:30:55.91 4Lv8Ku6J.net
>>494 Squeak Smalltalk。コンマを分割と見なしそれぞれについての和を出力させてみた
| fn |
fn := [:columnName |
FileStream oldFileNamed: 'data.txt' do: [:file |
| index sum |
index := (file nextLine subStrings: ' ') indexOf: columnName.
sum := 0.
[file atEnd] whileFalse: [
| next |
next := ((file nextLine subStrings: ' ') at: index) subStrings: ','.
sum := sum + (next size = 1 ifTrue: [next anyOne] ifFalse: [next])].
sum
]
].
fn value: 'カラム3'. "=> 7.1 "
fn value: 'カラム1'. "=> #(3.1 2.1) "