Creates a new procedure to the @thingsdb
or a @collection
scope. The name of the procedure must be unique within the scope.
The given closure will be copied to the procedure, so this is not a reference to the given closure.
This function generates a change.
new_procedure(name, closure)
Argument | Type | Description |
---|---|---|
name |
str (required) | Name of the new procedure. |
closure |
closure (required) | Closure which will be attached to the procedure. |
Returns the name of the new procedure. A lookup_err() is raised if the procedure already exists.
Create a new procedure
add_one
:
// Create a new procedure `add_one`
new_procedure('add_one', |x| {
"Adds one to a given value";
x + 1;
});
Return value in JSON format
"add_one"