Manage static UDFs¶
Manage q static user-defined functions (UDFs):
deleteUDF remove UDF from server
getUDFInfo get UDF metadata
saveUDF register a UDF on the server
getUDFDescription get UDF description in reader-friendly format
You can also manage q static UDFs through the command-line interface.
saveUDF¶
Define a UDF on the server
saveUDF `funcName`func`description!(funcName;func;description)
Where
funcNameis the name of a function as a symbol atomfuncis a function or a string that parses as a functiondescriptionis a string describing the function
The function is checked against the restrictions below and stored on the server. Any previous function of the same name is overwritten. If the restrictions are violated, saveUDF signals an error.
Example:
name:`testGetTicks
fn:"{[dict]
k:`symList`dataType`assetClass`startDate`endDate`startTime`endTime;
getTicks k!(`;`quote;`moneyMarket),dict`sD`eD`sT`eT }"
desc:"This function is a wrapper for getTicks.
It has 4 inputs, sD, ed, sT, eT,
which are startDate, endDate, startTime and endTime respectively."
saveUDF `funcName`func`description!(name;fn;desc)
To protect the server from user code that could permanently harm it, saveUDF parses incoming q UDF code and checks it against the following restrictions:
- takes a single dictionary argument
- refers to no global variables or functions besides API functions (
getStats,getTicks, etc.) and native q functions (e.g. joins), some.Qutilities, and some.zobjects - no disk operations
- opens no handles between processes (
hopen) - no system calls
- parses no strings (e.g.
get"hopen 5346"will fail) - no
exitcalls
Note
Comment lines in the func argument cause an error.
UDFs are parsed on loading to confirm that they are structured correctly.
Keep the func argument free from comments and copy the code with comments into the description argument.
getUDFInfo¶
Get UDF metadata from the server
getUDFInfo enlist[`funcNames]!names
where names is a list of UDF names as a symbol vector or atom, returns a table of information about the UDFs. The null symbol ` in names selects all defined UDFs.
The result table has columns:
funcName symbol name of the UDF
funcExists boolean whether defined in the system
funcCode string code for the UDF
description string description of the UDF
Example:
getUDFInfo enlist[`funcNames]!enlist `testGetTicks
A single-key dictionary needs the arguments of Dict enlisted.
deleteUDF¶
Remove UDFs from the server
deleteUDF enlist[`funcNames]!enlist names
where names is a list of UDF names as a symbol vector or atom, deletes the corresponding UDFs from the server. (The null symbol does not select all UDFs.)
Example:
deleteUDF (enlist`funcNames)!enlist `testGetTicks
getUDFDescription¶
Return the UDF description in a reader-friendly format
getUDFDescription enlist[`funcNames]!enlist names
where names is a list of UDF names as a symbol vector or atom, returns the corresponding UDF descriptions in a reader-friendly format. (The null symbol does not select all UDFs.)
getUDFDescription (enlist`funcNames)!enlist `testGetTicks