Forum Discussion
Patrick2788
Oct 29, 2025Silver Contributor
The Diagonal Suite: Gentle thunking goes a long way!
I've become a big advocate for gentle thunking - using thunks to delay eager evaluation wherever possible in generalized Lambda development. The timings are quicker and the logic is cleaner. On the ...
Patrick2788
Nov 05, 2025Silver Contributor
It looks like there's a bit more room for some gentle thunking to reduce calculation times even more.
For example, with Traverseλ 'result' is deferred until the very end. I snuck the () in at the end so it's not needed at the sheet level.
// --- Workbook module ---
// A file of name definitions of the form:
// name = definition;
//Author: Patrick H.
//Date: 10/27/2025
//Version: 1.0
//Repo: Please see The Diagonal Suite for a full suite of functions.
//-------------------------------------------------------------------------------------------
//Traverseλ - Directional Axis Remapper
//-------------------------------------------------------------------------------------------
//The selected axis is remapped to the top-left traversal order.
//Accepted directions:
// "NE" or 1 → Northeast (↗)
// "SE" or 2 → Southeast (↘)
// "SW" or 3 → Southwest (↙)
//Parameters:
//array → 2D input array (scalars not accepted)
//new_axis → Axis direction ("NE", "SE", "SW" or 1–3)
Traverseλ =
LAMBDA(
array,
new_axis,
//Input validation
IF(OR(ROWS(array)=1,COLUMNS(array)=1), "#2D-ARRAY!",
IF(AND(ISNUMBER(new_axis),OR(new_axis<=0,new_axis>3)),"#AXIS!",
LET(
//Dimensions
i, ROWS(array),
j, COLUMNS(array),
//Axis traversal indices (deferred)
x_NE, LAMBDA(SEQUENCE(j,,1,0)*SEQUENCE(,i)),
y_NE, LAMBDA(SEQUENCE(j,,j,-1)*SEQUENCE(,i,1,0)),
x_SE, LAMBDA(SEQUENCE(i,,i,-1)*SEQUENCE(,j,1,0)),
y_SE, LAMBDA(SEQUENCE(i,,j,0)+SEQUENCE(,j,0,-1)),
x_SW, LAMBDA(SEQUENCE(j,,i,0)+SEQUENCE(,i,0,-1)),
y_SW, LAMBDA(SEQUENCE(j,,1)*SEQUENCE(,i,1,0)),
//Axis mode selection
mode, IF(ISNUMBER(new_axis),new_axis,
SWITCH(new_axis,"NE",1,"SE",2,"SW",3,1)),
//Index selection
x, CHOOSE(mode,x_NE,x_SE,x_SW),
y, CHOOSE(mode,y_NE,y_SE,y_SW),
//Unwrap indices but defer results until function invocation
result, LAMBDA(INDEX(array,x(),y())),
result
)
))());This is fascinating in how a simple LAMBDA() tells Excel's formula parser to not read/fully evaluate a line and to treat it as "unrealized code".
Timings:
| Array | New axis | Calc Time | Calc Time - 1 more thunk |
| 100000x100 | SE | 1.98 | 1.7 |