User-defined operator call · name( )
---
config:
flowchart:
useMaxWidth: false
---
flowchart LR
classDef ok fill:#d4edda,stroke:#28a745,color:#000
classDef partial fill:#fff3cd,stroke:#ffc107,color:#000
classDef refused fill:#d4edda,stroke:#28a745,stroke-width:3px,stroke-dasharray: 2 2,color:#000
classDef missing fill:#f8d7da,stroke:#dc3545,color:#000
classDef diverge fill:#cce5ff,stroke:#007bff,color:#000
classDef block fill:#2b3a4a,stroke:#2b3a4a,color:#fff,font-weight:bold
classDef ext fill:#fff,stroke:#666,color:#000,stroke-dasharray: 5 5
O["User-defined operator call · name( )<br/>🟢4"]:::ok
v_no_args["op()"]:::ok
v_all_args["op(a, b)"]:::ok
v_default_omitted["op(a)"]:::ok
v_placeholder_arg["op(a, _, c)"]:::ok
v_no_args --- O
v_all_args --- O
O --- v_default_omitted
O --- v_placeholder_arg
click v_no_args href "#form-no-args"
click v_all_args href "#form-all-args"
click v_default_omitted href "#form-default-omitted"
click v_placeholder_arg href "#form-placeholder-arg"
Types
Takes operator, any scalar · Gives any type
Comes from: any operator that returns a value
Comes from · operator — 1 operator in 1 block 🟢1
Definitions (VTL-DL) (1) 🟢1
Goes to: whatever takes its input's type
Forms
op() 🟢 · operator → any type
Empty argument list 🟢 pandas ✅ · DuckDB ✅
- Tests:
A call with no arguments,
answer(), of an operator defined with no parameters.- Manual:
User-defined operator call: the syntax
operatorName ( { argument { , argument }* } )makes the whole list of arguments optional, and the define operator syntax does the same for the parameters,( { parameter { , parameter }* } ).- Expected:
SC_r = 42, the body of the operator, an Integer.
define operator answer ()
returns integer is
42
end operator;
SC_r := answer();
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · expected/scalars.json · example page ↗
op(a, b) 🟢 · operator, any scalar → any type
Positional order 🟢 pandas ✅ · DuckDB ✅
- Tests:
A call with every argument,
diff2(SC_1, SC_2)withSC_1= 10 andSC_2= 3, whose bodyx - ytells their order apart, as the page’smax1 ( 2, 3 )cannot.- Manual:
User-defined operator call: “The arguments passed to the operator in the invocation are associated to the corresponding parameters in positional order”. The page’s
max1, which the define operator page repeats, declaresreturns booleanfor a body that returns an integer, and the script ends its definition withend operator, as the examples there do, not withend define operatoras the syntax does.- Expected:
x = 10andy = 3, soSC_r = 7, an Integer asreturns integerdeclares; swapped arguments would give -7.
define operator diff2 (x integer, y integer)
returns integer is
x - y
end operator;
SC_r := diff2(SC_1, SC_2);
| SC_1 | SC_2 |
|---|---|
| 10 | 3 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
op(a) 🟢 · operator, any scalar → any type
Trailing default 🟢 pandas ✅ · DuckDB ✅
- Tests:
A call that omits its last argument, an optional one:
diff2(SC_1)withSC_1= 10.- Manual:
User-defined operator call: “One or more optional operands in the last positions can be simply omitted”, and define operator: “If parameterDefaultValue is specified then the parameter is optional”.
- Expected:
ytakes its default 1, soSC_r = 10 - 1 = 9, an Integer.
define operator diff2 (x integer, y integer default 1)
returns integer is
x - y
end operator;
SC_r := diff2(SC_1);
| SC_1 |
|---|
| 10 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
op(a, _, c) 🟢 · operator, any scalar → any type
Underscore in the middle 🟢 pandas ✅ · DuckDB ✅
- Tests:
A call with
_for an optional argument in the middle,diff3(SC_1, _, SC_2)withSC_1= 10 andSC_2= 5, where it cannot simply be left out becausezcomes after it.- Manual:
User-defined operator call: “An underscore (“_”) can be used to denote that the value for an optional operand is omitted.”
- Expected:
x = 10,ytakes its default 1 andz = 5, soSC_r = 10 - 1 - 5 = 4, an Integer; reading 5 asy, withzat its default 100, would give -95.
define operator diff3 (x integer, y integer default 1, z integer default 100)
returns integer is
x - y - z
end operator;
SC_r := diff3(SC_1, _, SC_2);
| SC_1 | SC_2 |
|---|---|
| 10 | 5 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