The Inbox: Collections-mt.833.mcz

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

The Inbox: Collections-mt.833.mcz

commits-2
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-mt.833.mcz

==================== Summary ====================

Name: Collections-mt.833
Author: mt
Time: 13 May 2019, 9:46:28.73801 am
UUID: 44057ed3-9b55-0b49-8472-71d5c3fdbeeb
Ancestors: Collections-mt.832

Second iteration of #take: (and #any:). #any: relates to #anyOne and thus signals an error if the collection is not large enough. #take: uses #any: but accounts for smaller collections.

=============== Diff against Collections-mt.832 ===============

Item was added:
+ ----- Method: CharacterSet>>any: (in category 'accessing') -----
+ any: numberOfElements
+
+ ^ self any: numberOfElements as: Array!

Item was added:
+ ----- Method: CharacterSet>>any:as: (in category 'accessing') -----
+ any: numberOfElements as: aClass
+
+ self canBeEnumerated
+ ifTrue: [^ super any: numberOfElements as: aClass]
+ ifFalse: [self shouldNotImplement]!

Item was removed:
- ----- Method: CharacterSet>>take: (in category 'accessing') -----
- take: n
-
- self shouldNotImplement.!

Item was added:
+ ----- Method: Collection>>any: (in category 'accessing') -----
+ any: numberOfElements
+
+ ^ self any: numberOfElements as: self species!

Item was added:
+ ----- Method: Collection>>any:as: (in category 'accessing') -----
+ any: numberOfElements as: aClass
+ "Enumerate this colleciton and return the specified number of elements. Signals an error if this collection has not enough elements."
+
+ | index result |
+ index := 0.
+ result := aClass new: numberOfElements.
+
+ result fillFrom: self with: [:each |
+ (index := index + 1) > numberOfElements
+ ifTrue: [^ result]
+ ifFalse: [each]].
+
+ index = numberOfElements
+ ifFalse: [self error: 'Not enough elements in this collection.'].
+
+ ^ result!

Item was changed:
  ----- Method: Collection>>take: (in category 'accessing') -----
+ take: maxNumberOfElements
+ "Returns maxNumberOfElements as a new collection or less if the collection is not large enough."
- take: n
- "Enumerate this collection and return the first n elements or less."
 
+ ^ self any: (maxNumberOfElements min: self size)!
- | index result |
- index := 1.
- result := self species new: (n min: self size).
- self associationsDo: [:each |
- result add: each.
- (index := index + 1) > n ifTrue: [^ result]].
- ^ result!

Item was added:
+ ----- Method: SequenceableCollection>>any: (in category 'accessing') -----
+ any: numberOfElements
+
+ ^ self first: numberOfElements!

Item was removed:
- ----- Method: SequenceableCollection>>take: (in category 'accessing') -----
- take: n
-
- ^ self first: (n min: self size)!

Item was added:
+ ----- Method: Stream>>any: (in category 'accessing') -----
+ any: numberOfElements
+ "See Collection protocol."
+
+ ^ self next: numberOfElements!

Item was changed:
  ----- Method: Stream>>take: (in category 'accessing') -----
+ take: maxNumberOfElements
+ "See Collection protocol."
+
+ ^ self any: maxNumberOfElements!
- take: n
-
- ^ self next: n!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-mt.833.mcz

Chris Muller-3
Hi Marcel,

The word "take" has a several different meanings and uses.  It's
possible this selector would exist in certain frameworks for different
purposes.  If, in one of these apps or frameworks, it existed in the
form of a general behavior for any Object, including Collections, then
it would become problematic for their framwork or app to be installed
in Squeak, and, worse, if other methods internal to Squeak were to
start depending on #take:, then the framework wouldn't be able to
replace it.

This is why I generally prefer to leave these kinds of broad words out
of the API as much as possible, so it can be "given" to apps for
whatever their interpretation would be of those words.

Just my 2-cents.

Best,
  Chris

PS -- we do have a lot of methods which utilize the "upTo"
nomenclature.  Could we integrate that in any way for consistency and
specificity?

On Mon, May 13, 2019 at 2:46 AM <[hidden email]> wrote:

