Steffen, I think the trouble you are seeing comes from trying to use a block in a way that is inappropriate.
A Block provides an anonymous function, but why use a Block that makes it so much more complicated? Perhaps, you should reconsider an approach like: (1 to: 1000) do: [:i | | data | data:= source compute: i. MyProcessor handleSourceData: data index: i ] That allows you to factor out the block code into clean and intention revealing code, and eliminates the need to compose the arguments into a form compatible with Block invocation. -----Original Message----- From: Steffen Märcker <merk...@web.de> Sent: April 11, 2023 09:44 To: Any question about pharo is welcome <pharo-users@lists.pharo.org> Cc: v...@lists.cs.illinois.edu Subject: [Pharo-users] Re: [vwnc] Block evaluation with n+1 arguments Hi! First, thanks for your engaging answers Richard, Stephane and the others! The objective is to avoid unnecessary object creation in a tight loop that interfaces between a value source and a block that processes the values. - The source object returns multiple values as a tuple (for good reasons). - The block processes theses values but needs another argument (at the first place). We do not know the number of values at compile time but know that they match the arity of the block. Something like this (though more involved in practice): (1 to: 1000) do: [:i | | args | args := source compute: i. block valueWithArguments: {i} , args ] Since prepending the tuple with the first argument and then sending #valueWithArguments: creates an intermediate Array, I wonder whether we can avoid (some of) that overhead in the loop without changing this structure. Note, "{i}, args" is only for illustration and creates an additional third array as Steve already pointed out. To sum up the discussion so far: - If possible, change the structure, e.g., processing the tuple directly. - Fast primitives exist for the special cases of 1, 2 and 3 arguments only. - Code for > 3 arguments would have to use #valueWithArguments: after all. Did I miss something? Kind regards, Steffen