I was looking at all the #doWithIndex:-like methods and decided a
deprecation tag might be good, at least for my own code.  I'm not even
sure I'm going to use it in my own code, but it gave me a chance to
break WeakSet, so

[EMAIL PROTECTED]/smalltalk--backstage--2.2--patch-30
    support #includes: on WeakSets

against upstream patch-393, attached as weakset-includes.diff.

Based on a search for findIndex in HashedCollection, I don't think any
other methods are affected.

Also attached is Deprecation.st.  Its Commentary section explains its
use.  The biggest benefit is being able to write "self deprecate: 'I am
poorly written'" and such in your code. :)

I'm happy to change the license if you want to include it in gst.

-- 
;;; Stephen Compall ** http://scompall.nocandysw.com/blog **
"Peta" is Greek for fifth; a petabyte is 10 to the fifth power, as
well as fifth in line after kilo, mega, giga, and tera.
  -- Lee Gomes, performing every Wednesday in his tech column
     "Portals" on page B1 of The Wall Street Journal
2007-06-10  Stephen Compall  <[EMAIL PROTECTED]>

	* kernel/WeakObjects.st: Add #includes: to WeakSet, as the
	inherited method doesn't work with this class.  Add
	#identityIncludes: to WeakIdentitySet.

--- orig/kernel/WeakObjects.st
+++ mod/kernel/WeakObjects.st
@@ -264,6 +264,11 @@
     ^anObject
 !
 
+includes: anObject
+    "Answer whether I contain anObject."
+    ^super includes: (HomedAssociation key: anObject value: nil environment: self)
+!
+
 remove: anObject ifAbsent: aBlock
     "Remove oldObject to the set. If it is found, answer oldObject.
      Otherwise, evaluate aBlock and return its value."
@@ -470,6 +475,14 @@
 ! !
 
 
+!WeakIdentitySet methodsFor: 'accessing'!
+
+identityIncludes: anObject
+    "Answer whether I include anObject exactly.  As I am an
+     identity-set, this is the same as #includes:."
+    ^self includes: anObject
+! !
+
 !WeakIdentitySet methodsFor: 'private methods'!
 
 hashFor: anObject
"Deprecation.st: A warning about calling deprecated methods.
Copyright (C) 2007  Stephen Compall.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA"

"Commentary

I include a brief Warning class called Deprecation and a method on
Object.  You can put

    self deprecate: 'use keysAndValuesDo: instead'.

at the beginning of deprecated methods, and on their first call, a
Deprecation will be signalled with the message given.

This could be sped up by using Presource to put a cookie in every self
deprecate: send, but you shouldn't use deprecated methods anyway."

"Code"

Warning subclass: #Deprecation
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'Language-Exceptions'
!

Deprecation class instanceVariableNames: 'usedMethods'!

Deprecation comment:
'I am signalled by methods that want to report that they shouldn''t be
called anymore.'
!

!Deprecation class methodsFor: 'signalling'!

deprecate: aMethod reporting: aString
    "If I have not signalled a Deprecation for aMethod yet, signal one
     now, adding aString as an additional note."
    ^(usedMethods includes: aMethod) ifFalse:
        [usedMethods add: aMethod.
         self signal: ('%1 is deprecated: %2'
                           bindWith: aMethod with: aString)]
! !

!Deprecation class methodsFor: 'initialization'!

initialize
    super initialize.
    usedMethods := WeakIdentitySet new.
! !

!Smalltalk.Object methodsFor: 'deprecating'!

deprecate: message
    "Deprecate the sending method, including message in the warning
     text if any is given."
    ^Deprecation deprecate: thisContext sender method
                 reporting: message
! !

Deprecation initialize!

"Deprecation.st ends here"

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to