>
> A new version of Collections was added to project The Inbox:
> http://source.squeak.org/inbox/Collections-mt.833.mcz
>
> ==================== Summary ====================
>
> Name: Collections-mt.833
> Author: mt
> Time: 13 May 2019, 9:46:28.73801 am
> UUID: 44057ed3-9b55-0b49-8472-71d5c3fdbeeb
> Ancestors: Collections-mt.832
>
> Second iteration of #take: (and #any:). #any: relates to #anyOne and thus signals an error if the collection is not large enough. #take: uses #any: but accounts for smaller collections.
>
> =============== Diff against Collections-mt.832 ===============
>
> Item was added:
> + ----- Method: CharacterSet>>any: (in category 'accessing') -----
> + any: numberOfElements
> +
> +       ^ self any: numberOfElements as: Array!
>
> Item was added:
> + ----- Method: CharacterSet>>any:as: (in category 'accessing') -----
> + any: numberOfElements as: aClass
> +
> +       self canBeEnumerated
> +               ifTrue: [^ super any: numberOfElements as: aClass]
> +               ifFalse: [self shouldNotImplement]!
>
> Item was removed:
> - ----- Method: CharacterSet>>take: (in category 'accessing') -----
> - take: n
> -
> -       self shouldNotImplement.!
>
> Item was added:
> + ----- Method: Collection>>any: (in category 'accessing') -----
> + any: numberOfElements
> +
> +       ^ self any: numberOfElements as: self species!
>
> Item was added:
> + ----- Method: Collection>>any:as: (in category 'accessing') -----
> + any: numberOfElements as: aClass
> +       "Enumerate this colleciton and return the specified number of elements. Signals an error if this collection has not enough elements."
> +
> +       | index result |
> +       index := 0.
> +       result := aClass new: numberOfElements.
> +
> +       result fillFrom: self with: [:each |
> +               (index := index + 1) > numberOfElements
> +                       ifTrue: [^ result]
> +                       ifFalse: [each]].
> +
> +       index = numberOfElements
> +               ifFalse: [self error: 'Not enough elements in this collection.'].
> +
> +       ^ result!
>
> Item was changed:
>   ----- Method: Collection>>take: (in category 'accessing') -----
> + take: maxNumberOfElements
> +       "Returns maxNumberOfElements as a new collection or less if the collection is not large enough."
> - take: n
> -       "Enumerate this collection and return the first n elements or less."
>
> +       ^ self any: (maxNumberOfElements min: self size)!
> -       | index result |
> -       index := 1.
> -       result := self species new: (n min: self size).
> -       self associationsDo: [:each |
> -               result add: each.
> -               (index := index + 1) > n ifTrue: [^ result]].
> -       ^ result!
>
> Item was added:
> + ----- Method: SequenceableCollection>>any: (in category 'accessing') -----
> + any: numberOfElements
> +
> +       ^ self first: numberOfElements!
>
> Item was removed:
> - ----- Method: SequenceableCollection>>take: (in category 'accessing') -----
> - take: n
> -
> -       ^ self first: (n min: self size)!
>
> Item was added:
> + ----- Method: Stream>>any: (in category 'accessing') -----
> + any: numberOfElements
> +       "See Collection protocol."
> +
> +       ^ self next: numberOfElements!
>
> Item was changed:
>   ----- Method: Stream>>take: (in category 'accessing') -----
> + take: maxNumberOfElements
> +       "See Collection protocol."
> +
> +       ^ self any: maxNumberOfElements!
> - take: n
> -
> -       ^ self next: n!
>
>

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-mt.833.mcz

marcel.taeumel
Hi Chris,

you sketch a rather broad scope for potential frameworks. While I cannot foresee the kind of frameworks that will be created in the future, I suspect that composition (instead of inheritance or extension methods) is a good fit for many scenarios out there. And composition has been successful for integrating collections into applications and frameworks in the past such as Morphic's submorphs. For Object, I do see your point, one has to subclass and might then be annoyed by existing -- simple -- selectors such as #name.

Best,
Marcel

Am 15.05.2019 02:38:55 schrieb Chris Muller <[hidden email]>:

Hi Marcel,

