A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-cwp.492.mcz ==================== Summary ==================== Name: Collections-cwp.492 Author: cwp Time: 22 October 2012, 12:42:48.371 am UUID: 692da7f2-5a98-47ee-bd1c-e8666206f6ed Ancestors: Collections-fbs.490 Tweak #numArgs, so that Strings respect the #allowUnderscoreSelectors preference, but Symbols don't. =============== Diff against Collections-fbs.490 =============== Item was changed: ----- Method: String>>numArgs (in category 'accessing') ----- numArgs "Answer either the number of arguments that the receiver would take if considered a selector. Answer -1 if it couldn't be a selector. Note that currently this will answer -1 for anything begining with an uppercase letter even though the system will accept such symbols as selectors. It is intended mostly for the assistance of spelling correction." | firstChar numColons excess start ix | self size = 0 ifTrue: [^ -1]. firstChar := self at: 1. (firstChar isLetter or: [firstChar = $:]) ifTrue: ["Fast reject if any chars are non-alphanumeric NOTE: fast only for Byte things - Broken for Wide" + self class isBytes + ifTrue: [(self findSubstring: '~' in: self startingAt: 1 matchTable: Tokenish) > 0 ifTrue: [^ -1]] + ifFalse: [2 to: self size do: [:i | (self at: i) tokenish ifFalse: [^ -1]]]. - Scanner prefAllowUnderscoreSelectors ifFalse: - [self class isBytes - ifTrue: [(self findSubstring: '~' in: self startingAt: 1 matchTable: Tokenish) > 0 ifTrue: [^ -1]] - ifFalse: [2 to: self size do: [:i | (self at: i) tokenish ifFalse: [^ -1]]]]. "Fast colon count" numColons := 0. start := 1. [(ix := self indexOf: $: startingAt: start) > 0] whileTrue: [numColons := numColons + 1. start := ix + 1]. numColons = 0 ifTrue: [^ 0]. firstChar = $: ifTrue: [excess := 2 "Has an initial keyword, as #:if:then:else:"] ifFalse: [excess := 0]. self last = $: ifTrue: [^ numColons - excess] ifFalse: [^ numColons - excess - 1 "Has a final keywords as #nextPut::andCR"]]. firstChar isSpecial ifTrue: [self size = 1 ifTrue: [^ 1]. 2 to: self size do: [:i | (self at: i) isSpecial ifFalse: [^ -1]]. ^ 1]. ^ -1.! Item was added: + ----- Method: Symbol>>numArgs (in category 'accessing') ----- + numArgs + "Answer either the number of arguments that the receiver would take if considered a selector. Answer -1 if it couldn't be a selector. Note that currently this will answer -1 for anything begining with an uppercase letter even though the system will accept such symbols as selectors. It is intended mostly for the assistance of spelling correction." + + | firstChar numColons excess start ix | + self size = 0 ifTrue: [^ -1]. + firstChar := self at: 1. + (firstChar isLetter or: [firstChar = $:]) ifTrue: + [2 to: self size do: + [:i || c | + c := self at: i. + (c = $_ or: [c tokenish]) ifFalse: [^ -1]]. + "Fast colon count" + numColons := 0. start := 1. + [(ix := self indexOf: $: startingAt: start) > 0] + whileTrue: + [numColons := numColons + 1. + start := ix + 1]. + numColons = 0 ifTrue: [^ 0]. + firstChar = $: + ifTrue: [excess := 2 "Has an initial keyword, as #:if:then:else:"] + ifFalse: [excess := 0]. + self last = $: + ifTrue: [^ numColons - excess] + ifFalse: [^ numColons - excess - 1 "Has a final keywords as #nextPut::andCR"]]. + firstChar isSpecial ifTrue: + [self size = 1 ifTrue: [^ 1]. + 2 to: self size do: [:i | (self at: i) isSpecial ifFalse: [^ -1]]. + ^ 1]. + ^ -1.! |
On Mon, Oct 22, 2012 at 12:42 AM, <[hidden email]> wrote:
> Tweak #numArgs, so that Strings respect the #allowUnderscoreSelectors preference, but Symbols don't. I think this batch of changes means we can turn #allowUnderscoreSelectors on by default. Looking through the senders of #numArgs, I noticed that many of them were messages to a selector. In those cases, the selector might contain underscores, even though the preference disallows them, so I made Symbol>>numArgs behave differently than String>>numArgs. Unless somebody objects, I'll move these to the trunk soonish. |
I'm a bit lost about which methods will get into the Trunk, since every
package has two versions with different content. For example Collections-cwp.491 extracts String class >> #initializeTokenish from #initialize, while Collections-cwp.492 don't. Also both versions containting changes to Scanner class >> #prefAllowUnderscoreSelectors: send String class >> #initialize instead of #initializeTokenish. Another thing is that the support for initial and final keywords is gone long ago, only #numArgs has traces of it, which should be removed. Levente On Mon, 22 Oct 2012, Colin Putney wrote: > On Mon, Oct 22, 2012 at 12:42 AM, <[hidden email]> wrote: > >> Tweak #numArgs, so that Strings respect the #allowUnderscoreSelectors preference, but Symbols don't. > > I think this batch of changes means we can turn > #allowUnderscoreSelectors on by default. > > Looking through the senders of #numArgs, I noticed that many of them > were messages to a selector. In those cases, the selector might > contain underscores, even though the preference disallows them, so I > made Symbol>>numArgs behave differently than String>>numArgs. > > Unless somebody objects, I'll move these to the trunk soonish. > > |
On Mon, Oct 22, 2012 at 8:56 AM, Levente Uzonyi <[hidden email]> wrote:
> I'm a bit lost about which methods will get into the Trunk, since every > package has two versions with different content. For example > Collections-cwp.491 extracts String class >> #initializeTokenish from > #initialize, while Collections-cwp.492 don't. Also both versions containting > changes to Scanner class >> #prefAllowUnderscoreSelectors: send String class >>> #initialize instead of #initializeTokenish. Yeah, sorry about that. I committed to the inbox, then realized that I was working from an outdated image. I've moved those first commits to inbox-treated. The versions that are still in the inbox are the ones that would be moved to the trunk. > Another thing is that the support for initial and final keywords is gone > long ago, only #numArgs has traces of it, which should be removed. Ok. I didn't really understand that stuff, so I left it alone. I'll do another version. Colin |
Free forum by Nabble | Edit this page |