Skip to content

User Defined Functions #170

Answered by EvgSkv
jimlloyd asked this question in Q&A
Discussion options

You must be logged in to vote

Yes!
And thanks to your comment I realized that tutorial should be improved to explain functions better.
There is no limit to how many arguments the function has, and arguments can be positional or named, just like with any other predicate.

Having one argument restriction is only for aggregation functions.

Here is an example of some functions:

@Engine("sqlite");

AreaOfRectangle(width, height) = width * height;
AreaOfTriangle(base:, height:) = base * height / 2;

Test("rectangle") = AreaOfRectangle(10, 20);
Test("triangle") = AreaOfTriangle(base: 10, height: 50);

Running it you'd get:

$ logica func.l run Test
+-----------+--------------+
| col0      | logica_value |
+-----------+--------…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jimlloyd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants