All,
I'm testing whether or not I can build a robust data model using nested dictionaries of data and f(x). The namespace/dot notation works well for what I'm attempting and we can reference the dictionary well but I'm unable to get the functions to execute when called as I thought.
I was hoping to reference the dictionary in the functions recursively to execute and recalculate when called and reduce incredible long functions.
Keeping the functions as part of the dictionary is an objective as we expect to have various functions for different dictionaries of data.
Here is a simple example of a nested dictionary and functions with the objective to calculate total rev based on the data in the inventory for prodA and prodB.
Many thanks in advance!
.inv.prodA.qty: 10 #10;
.inv.prodA.price: 10 #2.75;
.inv.prodA.cogs: 10 # 1.35;
.inv.prodA.net_price: {[x] x[`price] - x[`cogs]};
.inv.prodA.net_price [.inv.prodA];
.inv.prodA.rev: {[x] x[`qty] * (inv.net_price[ x[`price] - x[`cogs]])};
.inv.prodB.qty: 20 #2.50;
.inv.prodB.price: 20 #1.50;
.inv.prodB.cogs: 20 # 0.25;
.inv.prodB.net_price: {[x] x[`price] - x[`cogs]};
.inv.prodB.net_price [.inv.prodB];
.inv.prodB.rev: {[x] x[`qty] * (inv.net_price[ x[`price] - x[`cogs]])*.5}; //Note that the rev f(x) are unique for each prodA and prodB
.inv.total.rev: {[x] x[`prodA`rev] + x[`prodB`rev]};