Why doesn't collection have #excludes (the mirror of includes)?
Hi - in my quest to understand the edgier details of Pharo (and Smalltalk) - and driven by fresh thoughts of completing exercism exercises - I was surprised to find that there is no #excludes: operation on collection to mirror the #includes: operation? I was curious about this - its seems a strange omission? Of course I can inverse it with not, or do things a different way - but we have ifTrue: mirrored with ifFalse, empty/notEmpty so am I missing something? I wanted to write something like aString detect: [:c | ($0 to: $1) excludes: c] ifFound: aBlock. (Evaluate a block if the string isnât all 0 and 1âs) Of course I can write this as: (aString reject: [:c | c = $0 | c = $1)) ifNotEmpty: aBlock But as recent messages in this vein have shown me (and taught me lots - thanks to those answering), the answer is often not what I thought. Tim
On Sat, 16 Mar 2019 at 06:33, Tim Mackinnon <tim@testit.works> wrote:
Hi - in my quest to understand the edgier details of Pharo (and Smalltalk) - and driven by fresh thoughts of completing exercism exercises - I was surprised to find that there is no #excludes: operation on collection to mirror the #includes: operation?
I was curious about this - its seems a strange omission?
Of course I can inverse it with not, or do things a different way - but we have ifTrue: mirrored with ifFalse, empty/notEmpty so am I missing something?
I wanted to write something like
aString detect: [:c | ($0 to: $1) excludes: c] ifFound: aBlock. (Evaluate a block if the string isnât all 0 and 1âs)
purely off the cuff, if you want the opposite logic what about... aString detect: [:c | (($0 to: $1) includes: c) not ] ifFound: aBlock. Of course I can write this as:
(aString reject: [:c | c = $0 | c = $1)) ifNotEmpty: aBlock
cheers -ben
These are all good suggestions guys - but donât you find it odd that there isnât the mirror function #excludes: which would make all of them read more naturally? I know we canât have all combinations- but this one really struck me as odd by its absence (particularly when I was comparing the elegance of my little coding solution to other languages). Should I propose itâs inclusion in Collection? Tim Sent from my iPhone
On 16 Mar 2019, at 08:43, Sven Van Caekenberghe <sven@stfx.eu> wrote:
On 15 Mar 2019, at 23:06, Tim Mackinnon <tim@testit.works> wrote:
aString detect: [:c | ($0 to: $1) excludes: c] ifFound: aBlock. (Evaluate a block if the string isnât all 0 and 1âs)
(aString allSatisfy: [ :each | '01' includes: each ]) not.
On Sat, 16 Mar 2019 at 17:05, Tim Mackinnon <tim@testit.works> wrote:
These are all good suggestions guys - but donât you find it odd that there isnât the mirror function #excludes: which would make all of them read more naturally?
I know we canât have all combinations- but this one really struck me as odd by its absence (particularly when I was comparing the elegance of my little coding solution to other languages).
Should I propose itâs inclusion in Collection?
I'm mostly ambivalent, except simplifying transition from other languages is useful. What are some examples for other languages? cheers -ben
Tim
Sent from my iPhone
On 16 Mar 2019, at 08:43, Sven Van Caekenberghe <sven@stfx.eu> wrote:
On 15 Mar 2019, at 23:06, Tim Mackinnon <tim@testit.works> wrote:
aString detect: [:c | ($0 to: $1) excludes: c] ifFound: aBlock. (Evaluate a block if the string isnât all 0 and 1âs)
(aString allSatisfy: [ :each | '01' includes: each ]) not.
(1) As it happens, my Smalltalk library *does* have #excludes: and #identityExcludes: (2) The definitions are trivial. excludes: item ^(self includes: item) not identityExcludes: item ^(self identityIncludes: item) not If you want to execute aBlock when aString is not all zeros and ones, just do (aString allSatisfy: [:each | each = $0 or: [each = $1]]) ifFalse: [aBlock value]. or (aString anySatisfy: [:each | each ~= $0 and: [each ~= $1]]) ifTrue: [aBlock value]. or ('01' includesAll: aString) ifFalse: [aBlock value]. On Sat, 16 Mar 2019 at 11:33, Tim Mackinnon <tim@testit.works> wrote:
Hi - in my quest to understand the edgier details of Pharo (and Smalltalk) - and driven by fresh thoughts of completing exercism exercises - I was surprised to find that there is no #excludes: operation on collection to mirror the #includes: operation?
I was curious about this - its seems a strange omission?
Of course I can inverse it with not, or do things a different way - but we have ifTrue: mirrored with ifFalse, empty/notEmpty so am I missing something?
I wanted to write something like
aString detect: [:c | ($0 to: $1) excludes: c] ifFound: aBlock. (Evaluate a block if the string isnât all 0 and 1âs)
Of course I can write this as:
(aString reject: [:c | c = $0 | c = $1)) ifNotEmpty: aBlock
But as recent messages in this vein have shown me (and taught me lots - thanks to those answering), the answer is often not what I thought.
Tim
On 17 Mar 2019, at 07:56, Richard O'Keefe <raoknz@gmail.com> wrote:
(1) As it happens, my Smalltalk library *does* have
"my mystery Smalltalk" ;-)
#excludes: and #identityExcludes: (2) The definitions are trivial. excludes: item ^(self includes: item) not identityExcludes: item ^(self identityIncludes: item) not
If you want to execute aBlock when aString is not all zeros and ones, just do (aString allSatisfy: [:each | each = $0 or: [each = $1]]) ifFalse: [aBlock value]. or (aString anySatisfy: [:each | each ~= $0 and: [each ~= $1]]) ifTrue: [aBlock value]. or ('01' includesAll: aString) ifFalse: [aBlock value].
That last expression wins hands down ! Thank you for bringing that up, I learned something new.
On Sat, 16 Mar 2019 at 11:33, Tim Mackinnon <tim@testit.works> wrote: Hi - in my quest to understand the edgier details of Pharo (and Smalltalk) - and driven by fresh thoughts of completing exercism exercises - I was surprised to find that there is no #excludes: operation on collection to mirror the #includes: operation?
I was curious about this - its seems a strange omission?
Of course I can inverse it with not, or do things a different way - but we have ifTrue: mirrored with ifFalse, empty/notEmpty so am I missing something?
I wanted to write something like
aString detect: [:c | ($0 to: $1) excludes: c] ifFound: aBlock. (Evaluate a block if the string isnât all 0 and 1âs)
Of course I can write this as:
(aString reject: [:c | c = $0 | c = $1)) ifNotEmpty: aBlock
But as recent messages in this vein have shown me (and taught me lots - thanks to those answering), the answer is often not what I thought.
Tim
El dom., 17 mar. 2019 a las 6:33, Sven Van Caekenberghe (<sven@stfx.eu>) escribió:
On 17 Mar 2019, at 07:56, Richard O'Keefe <raoknz@gmail.com> wrote:
(1) As it happens, my Smalltalk library *does* have
"my mystery Smalltalk" ;-)
Codename "Unicorn". :) Jokes aside, I'd love to see such implementation because all software products developed by only a few minds, if not one at all, have a level of coherence and parsimony that can't be achieved with a larger team. I only saw it with Dolphin Smalltalk, and would love to see your Unicorn Smalltalk as well. Regards, Esteban A. Maringolo
Isn't this an "ultimate" goal for Pharo ... once you've got a stable (truly) minimum image, custom class libraries are possible if not desirable ... Dale On 3/18/19 11:08 AM, Esteban Maringolo wrote:
El dom., 17 mar. 2019 a las 6:33, Sven Van Caekenberghe (<sven@stfx.eu>) escribió:
On 17 Mar 2019, at 07:56, Richard O'Keefe <raoknz@gmail.com> wrote:
(1) As it happens, my Smalltalk library *does* have "my mystery Smalltalk" ;-)
Codename "Unicorn". :)
Jokes aside, I'd love to see such implementation because all software products developed by only a few minds, if not one at all, have a level of coherence and parsimony that can't be achieved with a larger team. I only saw it with Dolphin Smalltalk, and would love to see your Unicorn Smalltalk as well.
Regards,
Esteban A. Maringolo
An old draft has been available for yonks through http://www.cs.otago.ac.nz/staffpriv/ok/software.htm There are two *major* changes not included in that release and not quite finished yet. On Tue, 19 Mar 2019 at 07:09, Esteban Maringolo <emaringolo@gmail.com> wrote:
El dom., 17 mar. 2019 a las 6:33, Sven Van Caekenberghe (<sven@stfx.eu>) escribió:
On 17 Mar 2019, at 07:56, Richard O'Keefe <raoknz@gmail.com> wrote:
(1) As it happens, my Smalltalk library *does* have
"my mystery Smalltalk" ;-)
Codename "Unicorn". :)
Jokes aside, I'd love to see such implementation because all software products developed by only a few minds, if not one at all, have a level of coherence and parsimony that can't be achieved with a larger team. I only saw it with Dolphin Smalltalk, and would love to see your Unicorn Smalltalk as well.
Regards,
Esteban A. Maringolo
Thanks guys - I always learn something new from these threads.
On 17 Mar 2019, at 06:56, Richard O'Keefe <raoknz@gmail.com> wrote:
(1) As it happens, my Smalltalk library *does* have #excludes: and #identityExcludes: (2) The definitions are trivial. excludes: item ^(self includes: item) not identityExcludes: item ^(self identityIncludes: item) not
If you want to execute aBlock when aString is not all zeros and ones, just do (aString allSatisfy: [:each | each = $0 or: [each = $1]]) ifFalse: [aBlock value]. or (aString anySatisfy: [:each | each ~= $0 and: [each ~= $1]]) ifTrue: [aBlock value]. or ('01' includesAll: aString) ifFalse: [aBlock value].
On Sat, 16 Mar 2019 at 11:33, Tim Mackinnon <tim@testit.works> wrote: Hi - in my quest to understand the edgier details of Pharo (and Smalltalk) - and driven by fresh thoughts of completing exercism exercises - I was surprised to find that there is no #excludes: operation on collection to mirror the #includes: operation?
I was curious about this - its seems a strange omission?
Of course I can inverse it with not, or do things a different way - but we have ifTrue: mirrored with ifFalse, empty/notEmpty so am I missing something?
I wanted to write something like
aString detect: [:c | ($0 to: $1) excludes: c] ifFound: aBlock. (Evaluate a block if the string isnât all 0 and 1âs)
Of course I can write this as:
(aString reject: [:c | c = $0 | c = $1)) ifNotEmpty: aBlock
But as recent messages in this vein have shown me (and taught me lots - thanks to those answering), the answer is often not what I thought.
Tim
And looking at this in the code - there are quite a few variations of #includes⦠that I donât think it makes sense to write the mirror of all of them. Not it is...
On 18 Mar 2019, at 16:48, Tim Mackinnon <tim@testit.works> wrote:
Thanks guys - I always learn something new from these threads.
On 17 Mar 2019, at 06:56, Richard O'Keefe <raoknz@gmail.com <mailto:raoknz@gmail.com>> wrote:
(1) As it happens, my Smalltalk library *does* have #excludes: and #identityExcludes: (2) The definitions are trivial. excludes: item ^(self includes: item) not identityExcludes: item ^(self identityIncludes: item) not
If you want to execute aBlock when aString is not all zeros and ones, just do (aString allSatisfy: [:each | each = $0 or: [each = $1]]) ifFalse: [aBlock value]. or (aString anySatisfy: [:each | each ~= $0 and: [each ~= $1]]) ifTrue: [aBlock value]. or ('01' includesAll: aString) ifFalse: [aBlock value].
On Sat, 16 Mar 2019 at 11:33, Tim Mackinnon <tim@testit.works <mailto:tim@testit.works>> wrote: Hi - in my quest to understand the edgier details of Pharo (and Smalltalk) - and driven by fresh thoughts of completing exercism exercises - I was surprised to find that there is no #excludes: operation on collection to mirror the #includes: operation?
I was curious about this - its seems a strange omission?
Of course I can inverse it with not, or do things a different way - but we have ifTrue: mirrored with ifFalse, empty/notEmpty so am I missing something?
I wanted to write something like
aString detect: [:c | ($0 to: $1) excludes: c] ifFound: aBlock. (Evaluate a block if the string isnât all 0 and 1âs)
Of course I can write this as:
(aString reject: [:c | c = $0 | c = $1)) ifNotEmpty: aBlock
But as recent messages in this vein have shown me (and taught me lots - thanks to those answering), the answer is often not what I thought.
Tim
participants (6)
-
Ben Coman -
Dale Henrichs -
Esteban Maringolo -
Richard O'Keefe -
Sven Van Caekenberghe -
Tim Mackinnon