doing bad things to Dictionaries.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

doing bad things to Dictionaries.

David Goehrig
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/

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: doing bad things to Dictionaries.

Michael Roberts-2
Why do you assume all keys of dictionarys understand beginsWith: ?

Thanks
mike
On Wednesday, July 8, 2009, David Goehrig <[hidden email]> 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/
>
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: doing bad things to Dictionaries.

David Goehrig
On Wed, Jul 8, 2009 at 1:06 PM, Michael Roberts <[hidden email]> 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
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: doing bad things to Dictionaries.

Schwab,Wilhelm K
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: [hidden email] [mailto:[hidden email]] On Behalf Of David Goehrig
Sent: Wednesday, July 08, 2009 12:33 PM
To: [hidden email]
Subject: Re: [Pharo-project] doing bad things to Dictionaries.

On Wed, Jul 8, 2009 at 1:06 PM, Michael Roberts <[hidden email]> 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
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: doing bad things to Dictionaries.

Michael Roberts-2
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 <[hidden email]>:

> 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: [hidden email]
> [mailto:[hidden email]] On Behalf Of David
> Goehrig
> Sent: Wednesday, July 08, 2009 12:33 PM
> To: [hidden email]
> Subject: Re: [Pharo-project] doing bad things to Dictionaries.
>
> On Wed, Jul 8, 2009 at 1:06 PM, Michael Roberts <[hidden email]> 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
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: doing bad things to Dictionaries.

Stéphane Ducasse
+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 <[hidden email]>:
>> 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: [hidden email]
>> [mailto:[hidden email]] On Behalf Of  
>> David
>> Goehrig
>> Sent: Wednesday, July 08, 2009 12:33 PM
>> To: [hidden email]
>> Subject: Re: [Pharo-project] doing bad things to Dictionaries.
>>
>> On Wed, Jul 8, 2009 at 1:06 PM, Michael Roberts <[hidden email]>  
>> 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
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project