Functions
Function call
The major distinction between PRQL and today’s conventional programming languages such as C or Python is the function call syntax. It consists of the function name followed by arguments separated by whitespace.
If one of the arguments is also a function call, it must be encased in parentheses, so we know where arguments of inner function end and the arguments of outer function start.
Pipeline
There is a alternative way of calling functions: using a pipeline. Regardless of whether the pipeline is delimited by pipe symbol |
or a new line, the pipeline is equivalent to applying each of functions as the last argument of the next function.
… is equivalent to …
As you may have noticed, transforms are regular functions too!
PRQL
from employees
filter age > 50
sort name
SQL
SELECT
*
FROM
employees
WHERE
age > 50
ORDER BY
name
… is equivalent to …
PRQL
from employees | filter age > 50 | sort name
SQL
SELECT
*
FROM
employees
WHERE
age > 50
ORDER BY
name
… is equivalent to …
PRQL
filter age > 50 (from employees) | sort name
SQL
SELECT
*
FROM
employees
WHERE
age > 50
ORDER BY
name
… is equivalent to …
PRQL
sort name (filter age > 50 (from employees))
SQL
SELECT
*
FROM
employees
WHERE
age > 50
ORDER BY
name
As you can see, the first example with pipeline notation is much easier to comprehend, compared to the last one with the regular function call notation. This is why it is recommended to use pipelines for nested function calls that are 3 or more levels deep.
Currying and late binding
In PRQL, functions are first class citizens. As cool as that sounds, we need simpler terms to explain it. In essence in means that we can operate with functions are with any other value.