Article View: gnu.smalltalk.bug
Article #26Re: GNU Smalltalk SampleSpaceWithoutReplacem
From: Mark Bush
Date: Thu, 07 Jan 1993 15:46
Date: Thu, 07 Jan 1993 15:46
41 lines
1881 bytes
1881 bytes
In article <930106230330_73300.2046_EHJ21-1@CompuServe.COM> 73300.2046@compuserve.COM (Jim Pannozzi 73300.2046@compuserve.com) writes:
# "Error: the method is the responsibility of the subclass".
#
#Date 1-6-93.
#
#Smaltalk Version 1.1.1
#
#Bug: Fails to do a ^data remove: super next
The bug is that OrderedCollection does not define a method for
#remove:ifAbsent:
The Blue Book does state that OrderedCollection should support #remove:, and
in GNU Smalltalk, this is defined in Collection as:
remove: oldObject
self remove: oldObject
ifAbsent: [ ^self error: 'Failed to remove object' ].
^oldObject
This is still missing in version 1.2 (at least my version). To make the
example from Chapter 11 work, try adding something like:
!OrderedCollection methodsFor: 'removing'!
remove: anElement ifAbsent: errorBlock
| newCollection notFound |
(self includes: anElement)
ifFalse: errorBlock.
newCollection := OrderedCollection new: self basicSize.
notFound := true.
self do: [ :elem | (notFound and: [elem = anElement])
ifFalse: [ newCollection add: elem ]
ifTrue: [ notFound := false ] ].
self become: newCollection.
^anElement
!!
This works, but is probably not the best way of implementing this.
Mark
Technical Details
Message-ID:
<1993Jan7.154627.9262@thom5.ecs.ox.ac.uk>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!prg.ox.ac.UK!Mark.BushReferences:
<930106230330_73300.2046_EHJ21-1@CompuServe.COM>Show Full Headers
Complete Article Headers
Newsgroups: gnu.smalltalk.bug Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!prg.ox.ac.UK!Mark.Bush From: Mark.Bush@prg.ox.ac.UK (Mark Bush) Subject: Re: GNU Smalltalk SampleSpaceWithoutReplacem Message-ID: <1993Jan7.154627.9262@thom5.ecs.ox.ac.uk> Sender: gnulists@ai.mit.edu Organization: Oxford University Computing Laboratory References: <930106230330_73300.2046_EHJ21-1@CompuServe.COM> Distribution: gnu Date: Thu, 7 Jan 1993 15:46:27 GMT Approved: bug-smalltalk@prep.ai.mit.edu Lines: 42