Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!haven!mimsy!tove.umd.edu!folta From: folta@tove.umd.edu (Wayne Folta) Newsgroups: comp.lang.smalltalk Subject: Smalltalk (maybe only Smalltalk/V) quest. Message-ID: <17280@mimsy.UUCP> Date: 3 May 89 21:48:00 GMT Sender: nobody@mimsy.UUCP Reply-To: folta@tove.umd.edu.UUCP (Wayne Folta) Distribution: usa Organization: U of Maryland, Dept. of Computer Science, gs Lines: 31 I just got Smalltalk/V Mac last night, and I was running through the book that comes with it. One of their examples does not work, however, and I wonder if my question is Smalltalk- or Smalltalk/V-specific: it has to do with Smalltalk/V's Bags class. Is this a standard class in most Smalltalk implementations, or is it Smalltalk/V-specific? As for the question... they give a program in Pascal that counts the occurrences of letters in an input string. Then they show the Pascal-like Smalltalk code to do the same thing, which is about 25% shorter. Then, they give a "native" Smalltalk version, which is only 5 lines: |s f| s := Prompter prompt: 'enter line' default: ''. f := Bag new. s do: [:c | c isLetter ifTrue: [f add: c asLowerCase]]. ^f It is impressive to see how much more efficient Smalltalk can be, until you actually evaluate the program. 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. What is the most Smalltalk- like way (if there is such a thing) to accomplish this? Maybe something like: ^'abcdefghijklmnopqrstuvwxyz' collect: [:c | f occurrencesOf: c] (Which gives me an error which I--novice that I am--don't understand.) Wayne Folta (folta@tove.umd.edu 128.8.128.42)