The word "take" has a several different meanings and uses. It's
possible this selector would exist in certain frameworks for different
purposes. If, in one of these apps or frameworks, it existed in the
form of a general behavior for any Object, including Collections, then
it would become problematic for their framwork or app to be installed
in Squeak, and, worse, if other methods internal to Squeak were to
start depending on #take:, then the framework wouldn't be able to
replace it.

This is why I generally prefer to leave these kinds of broad words out
of the API as much as possible, so it can be "given" to apps for
whatever their interpretation would be of those words.

Just my 2-cents.

Best,
Chris

PS -- we do have a lot of methods which utilize the "upTo"
nomenclature. Could we integrate that in any way for consistency and
specificity?

On Mon, May 13, 2019 at 2:46 AM wrote:

>
> A new version of Collections was added to project The Inbox:
> http://source.squeak.org/inbox/Collections-mt.833.mcz
>
> ==================== Summary ====================
>
> Name: Collections-mt.833
> Author: mt
> Time: 13 May 2019, 9:46:28.73801 am
> UUID: 44057ed3-9b55-0b49-8472-71d5c3fdbeeb
> Ancestors: Collections-mt.832
>
> Second iteration of #take: (and #any:). #any: relates to #anyOne and thus signals an error if the collection is not large enough. #take: uses #any: but accounts for smaller collections.
>
> =============== Diff against Collections-mt.832 ===============
>
> Item was added:
> + ----- Method: CharacterSet>>any: (in category 'accessing') -----
> + any: numberOfElements
> +
> + ^ self any: numberOfElements as: Array!
>
> Item was added:
> + ----- Method: CharacterSet>>any:as: (in category 'accessing') -----
> + any: numberOfElements as: aClass
> +
> + self canBeEnumerated
> + ifTrue: [^ super any: numberOfElements as: aClass]
> + ifFalse: [self shouldNotImplement]!
>
> Item was removed:
> - ----- Method: CharacterSet>>take: (in category 'accessing') -----
> - take: n
> -
> - self shouldNotImplement.!
>
> Item was added:
> + ----- Method: Collection>>any: (in category 'accessing') -----
> + any: numberOfElements
> +
> + ^ self any: numberOfElements as: self species!
>
> Item was added:
> + ----- Method: Collection>>any:as: (in category 'accessing') -----
> + any: numberOfElements as: aClass
> + "Enumerate this colleciton and return the specified number of elements. Signals an error if this collection has not enough elements."
> +
> + | index result |
> + index := 0.
> + result := aClass new: numberOfElements.
> +
> + result fillFrom: self with: [:each |
> + (index := index + 1) > numberOfElements
> + ifTrue: [^ result]
> + ifFalse: [each]].
> +
> + index = numberOfElements
> + ifFalse: [self error: 'Not enough elements in this collection.'].
> +
> + ^ result!
>
> Item was changed:
> ----- Method: Collection>>take: (in category 'accessing') -----
> + take: maxNumberOfElements
> + "Returns maxNumberOfElements as a new collection or less if the collection is not large enough."
> - take: n
> - "Enumerate this collection and return the first n elements or less."
>
> + ^ self any: (maxNumberOfElements min: self size)!
> - | index result |
> - index := 1.
> - result := self species new: (n min: self size).
> - self associationsDo: [:each |
> - result add: each.
> - (index := index + 1) > n ifTrue: [^ result]].
> - ^ result!
>
> Item was added:
> + ----- Method: SequenceableCollection>>any: (in category 'accessing') -----
> + any: numberOfElements
> +
> + ^ self first: numberOfElements!
>
> Item was removed:
> - ----- Method: SequenceableCollection>>take: (in category 'accessing') -----
> - take: n
> -
> - ^ self first: (n min: self size)!
>
> Item was added:
> + ----- Method: Stream>>any: (in category 'accessing') -----
> + any: numberOfElements
> + "See Collection protocol."
> +
> + ^ self next: numberOfElements!
>
> Item was changed:
> ----- Method: Stream>>take: (in category 'accessing') -----
> + take: maxNumberOfElements
> + "See Collection protocol."
> +
> + ^ self any: maxNumberOfElements!
> - take: n
> -
> - ^ self next: n!
>
>