[Pharo-project] doing bad things to Dictionaries.
So I've been doing some very bad things to dictionaries, and I've had to make a small change: 'From Pharo0.1 of 16 May 2008 [Latest update: #10342] on 8 July 2009 at 12:28:04 pm'! !Dictionary methodsFor: 'testing' stamp: 'djg 7/8/2009 11:53'! hasBindingThatBeginsWith: aString "Answer true if the receiver has a key that begins with aString, false otherwise" self keysDo:[:each | each ifNotNil: [ (each beginsWith: aString) ifTrue:[^true]]]. ^false! ! I'm occasionally had code blow up and was left with nil keys in my SystemDictionary (which may be a red herring), and SHParserST80 resolvePartial: was throwing fits as a result of what I believe was an environment key being nil. I doubt this is a suitable fix, but if someone know why that might happen I'd love to hear it. Dave -- -=-=-=-=-=-=-=-=-=-=- http://blog.dloh.org/
Why do you assume all keys of dictionarys understand beginsWith: ? Thanks mike On Wednesday, July 8, 2009, David Goehrig <dave@nexttolast.com> wrote:
So I've been doing some very bad things to dictionaries, and I've had to make a small change: 'From Pharo0.1 of 16 May 2008 [Latest update: #10342] on 8 July 2009 at 12:28:04 pm'!
!Dictionary methodsFor: 'testing' stamp: 'djg 7/8/2009 11:53'!hasBindingThatBeginsWith: aString "Answer true if the receiver has a key that begins with aString, false otherwise" self keysDo:[:each |Â each ifNotNil: [ (each beginsWith: aString) ifTrue:[^true]]]. ^false! !
I'm occasionally had code blow up and was left with nil keys in my SystemDictionary (which may be a red herring), and SHParserST80 resolvePartial: was throwing fits as a result of what I believe was an environment key being nil.
I doubt this is a suitable fix, but if someone know why that might happen I'd love to hear it. Dave -- -=-=-=-=-=-=-=-=-=-=- http://blog.dloh.org/
On Wed, Jul 8, 2009 at 1:06 PM, Michael Roberts <mike@mjr104.co.uk> wrote:
Why do you assume all keys of dictionarys understand beginsWith: ?
I don't. Someone else did. I just added a nil check to the code. There's probably bigger issues with this code. Dave -- -=-=-=-=-=-=-=-=-=-=- http://blog.dloh.org/
It certainly is not a generally applicable method for Dictionary (not all/most keys will not understand #beginsWith:), but for some senders, it might make sense, as it (I think) does for SystemDictionary. It would bother me less as a loose method packaged as part of something that "needs" it, but I would be inclined to deprecate/clean it if it is intended as part of the collection protocol. Clients/senders could always define something like #dictionary:hasKeyBeginningWith:. One of the great things about Smalltalk is the ability to add methods to system classes. This is probably not the best use of that freedom. Has this been of _any_ help? :) Bill ________________________________ From: pharo-project-bounces@lists.gforge.inria.fr [mailto:pharo-project-bounces@lists.gforge.inria.fr] On Behalf Of David Goehrig Sent: Wednesday, July 08, 2009 12:33 PM To: Pharo-project@lists.gforge.inria.fr Subject: Re: [Pharo-project] doing bad things to Dictionaries. On Wed, Jul 8, 2009 at 1:06 PM, Michael Roberts <mike@mjr104.co.uk<mailto:mike@mjr104.co.uk>> wrote: Why do you assume all keys of dictionarys understand beginsWith: ? I don't. Someone else did. I just added a nil check to the code. There's probably bigger issues with this code. Dave -- -=-=-=-=-=-=-=-=-=-=- http://blog.dloh.org/
ok well the context wasn't clear to be honest. Best thing to do is to create an issue on the tracker and try and describe a test case for invoking the problem. This is in preference to just patching code that doesn't look right. thanks, Mike 2009/7/8 Schwab,Wilhelm K <bschwab@anest.ufl.edu>:
It certainly is not a generally applicable method for Dictionary (not all/most keys will not understand #beginsWith:), but for some senders, it might make sense, as it (I think) does for SystemDictionary.  It would bother me less as a loose method packaged as part of something that "needs" it, but I would be inclined to deprecate/clean it if it is intended as part of the collection protocol. Clients/senders could always define something like #dictionary:hasKeyBeginningWith:.
One of the great things about Smalltalk is the ability to add methods to system classes. This is probably not the best use of that freedom. Has this been of _any_ help? :)
Bill
________________________________ From: pharo-project-bounces@lists.gforge.inria.fr [mailto:pharo-project-bounces@lists.gforge.inria.fr] On Behalf Of David Goehrig Sent: Wednesday, July 08, 2009 12:33 PM To: Pharo-project@lists.gforge.inria.fr Subject: Re: [Pharo-project] doing bad things to Dictionaries.
On Wed, Jul 8, 2009 at 1:06 PM, Michael Roberts <mike@mjr104.co.uk> wrote:
Why do you assume all keys of dictionarys understand beginsWith: ?
I don't. Someone else did. Â I just added a nil check to the code. Â There's probably bigger issues with this code. Dave
-- -=-=-=-=-=-=-=-=-=-=- http://blog.dloh.org/
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
+1 On Jul 8, 2009, at 11:57 PM, Michael Roberts wrote:
ok well the context wasn't clear to be honest. Best thing to do is to create an issue on the tracker and try and describe a test case for invoking the problem. This is in preference to just patching code that doesn't look right.
thanks, Mike
2009/7/8 Schwab,Wilhelm K <bschwab@anest.ufl.edu>:
It certainly is not a generally applicable method for Dictionary (not all/most keys will not understand #beginsWith:), but for some senders, it might make sense, as it (I think) does for SystemDictionary. It would bother me less as a loose method packaged as part of something that "needs" it, but I would be inclined to deprecate/clean it if it is intended as part of the collection protocol. Clients/senders could always define something like #dictionary:hasKeyBeginningWith:.
One of the great things about Smalltalk is the ability to add methods to system classes. This is probably not the best use of that freedom. Has this been of _any_ help? :)
Bill
________________________________ From: pharo-project-bounces@lists.gforge.inria.fr [mailto:pharo-project-bounces@lists.gforge.inria.fr] On Behalf Of David Goehrig Sent: Wednesday, July 08, 2009 12:33 PM To: Pharo-project@lists.gforge.inria.fr Subject: Re: [Pharo-project] doing bad things to Dictionaries.
On Wed, Jul 8, 2009 at 1:06 PM, Michael Roberts <mike@mjr104.co.uk> wrote:
Why do you assume all keys of dictionarys understand beginsWith: ?
I don't. Someone else did. I just added a nil check to the code. There's probably bigger issues with this code. Dave
-- -=-=-=-=-=-=-=-=-=-=- http://blog.dloh.org/
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
participants (4)
-
David Goehrig -
Michael Roberts -
Schwab,Wilhelm K -
Stéphane Ducasse