The Inbox: Kernel-ct.1266.mcz

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

The Inbox: Kernel-ct.1266.mcz

commits-2
A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel-ct.1266.mcz

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

Name: Kernel-ct.1266
Author: ct
Time: 6 September 2019, 1:16:39.325698 pm
UUID: a5b0464f-61cf-4749-9ad3-92e7d8c85341
Ancestors: Kernel-eem.1265

Add shorthands for interval collecting

There are enough senders of #timesRepeat: that manually fill a collection, same goes for #to:do:

=============== Diff against Kernel-eem.1265 ===============

Item was added:
+ ----- Method: Integer>>timesCollect: (in category 'enumerating') -----
+ timesCollect: aBlock
+
+ ^ (1 to: self) collect: [:i | aBlock value]!

Item was added:
+ ----- Method: Number>>to:collect: (in category 'intervals') -----
+ to: stop collect: aBlock
+ "Evaluate aBlock for each element of the interval (self to: stop by: 1) and return the results."
+
+ ^ (self to: stop) collect: aBlock!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Kernel-ct.1266.mcz

marcel.taeumel
Hmm... #timesCollect: seems strange. Especially since #timesRepeat: does not provide the iteration number to the block. Then, #to:collect: has a similar problem: "from x to y collect what?" The explicit from "(x to: y)" for the interval object seems more readable.

-1  ;-)

Best,
Marcel

Am 06.09.2019 13:16:54 schrieb [hidden email] <[hidden email]>:

A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel-ct.1266.mcz

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

Name: Kernel-ct.1266
Author: ct
Time: 6 September 2019, 1:16:39.325698 pm
UUID: a5b0464f-61cf-4749-9ad3-92e7d8c85341
Ancestors: Kernel-eem.1265

Add shorthands for interval collecting

There are enough senders of #timesRepeat: that manually fill a collection, same goes for #to:do:

=============== Diff against Kernel-eem.1265 ===============

Item was added:
+ ----- Method: Integer>>timesCollect: (in category 'enumerating') -----
+ timesCollect: aBlock
+
+ ^ (1 to: self) collect: [:i | aBlock value]!

Item was added:
+ ----- Method: Number>>to:collect: (in category 'intervals') -----
+ to: stop collect: aBlock
+ "Evaluate aBlock for each element of the interval (self to: stop by: 1) and return the results."
+
+ ^ (self to: stop) collect: aBlock!




Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Kernel-ct.1266.mcz

marcel.taeumel
In reply to this post by commits-2
I think it is better to name the kind of collection you are going to fill. 

For some of these examples, there are better ways such as "OrderedCollection new: 20 withAll: 0".

Maybe support blocks in #new:withAll:?

OrderedCollection
   new: 20
   withAll: [:index | index atRandom]

Best,
Marcel

Am 06.09.2019 16:04:49 schrieb Thiede, Christoph <[hidden email]>:

Especially since #timesRepeat: does not provide the iteration number to the block.

But so does #timesRepeat:? I was looking for a convenient way to evaluate a block n times and store the results. There seem to be various methods which, imho, could be written simpler:



Best,

Christoph


Von: Squeak-dev <[hidden email]> im Auftrag von Taeumel, Marcel
Gesendet: Freitag, 6. September 2019 15:36:49
An: gettimothy via Squeak-dev
Betreff: Re: [squeak-dev] The Inbox: Kernel-ct.1266.mcz
 
Hmm... #timesCollect: seems strange. Especially since #timesRepeat: does not provide the iteration number to the block. Then, #to:collect: has a similar problem: "from x to y collect what?" The explicit from "(x to: y)" for the interval object seems more readable.

-1  ;-)

Best,
Marcel

Am 06.09.2019 13:16:54 schrieb [hidden email] <[hidden email]>:

A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel-ct.1266.mcz

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

Name: Kernel-ct.1266
Author: ct
Time: 6 September 2019, 1:16:39.325698 pm
UUID: a5b0464f-61cf-4749-9ad3-92e7d8c85341
Ancestors: Kernel-eem.1265

Add shorthands for interval collecting

There are enough senders of #timesRepeat: that manually fill a collection, same goes for #to:do:

=============== Diff against Kernel-eem.1265 ===============

Item was added:
+ ----- Method: Integer>>timesCollect: (in category 'enumerating') -----
+ timesCollect: aBlock
+
+ ^ (1 to: self) collect: [:i | aBlock value]!

Item was added:
+ ----- Method: Number>>to:collect: (in category 'intervals') -----
+ to: stop collect: aBlock
+ "Evaluate aBlock for each element of the interval (self to: stop by: 1) and return the results."
+
+ ^ (self to: stop) collect: aBlock!




Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Kernel-ct.1266.mcz

Christoph Thiede

Good point. Maybe introduce a new selector, for example #new:withEach:? It might be misleading if you really want to create a collection of blocks.


OrderedCollection

    new: 20

    withEach: [50 atRandom]


I think the block should be called with #cull:, as there are many cases where index does not matter.


Best,

Christoph


Von: Taeumel, Marcel
Gesendet: Freitag, 6. September 2019 16:40:59
An: Thiede, Christoph; gettimothy via Squeak-dev
Betreff: Re: AW: [squeak-dev] The Inbox: Kernel-ct.1266.mcz
 
