[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-smalltalk] problems with nil balance in gst tutorial
From: |
Brian Wisti |
Subject: |
[Help-smalltalk] problems with nil balance in gst tutorial |
Date: |
Mon, 1 Nov 2004 17:13:11 -0800 (PST) |
Hi all,
I am new to the list and new to smalltalk as well, and I need some
help.
I downloaded and compiled GNU Smalltalk 2.1.8 this morning, and started
working my way through the tutorial. For some reason, I get stuck
partway into the Account class. "Account printNl" always shows 'an
Account with balance: nil', and attempting to use the "spend" or
"deposit" methods results in error messages. My code and output is at
the end of this message.
An message on this mailing list from last year mentioned a
similar-sounding bug, and the possibility that the JIT might be to
blame. Has any progress been made in figuring out why this problem
happens for some users?
Kind Regards,
Brian Wisti
-- The Code --
Object subclass: #Account
instanceVariableNames: 'balance'
classVariableNames: ''
poolDictionaries: ''
category: nil
!
Account comment:
'I represent a place to deposit and withdraw money'
!
!Account methodsFor: 'instance creation'!
new
| r |
r := super new.
r init.
^r
! !
!Account methodsFor: 'instance initialization'!
init
balance := 0
! !
!Account methodsFor: 'printing'!
printOn: stream
super printOn: stream.
stream nextPutAll: ' with balance: '.
balance printOn: stream
! !
!Account methodsFor: 'moving money'!
spend: amount
balance := balance - amount.
!
deposit: amount
balance := balance + amount.
! !
Smalltalk at: #a put: (Account new) !
a printNl !
a deposit: 15!
a spend: 5!
a printNl !
-- Sample usage results
bash-2.03$ gst account.st
an Account with balance: nil
Object: nil error: did not understand #+
UndefinedObject(Object)>>#doesNotUnderstand:
Account>>#deposit:
UndefinedObject>>#executeStatements
Object: nil error: did not understand #-
UndefinedObject(Object)>>#doesNotUnderstand:
Account>>#spend:
UndefinedObject>>#executeStatements
an Account with balance: nil
bash-2.03$
- [Help-smalltalk] problems with nil balance in gst tutorial,
Brian Wisti <=