Forum Discussion
Working with Arrays of Ranges
Interesting scenario and method.
I played around a little looking to see if it was possible to avoid the use of thunks by combining references into arrays and had partial success. If the names of the ranges are Table1,..,Table4 we can define a multi-area range: Tables=Table1,Table2,Table3,Table4 and try the following formula to convert this to an array of ranges.
=SUMIF(LAMBDA(T,MAP(SEQUENCE(AREAS(T)),LAMBDA(a,DROP(INDEX(T,,,a),{0}))))(Tables),"<>")
Strangely, this appears to work fine in Monthly Enterprise Channel but not Beta Channel.
An alternative that was more successful was to build a multi-area reference via REDUCE as shown
Hi Lori
I think my experimentation may have more significance in terms of my working than I realised!
The pairing of a text string and a thunk allows me to build a data dictionary that provides a mechanism to pass complex data structures between Lambda function (in particular to return multiple data objects from a sub-function).
So far I have written a DICTIONARYλ constructor function that builds the data structure
/* NAME: DICTIONARYλ
REVISIONS: Date Developer Description
Dec 19 2024 Peter Bartholomew Original Development
*/
DICTIONARYλ
= LAMBDA( _key01, object01, [_key02], [object02], ...
// Check inputs - Omitted required arguments
Help?, OR(
ISOMITTED(_key01),
ISOMITTED(object01),
),
NULLOMMITTED, LAMBDA(x, IF(ISOMITTED(x), "", x)),
_key02, NULLOMMITTED(_key02),
...
// Procedure
// Build array of unique keys
uniqueKeys, VSTACK(_key01, _key02,_...),
// Build array of thunked arrays (also applicable to scalars)
objectArray, VSTACK(LAMBDA(object01), LAMBDA(object02), ... ),
// Combine unique keys with references to data objects
result, FILTER(HSTACK(uniqueKeys, objectArray), uniqueKeys<>""),
CHOOSE(Help? + 1, Result, Help)
)
);as well as generic and dictionary-specific functions to return data from dictionaries
GETλ
= LAMBDA(dict, LAMBDA(key,
LET(
uniqueKeys, TAKE(dict,,1),
objects, DROP(dict,,1),
result, XLOOKUP(key, uniqueKeys, objects, "keyword not found"),
(@result)()
)
));
GETSERIESDATAλ
= GETλ(seriesDataDictionary)
;and the ability to return a list of keys
KEYSλ = LAMBDA(dict, TAKE(dict,,1));Within a functional programming environment, each dictionary is write once, read many since all objects are immutable, but I should be able to combine two directories to give a fresh data object.
That might sound extravagant in terms of memory commitment, but since I am only storing thunks (references to memory allocated to a LET variable) the burden might be modest.
The Excel failure to return arrays of arrays makes it a little difficult to dump an image of the dictionary to the worksheet for checking or to provide persistence but I think my MAPλ function should work.
I have addressed these thoughts to you, as a Python programmer, in the hope that you might have additional insight that you could draw upon to educate me🙂! Of course, others are welcome to contribute.