I think it is better to name the kind of collection you are going to fill. 

For some of these examples, there are better ways such as "OrderedCollection new: 20 withAll: 0".

Maybe support blocks in #new:withAll:?

OrderedCollection
   new: 20
   withAll: [:index | index atRandom]

Best,
Marcel

Am 06.09.2019 16:04:49 schrieb Thiede, Christoph <[hidden email]>:

Especially since #timesRepeat: does not provide the iteration number to the block.

But so does #timesRepeat:? I was looking for a convenient way to evaluate a block n times and store the results. There seem to be various methods which, imho, could be written simpler:



Best,

Christoph


Von: Squeak-dev <[hidden email]> im Auftrag von Taeumel, Marcel
Gesendet: Freitag, 6. September 2019 15:36:49
An: gettimothy via Squeak-dev
Betreff: Re: [squeak-dev] The Inbox: Kernel-ct.1266.mcz
 
Hmm... #timesCollect: seems strange. Especially since #timesRepeat: does not provide the iteration number to the block. Then, #to:collect: has a similar problem: "from x to y collect what?" The explicit from "(x to: y)" for the interval object seems more readable.

-1  ;-)

Best,
Marcel

Am 06.09.2019 13:16:54 schrieb [hidden email] <[hidden email]>:

A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel-ct.1266.mcz

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

Name: Kernel-ct.1266
Author: ct
Time: 6 September 2019, 1:16:39.325698 pm
UUID: a5b0464f-61cf-4749-9ad3-92e7d8c85341
Ancestors: Kernel-eem.1265

Add shorthands for interval collecting

There are enough senders of #timesRepeat: that manually fill a collection, same goes for #to:do:

=============== Diff against Kernel-eem.1265 ===============

Item was added:
+ ----- Method: Integer>>timesCollect: (in category 'enumerating') -----
+ timesCollect: aBlock
+
+ ^ (1 to: self) collect: [:i | aBlock value]!

Item was added:
+ ----- Method: Number>>to:collect: (in category 'intervals') -----
+ to: stop collect: aBlock
+ "Evaluate aBlock for each element of the interval (self to: stop by: 1) and return the results."
+
+ ^ (self to: stop) collect: aBlock!




Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Kernel-ct.1266.mcz

marcel.taeumel
I put a proposal in the inbox: Collections-mt.852.

Best,
Marcel

Am 06.09.2019 16:47:05 schrieb Thiede, Christoph <[hidden email]>:

Good point. Maybe introduce a new selector, for example #new:withEach:? It might be misleading if you really want to create a collection of blocks.


OrderedCollection

    new: 20

    withEach: [50 atRandom]


I think the block should be called with #cull:, as there are many cases where index does not matter.


Best,

Christoph


Von: Taeumel, Marcel
Gesendet: Freitag, 6. September 2019 16:40:59
An: Thiede, Christoph; gettimothy via Squeak-dev
Betreff: Re: AW: [squeak-dev] The Inbox: Kernel-ct.1266.mcz
 
I think it is better to name the kind of collection you are going to fill. 

For some of these examples, there are better ways such as "OrderedCollection new: 20 withAll: 0".

Maybe support blocks in #new:withAll:?

OrderedCollection
   new: 20
   withAll: [:index | index atRandom]

Best,
Marcel

Am 06.09.2019 16:04:49 schrieb Thiede, Christoph <[hidden email]>:

Especially since #timesRepeat: does not provide the iteration number to the block.

But so does #timesRepeat:? I was looking for a convenient way to evaluate a block n times and store the results. There seem to be various methods which, imho, could be written simpler:



Best,

Christoph


Von: Squeak-dev <[hidden email]> im Auftrag von Taeumel, Marcel
Gesendet: Freitag, 6. September 2019 15:36:49
An: gettimothy via Squeak-dev
Betreff: Re: [squeak-dev] The Inbox: Kernel-ct.1266.mcz
 
Hmm... #timesCollect: seems strange. Especially since #timesRepeat: does not provide the iteration number to the block. Then, #to:collect: has a similar problem: "from x to y collect what?" The explicit from "(x to: y)" for the interval object seems more readable.

-1  ;-)

Best,
Marcel

Am 06.09.2019 13:16:54 schrieb [hidden email] <[hidden email]>:

A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel-ct.1266.mcz

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

Name: Kernel-ct.1266
Author: ct
Time: 6 September 2019, 1:16:39.325698 pm
UUID: a5b0464f-61cf-4749-9ad3-92e7d8c85341
Ancestors: Kernel-eem.1265

Add shorthands for interval collecting

There are enough senders of #timesRepeat: that manually fill a collection, same goes for #to:do:

=============== Diff against Kernel-eem.1265 ===============

Item was added:
+ ----- Method: Integer>>timesCollect: (in category 'enumerating') -----
+ timesCollect: aBlock
+
+ ^ (1 to: self) collect: [:i | aBlock value]!

Item was added:
+ ----- Method: Number>>to:collect: (in category 'intervals') -----
+ to: stop collect: aBlock
+ "Evaluate aBlock for each element of the interval (self to: stop by: 1) and return the results."
+
+ ^ (self to: stop) collect: aBlock!