Can I streamline this @for calculator loop?

Clause: #1029711

Hi all,

I’ve been working more with @for recently, in part thanks to advice I got from @robbert.jacobs on previous forum posts.

I have created a clause that tallies the amounts of shares across multiple series and automatically assigns consecutive numbers to them.

For example, if 25.000 common stock exist, and series 1 adds 1.000 shares, and series 2 adds another 2.000 shares, then:

series 1 will have the number 25.001 - 26.000, and
series 2 will get 26.001 - 28.000

Below is my working version of this logic:

What I like about this is that users only need to input the series name and amount, and the rest gets filled automagically.

However, I still feel that my calculators for the starting and ending numbers could be better:

// — Share Starting Amount Calculator — //
X-START = {1 + #shares^common-stock-initial + @get(#share-series^amount-issued, ?X -1) + @get(#share-series^amount-issued, ?X -2) + @get(#share-series^amount-issued, ?X -3) + @get(#share-series^amount-issued, ?X -4) + @get(#share-series^amount-issued, ?X -5)}
// X-START: using @get(?X -1) allows me to display the total sum of all preferred series, minus the ones whos index has not been called yet

// — Share Ending Amount Calculator — //
X-END = {#shares^common-stock-initial + @get(#share-series^amount-issued, ?X) + @get(#share-series^amount-issued, ?X -1) + @get(#share-series^amount-issued, ?X -2) + @get(#share-series^amount-issued, ?X -3) + @get(#share-series^amount-issued, ?X -4)}
// X-END: same logic as X-START, but adding the current preferred amount to the iteration

My idea in building it this way was that on the first loop, ?X - 1 would result in @get-ting “nothing” from the list, whilst on the second loop, ?X -1 would @get the first item.

My question here is can I streamline X-START and X-END ? I feel like I am using @get a bunch of times. I kind of feel like I did when I wrote a previous post, again limiting the amount of loops allowed because I don’t want to manually account for more than 5

Thanks!

Hi Kai!

Complex question, I broke my head thinking about this. I think I have a solution that works (and that does not need/use the #share-series^name-as-nr datafield):

@for(?AMOUNT, #share-series^_amount-issued, @REPEAT)
 
REPEAT = 1. {1 + @get(@for-calc(?AMOUNT, #share-series^_amount-issued, @X-START(?AMOUNT := ?AMOUNT)), ?INDEX)} to @get(@for-calc(?AMOUNT, #share-series^_amount-issued, @X-END(?AMOUNT := ?AMOUNT)), ?INDEX)

X-START = {#shares^common-stock-initial + @get(#share-series^_amount-issued, ?INDEX -1) + @get(?ACC, ?INDEX -1)}

X-END = {#shares^common-stock-initial + @get(#share-series^_amount-issued, ?INDEX) + @get(?ACC, ?INDEX -1)}

It is a bit too complex to try to explain in its entirety, but basically I tried to leverage the implicit ?ACC placeholder to avoid having to list all the possible instances manually. (This led into thinking on how to solve the self-referential nature of the ?ACC list, which I will spare you from for now…)

The above seems to work, feel free to adapt to your specific language and let me know what you think.

1 Like