BuaBook / kdb-common

kdb+ Core Libraries and Utilities
Apache License 2.0
51 stars 16 forks source link

ns: .ns.getFunctionArguments / .ns.protectedExecute upgrades [fixes #4] #56

Closed jasraj closed 3 years ago

jasraj commented 3 years ago

.ns.getFunctionArguments

Now supports types 101, 102, 103 and 104h:

q).ns.getFunctionArguments (::)
,`x
q).ns.getFunctionArguments (+)
`x`y
q).ns.getFunctionArguments (')
`x`y
q).ns.getFunctionArguments {[x;y;z] z }[;1;]
`x`z

.ns.protectedExecute

Now supports passing functions by value and works with the additional types supported by .ns.getFunctionArguments:

q).ns.protectedExecute[(::); 1]
1
q).ns.protectedExecute[(+); 1 2]
3
q).ns.protectedExecute[('); (neg; 1 2)]
-1 2
q).ns.protectedExecute[{[x;y;z] z }[;1;]; 0 -1]
-1

Error example:

q).ns.protectedExecute[(+); (1;`a)]
isError  | `PROT_EXEC_FAILED
backtrace| ()
errorMsg | "type"

Exceptions

Both now throw NotAFunctionException if the value passed is not a function or the reference does not refer to a function:


/ Protected execute the protected execute!
q).ns.protectedExecute[`.ns.protectedExecute; (1; 1)]`errorMsg
"NotAFunctionException"
...