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 <[hidden email]> 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? 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: cheers -ben |
In reply to this post by Tim Mackinnon
> On 15 Mar 2019, at 23:06, Tim Mackinnon <[hidden email]> 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. |
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 <[hidden email]> wrote: > > > >> On 15 Mar 2019, at 23:06, Tim Mackinnon <[hidden email]> 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 <[hidden email]> 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'm mostly ambivalent, except simplifying transition from other languages is useful. What are some examples for other languages? cheers -ben
|
In reply to this post by Tim Mackinnon
(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 <[hidden email]> 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? |
> On 17 Mar 2019, at 07:56, Richard O'Keefe <[hidden email]> 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 <[hidden email]> 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 > > |
In reply to this post by Richard O'Keefe
Thanks guys - I always learn something new from these threads.
|
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...
|
In reply to this post by Sven Van Caekenberghe-2
El dom., 17 mar. 2019 a las 6:33, Sven Van Caekenberghe
(<[hidden email]>) escribió: > > > > > On 17 Mar 2019, at 07:56, Richard O'Keefe <[hidden email]> 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 > (<[hidden email]>) escribió: >> >> >>> On 17 Mar 2019, at 07:56, Richard O'Keefe <[hidden email]> 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 > |
In reply to this post by Esteban A. Maringolo
An old draft has been available for yonks through 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 <[hidden email]> wrote: El dom., 17 mar. 2019 a las 6:33, Sven Van Caekenberghe |
Free forum by Nabble | Edit this page |