2022.07.29 07:34 AM
Hi,
My code below works without error:
No Error
g:`;
g:{[xG] xG + 2}; // global; works for f and h
f:{[xF]
h:{[xH] g[xH] + 3};
show g[xF] + h[xF];
}
f[40]; // i.e. 87; no error
However, I prefer a local g instead of a local one. I also tried below, but both failed:
Trial 1 (Failed)
g:`;
f:{[xF]
g:{[xG] xG + 2}; // local; doesn't work for h
h:{[xH] g[xH] + 3};
show g[xF] + h[xF];
}
f[40]; // error
and
Trial 2 (Failed)
g:`;
f:{[xF]
h:{[xH] g:{[xG] xG + 2}; g[xH] + 3}; // local; doesn't work for f
show g[xF] + h[xF];
}
f[40];// error
Is it possible to have a local g without an error? Thanks.
2022.07.29 07:57 AM - edited 2022.07.29 08:02 AM
You could pass it in to a projection
q)f:{[xF] g:{[xG] xG + 2};h:{[g;xH] g[xH] + 3}[g];g[xF] + h[xF]}
q)f[40]
87
Or composition in this basic case
q)f:{[xF] g:{[xG] xG + 2};h:+[3] g @;g[xF] + h[xF]}
q)f[40]
87
2022.07.29 07:57 AM - edited 2022.07.29 08:02 AM
You could pass it in to a projection
q)f:{[xF] g:{[xG] xG + 2};h:{[g;xH] g[xH] + 3}[g];g[xF] + h[xF]}
q)f[40]
87
Or composition in this basic case
q)f:{[xF] g:{[xG] xG + 2};h:+[3] g @;g[xF] + h[xF]}
q)f[40]
87
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.