[squeak-dev] The Inbox: Collections-ul.844.mcz

Tobias das.linux at gmx.de
Fri Jul 19 07:15:02 UTC 2019


Hi Levente

On Thu, 2019-07-18 at 22:13 +0000, commits at source.squeak.org wrote:
> Levente Uzonyi uploaded a new version of Collections to project The
> Inbox:
> http://source.squeak.org/inbox/Collections-ul.844.mcz
>
> ==================== Summary ====================
>
> Name: Collections-ul.844
> Author: ul
> Time: 19 July 2019, 12:08:51.94435 am
> UUID: df5ebfa9-4ebf-4505-8031-afd892a1061c
> Ancestors: Collections-mt.843
>
> - added String >> #atOrNil: which uses primitive 63 and returns
> either the character at the given index or nil when the primtiive
> fails. This is a faster alternative to #at:ifAbsent: when the absent
> block would yield nil.
>

Could you tell me the use case here?
This sounds like a convoluted range check.
I mean, yes it would be faster to do

 knorz := 'foo'
 index := 32
 ^ knorz atOrNil: index

but I would rather see

 knorz := 'foo'
 index := 32
 ^ index <= knorz size ifTrue:  [knorz at: size]

or more robust even


 knorz := 'foo'
 index := 32
 ^ knorz atPin: 32

(even though that changes the semantic)

So, can you tell me the use case here?
Best regards
	-Tobias

PS: That said, I think using #at: for String in the first place will
bite us down the road, whether we want to change the String
representation at some point (ropes, immutables, values, ...) or just
because Unicode is hard: ('Lèon' at: 3) can surely yield $'̀ ', $e
or $'è'




More information about the Squeak-dev mailing list