idl 8.4 introduced the lambda
function. I have IDL 8.6.1 and the lambda
function does not fully work as documented:
IDL> f = lambda(x : x * x)
IDL> print, call_function(f, findgen(10))
0.00000 1.00000 4.00000 9.00000 16.0000 25.0000 36.0000 49.0000 64.0000
81.0000
IDL> print, f(findgen(10))
IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5 IDL$LAMBDAF5
IDL$LAMBDAF5
IDL> print, f(5)
% Attempt to subscript F with <INT ( 5)> is out of range.
So, why f(5)
does not return 25
?
Oh, as commented here, this is documented.
Note: To make direct calls on a Lambda function, you should make sure that compile_opt strictarr (or compile_opt idl2) is turned on so that IDL interprets the parentheses as a function call instead of array indices. See COMPILE_OPT for details.
So
compile_opt strictarr
or
compile_opt idl2
.
However, I would have expected that direct calls are possible by default.