MACRO()
All functions > CORE > MACRO()
Turns a feature expression into a function whose parameters are some of its inputs.
Signatures
Returns: A function you call like a built-in: F(2e0) or 2e0.F()
MACRO( expression USING parameter, ... ) → FEATURE
| Parameter | Type | Required | Description |
|---|---|---|---|
expression | FEATURE | Yes | Body of the function: a feature or an inline expression |
parameter | FEATURE | Yes | Input of the body that becomes a parameter. The USING order is the argument order |
Notes
- A call is a
VARIANT()of the body that replaces each parameter with its argument, everywhere in the body's graph - Arguments are computed in the caller's graph, so an argument can be a feature the body also uses
- Use
UDF()when you need several signatures or backend-specific SQL
See also
Examples
Turn a feature into a function and call it
FeatureQL
DEFINE
radius := INPUT(DOUBLE),
area_circle_feature := PI() * POW(radius, 2e0),
area_circle_function := MACRO(area_circle_feature USING radius)
RETURN
area_circle_value_for_2 := area_circle_function(2e0),
area_circle_value_for_5 := area_circle_function(5e0)
;Result
| AREA_CIRCLE_VALUE_FOR_2 DOUBLE | AREA_CIRCLE_VALUE_FOR_5 DOUBLE |
|---|---|
| 12.566370614359172 | 78.53981633974483 |
Several parameters: USING order is the argument order
FeatureQL
DEFINE
length := INPUT(DOUBLE),
width := INPUT(DOUBLE),
area_rectangle_function := MACRO(length * width USING length, width)
RETURN
area_rectangle_value_for_2_5 := area_rectangle_function(2e0, 5e0),
area_rectangle_value_for_5_3 := area_rectangle_function(5e0, 3e0)
;Result
| AREA_RECTANGLE_VALUE_FOR_2_5 DOUBLE | AREA_RECTANGLE_VALUE_FOR_5_3 DOUBLE |
|---|---|
| 10.0 | 15.0 |
Call with the chaining syntax
FeatureQL
DEFINE
radius := INPUT(DOUBLE),
area_circle_function := MACRO(PI() * POW(radius, 2e0) USING radius)
RETURN
area_circle_value_for_2_chaining := 2e0.area_circle_function()
;Result
| AREA_CIRCLE_VALUE_FOR_2_CHAINING DOUBLE |
|---|
| 12.566370614359172 |