[Cuis-dev] On ArrayedCollection >> incrementFraction

Francisco Garau francisco.garau at gmail.com
Wed May 13 05:31:13 PDT 2026


I've prepared a more generic and efficient implementation of these methods
(with a small difference in behavior) -- I would prefer to submit this
changes with a couple of PRs (one for the base image and one for the
numerical package). Appreciate if there is any documentation for new
contributions.

#( 3 5 8 ) successiveRatios = { 1. 5/3 . 8/5} ." -- currently the first
element is always 1 -- "
#( 3 5 8 ) successiveRatios = { 5/3 . 8/5} . " -- the ratios will be
calculated in between pairs --"

*ArrayedCollection >> successiveRatios*

"
#( 3 5 8 ) successiveRatios = {5/3 . 8/5}.
([#(3) successiveRatios] on: Error do: [:ex | ex description ] ) = 'Error:
this collection is too small'.
"
^self collectSlidingWindow: [:a :b | b / a ]



*SequenceableCollection >> collectSlidingWindow: aBlock*

"
(#( 3 5 8 13 ) collectSlidingWindow: [:a :b | a at b]) = {3 at 5 . 5 at 8 . 8 at 13}.
(#( 3 5 8 13 ) collectSlidingWindow: [:a :b :c | {a. b. c}]) = {{3. 5. 8}.
{5. 8. 13.}}.
('hello_word'  collectSlidingWindow: [:a | Character codePoint: a codePoint
- 32]) = 'HELLO?WORD'.

([#(3) collectWithSlidingWindow: [:a :b | a + b]] on: Error do: [:ex | ex
description]) = 'Error: this collection is too small'.
"
|  tupleSize newSize answer  blockArgs |
tupleSize := aBlock numArgs.
self size < tupleSize ifTrue: [self errorCollectionTooSmall].
newSize := self size - tupleSize + 1.
answer := self species new: newSize.
blockArgs := Array new: tupleSize.
1 to: newSize do: [ :i |
1 to: tupleSize do: [:m | blockArgs at: m put: (self at: i + m -1 )].
answer at: i put: (aBlock valueWithArguments: blockArgs).].
^ answer



On Mon, 11 May 2026 at 20:12, Juan Vuletich via Cuis-dev <
cuis-dev at lists.cuis.st> wrote:

> Hi Ezequiel,
>
> (inline)
> On 2026-05-03 1:48 AM, Ezequiel Birman via Cuis-dev wrote:
>
> Hi!,
>
> I want to collect the successive ratios in a collection of numbers in
> order to appreciate how “fast” they grow. I noticed that the image already
> implements ArrayedCollection >> incrementFraction, which is almost equal to
> ArrayedCollection >> derivative:
>
> incrementFraction
>> "
>> #(10 12.5 15 20) incrementFraction
>> "
>> | displaced answer |
>> displaced := self class new: self size.
>> displaced replaceFrom: 2 to: self size with: self startingAt: 1.
>> displaced at: 1 put: self first.
>> answer := self copy.
>> answer -= displaced.
>
> ^answer / displaced
>
>
> derivative
>> | displaced answer |
>> displaced := self class new: self size.
>> displaced replaceFrom: 2 to: self size with: self startingAt: 1.
>> displaced at: 1 put: self first - self first. "Some reasonable zero"
>> answer := self copy.
>> answer -= displaced.
>> ^answer
>
>
> I think I want something similar, except for the subtraction:
>
>> myThing
>>
>> | displaced answer |
>> displaced := self class new: self size.
>> displaced replaceFrom: 2 to: self size with: self startingAt: 1.
>> displaced at: 1 put: self first.
>> answer := self copy.
>
> ^answer / displaced
>
>
> I'll probably need both, since I'm doing exploratory analysis. And while
> `myThing`, (which could be named `successiveRatios` or something along
> those lines) can answer if there is a constant or varying growth,
> `incrementFraction` measures the rate at which the growth itself is scaling.
>
> This makes a lot of sense. I've just added your method with selector
> #successiveRatios and your author initials. Thanks!
>
>
> Neither `derivative` nor `incrementFraction` nor `Integral` have senders.
> Juan, maybe you remember why or under which circumstances you added them in
> 2024?
>
> I'd guess they are older than that. They are there because they are
> ilustrative and could be of use. It is nice to have this kind of stuff in
> the image. I believe it shows general Smalltalk-fu.
>
>  Are there any efforts / packages for numeric or data analysis?
>
>
> Not specifically for that, but a good place for it would be
> https://github.com/Cuis-Smalltalk/Numerics
>
> Cheers,
>
>
> --
> Eze
>
> --
> Juan Vuletichwww.cuis.stgithub.com/jvuletichresearchgate.net/profile/Juan-Vuletichindependent.academia.edu/JuanVuletichpatents.justia.com/inventor/juan-manuel-vuletich
>
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20260513/d5f5e210/attachment.htm>


More information about the Cuis-dev mailing list