Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!decwrl!shelby!labrea!rutgers!rochester!pt.cs.cmu.edu!andrew.cmu.edu!sa1z+ From: sa1z+@andrew.cmu.edu (Sudheer Apte) Newsgroups: comp.lang.smalltalk Subject: Re: Smalltalk (maybe only Smalltalk/V) quest. Message-ID: <4YM4BGy00WB70PfHlo@andrew.cmu.edu> Date: 4 May 89 12:34:26 GMT References: <17280@mimsy.UUCP> Distribution: usa Organization: Civil Engineering, Carnegie Mellon, Pittsburgh, PA Lines: 32 folta@tove.umd.edu writes <17280@mimsy.UUCP>: > |s f| > s := Prompter prompt: 'enter line' default: ''. > f := Bag new. > s do: [:c | c isLetter ifTrue: [f add: c asLowerCase]]. > ^f >... >The problem is that it *does not* result in an array with the number of >occurrences, it results in a Bag containing all of the letters. One more >step is needed to get the number of occurrences... Good to hear that your problem was subsequently solved, but I think this code does indeed return the occurrences of each letter-- though not in the Pascal-like way of returning an array full of numbers. A bag can be considered (and used) as an array indexed by the elements, so that f occurrencesOf: ch where ch is a character is a ``lookup'' in the array. After all, how would one be using such an array of occurrences? I think this *is* the most ``Smalltalk-like'' way of solving the problem! Thanks, Sudheer. ---------------- Sudheer Mukund Apte sa1z@andrew.cmu.edu Civil Engineering Department, Carnegie-Mellon University, ...!harvard!andrew.cmu.edu!sa1z Pittsburgh, PA 15213 ------------------------------------------------------------------------