sumim #4475(2007/11/29 05:42 GMT) [ Smalltalk ] Rating0/0=0.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| pathList tree dumpTree | pathList := #('abc\def' 'abc\def\gh' 'abc\def\ij' 'abc\jk\lm' 'de'). tree := Dictionary new. pathList do: [:path | (path subStrings: #($\)) inject: tree into: [:tr :dir | tr at: dir ifAbsentPut: [Dictionary new]]]. dumpTree := [:tr :lev | tr keys asSortedCollection do: [:key | Transcript crtab: lev; show: key. (tr at: key) ifNotEmptyDo: [:child | dumpTree copy fixTemps value: child value: lev + 1]]]. World findATranscript: nil. dumpTree copy fixTemps value: tree value: 0 "=> abc def gh ij jk lm de "
Rating0/0=0.00-0+
[ reply ]
sumim
#4475()
[
Smalltalk
]
Rating0/0=0.00
感動したので、Squeak Smalltalk に意訳させていただきました。
| pathList tree dumpTree | pathList := #('abc\def' 'abc\def\gh' 'abc\def\ij' 'abc\jk\lm' 'de'). tree := Dictionary new. pathList do: [:path | (path subStrings: #($\)) inject: tree into: [:tr :dir | tr at: dir ifAbsentPut: [Dictionary new]]]. dumpTree := [:tr :lev | tr keys asSortedCollection do: [:key | Transcript crtab: lev; show: key. (tr at: key) ifNotEmptyDo: [:child | dumpTree copy fixTemps value: child value: lev + 1]]]. World findATranscript: nil. dumpTree copy fixTemps value: tree value: 0 "=> abc def gh ij jk lm de "Rating0/0=0.00-0+