Message-ID: <31727429.2AA@rwi.com>
Date: Mon, 15 Apr 1996 11:07:05 -0500
From: Rupert Bruce <rbruce@rwi.com>
Organization: RothWell international
X-Mailer: Mozilla 2.0 (X11; I; HP-UX A.09.05 9000/715)
MIME-Version: 1.0
Newsgroups: comp.lang.smalltalk
Subject: Re: (newbie) problem
References: <4knu6e$s9d@nyheter.chalmers.se> <316FB577.25B@charm.net>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: quasar.rwi.com
Lines: 53
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!newsfeed.internetmci.com!howland.reston.ans.net!news.sprintlink.net!wally2.hti.net!

Tommy Hallgren wrote:
>
> Hi!
>
> I'm a newbie to Smalltalk using IBM Smalltalk (OS/2) and I'm trying to do a simple Alphapet game
> which builds it's vocabulary while playing. Imagine beating that program after playing 10-100
> games. :)
>
> Anyway, I've bumped into a little problem. I've a class that takes a character and return it's
> value.
>
>         Bokstav new value: 'A'.
>
> Gives me the value of 'A'. The class 'Bokstav' uses Dictionary internally to store each
> characters value.
>
> The problem occures in the vocabulary class where I want to calculate how much a while string is
> worth. The code looks something like this:
>
> value: aWord
>         | sum |
>
>         sum := 0.
>
>         1 to aWord size do:
>         [ :pos |
>                 sum := sum + Bokstav new value: (aWord at: pos).
>         ].
>
>         ^sum.
>
> The error occurs at "sum := sum + ..." line. It works just fine if I write:
>
>         sum := sum + Bokstav new value: 'A'.
>
> It seems to me that "aWord at: pos" returns a strange object.
>
> Can someone help me?
>
> /Tommy

Just a little note on style (and save yourself some keypresses!):

value: aWord
         | sum |

         sum := 0.

         aWord do: 	[ :letter |
			"*see note"
                 	sum := sum + (Bokstav new value: letter).
         		].

         ^sum.


* try putting the following code here and confirming that the value
being put into Bokstav is what you want (ie. a String):
	letter inspect.
