Macros

A macro gives a title to reusable expression syntax. Expansion replaces a call with its template before compilation. The expanded expression follows the expression type and cost rules.

TRON371 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0043C 616765txt "age"
00802 24000000000000 00i64 36
0110F 0A 04000000 0800 0000map leaf, size 10: @4 → @8
01B4C 726F6C65txt "role"
0208C 656E67696E6565 72txt "engineer"
0290F 0A 1B000000 2000 0000map leaf, size 10: @1B → @20
0334C 6E616D65txt "name"
0383C 416461txt "Ada"
03C0F 0A 33000000 3800 0000map leaf, size 10: @33 → @38
04607 12 00910000 1100 0000 29000000 3C00 0000map branch, size 18, depth 0 (root), slots 8, 12, 15: @11 → @29 → @3C
0585C 236C696E6Btxt "#link"
05E5C 235F616461txt "#_ada"
0640F 0A 58000000 5E00 0000map leaf, size 10: @58 → @5E
06E3C 616765txt "age"
07202 29000000000000 00i64 41
07B0F 0A 6E000000 7200 0000map leaf, size 10: @6E → @72
0856C 6D656E746F72txt "mentor"
08C0F 0A 85000000 6400 0000map leaf, size 10: @85 → @64
0964C 726F6C65txt "role"
09B8C 656E67696E6565 72txt "engineer"
0A40F 0A 96000000 9B00 0000map leaf, size 10: @96 → @9B
0AE4C 6E616D65txt "name"
0B33C 426F62txt "Bob"
0B70F 0A AE000000 B300 0000map leaf, size 10: @AE → @B3
0C107 16 00990000 7B00 0000 8C000000 A400 0000 B7000000map branch, size 22, depth 0 (root), slots 8, 11, 12, 15: @7B → @8C → @A4 → @B7
0D73C 616765txt "age"
0DB02 1D000000000000 00i64 29
0E40F 0A D7000000 DB00 0000map leaf, size 10: @D7 → @DB
0EE4C 726F6C65txt "role"
0F38C 64657369676E65 72txt "designer"
0FC0F 0A EE000000 F300 0000map leaf, size 10: @EE → @F3
1064C 6E616D65txt "name"
10B2C 4379txt "Cy"
10E0F 0A 06010000 0B01 0000map leaf, size 10: @106 → @10B
11807 12 00910000 E400 0000 FC000000 0E01 0000map branch, size 18, depth 0 (root), slots 8, 12, 15: @E4 → @FC → @10E
12A4C 235F6379txt "#_cy"
12F0F 0A 2A010000 1801 0000map leaf, size 10: @12A → @118
1395C 235F626F62txt "#_bob"
13F0F 0A 39010000 C100 0000map leaf, size 10: @139 → @C1
1495C 235F616461txt "#_ada"
14F0F 0A 49010000 4600 0000map leaf, size 10: @149 → @46
15907 12 80210000 2F01 0000 3F010000 4F01 0000map branch, size 18, depth 0 (root), slots 7, 8, 13: @12F → @13F → @14F

Define a macro

A macro document has ordered params and an expands template. An optional description explains its purpose. A stored definition has a title. The native macro builder also accepts an authored definition without saving it.

TRON216 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
046C 616D6F756E74txt "amount"
0B4C 72617465txt "rate"
100E 11 00 0300 020000 00 04000000 0B0000 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @4 → @B
216C 696E73657274txt "insert"
286C 616D6F756E74txt "amount"
2F0F 0A 21000000 2800 0000map leaf, size 10: @21 → @28
396C 696E73657274txt "insert"
404C 72617465txt "rate"
450F 0A 39000000 4000 0000map leaf, size 10: @39 → @40
4F1C 2Atxt "*"
510E 15 00 0700 030000 00 4F000000 2F0000 00 45000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4F → @2F → @45
666C 706172616D73txt "params"
6D0F 0A 66000000 1000 0000map leaf, size 10: @66 → @10
777C 657870616E6473txt "expands"
7F0F 0A 77000000 5100 0000map leaf, size 10: @77 → @51
89BC 64657363726970 74696F6Etxt "description"
9514 1D 4D756C746970 6C7920616E20616D 6F756E7420627920 6120726174652Etxt "Multiply an amount by a …"
B40F 0A 89000000 9500 0000map leaf, size 10: @89 → @95
BE07 12 00850000 6D00 0000 7F000000 B400 0000map branch, size 18, depth 0 (root), slots 8, 10, 15: @6D → @7F → @B4

Parameter names are plain text. Each name must differ from the other names. A name cannot be empty or contain whitespace. A macro cannot have a built-in operator's title. Definition validation rejects unknown fields, missing required fields and invalid markers.

Call a macro

A call has the title first, then one argument for each declared parameter.

TRON72 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0414 12 70726963696E 672F6170706C792D 72617465txt "pricing/apply-rate"
189C 3F737562746F74 616Ctxt "?subtotal"
2203 9A9999999999C9 3Ff64 0.2
2B0E 15 00 0700 030000 00 04000000 180000 00 22000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @18 → @22
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0403 00000000000034 40f64 20

Expansion produces [* ?subtotal 0.2]. The variable remains a caller input. Expansion rejects an invalid argument count.

TRON58 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0414 12 70726963696E 672F6170706C792D 72617465txt "pricing/apply-rate"
1802 64000000000000 00i64 100
210E 11 00 0300 020000 00 04000000 180000 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @4 → @18

Error

Invalid_Call

Insert and spread

An insertion marker is a map with one member. {insert name} replaces the marker with one argument tree. {spread name} inserts each item of a list argument into the surrounding list.

TRON124 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
046C 76616C756573txt "values"
0B0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
186C 737072656164txt "spread"
1F6C 76616C756573txt "values"
260F 0A 18000000 1F00 0000map leaf, size 10: @18 → @1F
301C 2Btxt "+"
320E 11 00 0300 020000 00 30000000 260000 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @30 → @26
436C 706172616D73txt "params"
4A0F 0A 43000000 0B00 0000map leaf, size 10: @43 → @B
547C 657870616E6473txt "expands"
5C0F 0A 54000000 3200 0000map leaf, size 10: @54 → @32
6607 0E 00050000 4A00 0000 5C000000map branch, size 14, depth 0 (root), slots 8, 10: @4A → @5C
TRON98 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 01000000000000 00i64 1
0D02 02000000000000 00i64 2
1602 03000000000000 00i64 3
1F02 04000000000000 00i64 4
280E 19 00 0F00 040000 00 04000000 0D0000 00 16000000 1F0000 00array leaf, size 25, shift 0, bitmap 000F, count 4 (root): @4 → @D → @16 → @1F
417C 73756D2D616C6Ctxt "sum-all"
490E 11 00 0300 020000 00 41000000 280000 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @41 → @28
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 0A000000000000 00i64 10

The expansion is [+ 1 2 3 4]. A spread marker needs a surrounding list and a list argument. An insertion preserves a list or map as one argument tree.

Compose macros

A template can call another macro. Expansion resolves nested calls before the compiler validates operators and types. Expansion rejects direct and indirect cycles.

TRON160 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 76616C7565txt "value"
0A5C 666C6F6F72txt "floor"
100E 11 00 0300 020000 00 04000000 0A0000 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @4 → @A
216C 696E73657274txt "insert"
285C 76616C7565txt "value"
2E0F 0A 21000000 2800 0000map leaf, size 10: @21 → @28
386C 696E73657274txt "insert"
3F5C 666C6F6F72txt "floor"
450F 0A 38000000 3F00 0000map leaf, size 10: @38 → @3F
4F2C 3E3Dtxt ">="
520E 15 00 0700 030000 00 4F000000 2E0000 00 45000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4F → @2E → @45
676C 706172616D73txt "params"
6E0F 0A 67000000 1000 0000map leaf, size 10: @67 → @10
787C 657870616E6473txt "expands"
800F 0A 78000000 5200 0000map leaf, size 10: @78 → @52
8A07 0E 00050000 6E00 0000 80000000map branch, size 14, depth 0 (root), slots 8, 10: @6E → @80
TRON222 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 76616C7565txt "value"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
176C 696E73657274txt "insert"
1E5C 76616C7565txt "value"
240F 0A 17000000 1E00 0000map leaf, size 10: @17 → @1E
2E8C 61742D6C656173 74txt "at-least"
3702 12000000000000 00i64 18
400E 15 00 0700 030000 00 2E000000 240000 00 37000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @2E → @24 → @37
556C 696E73657274txt "insert"
5C5C 76616C7565txt "value"
620F 0A 55000000 5C00 0000map leaf, size 10: @55 → @5C
6C1C 3Ctxt "<"
6E02 41000000000000 00i64 65
770E 15 00 0700 030000 00 6C000000 620000 00 6E000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @6C → @62 → @6E
8C3C 616E64txt "and"
900E 15 00 0700 030000 00 8C000000 400000 00 77000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @8C → @40 → @77
A56C 706172616D73txt "params"
AC0F 0A A5000000 0A00 0000map leaf, size 10: @A5 → @A
B67C 657870616E6473txt "expands"
BE0F 0A B6000000 9000 0000map leaf, size 10: @B6 → @90
C807 0E 00050000 AC00 0000 BE000000map branch, size 14, depth 0 (root), slots 8, 10: @AC → @BE
TRON50 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
04BC 776F726B696E67 2D616765txt "working-age"
1002 24000000000000 00i64 36
190E 11 00 0300 020000 00 04000000 100000 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @4 → @10
TRON13 B
Offset (hex)Bytes (hex)Meaning
054 52 4F 4Emagic TRON
409bit true

quote stops macro expansion inside its values. The expression evaluator still rejects quote. Syntax preserved during expansion is not necessarily executable.

Use macros in queries

A query expands macros in expression positions, including predicates, derivations, computed columns, grouping filters, ordering and projection. Ordinary fact values remain data.

TRON250 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 3F6E616D65txt "?name"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
177C 3F706572736F6Etxt "?person"
1F3C 616765txt "age"
234C 3F616765txt "?age"
280E 15 00 0700 030000 00 17000000 1F0000 00 23000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @17 → @1F → @23
3D7C 3F706572736F6Etxt "?person"
454C 6E616D65txt "name"
4A5C 3F6E616D65txt "?name"
500E 15 00 0700 030000 00 3D000000 450000 00 4A000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @3D → @45 → @4A
65BC 776F726B696E67 2D616765txt "working-age"
714C 3F616765txt "?age"
760E 11 00 0300 020000 00 65000000 710000 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @65 → @71
870E 15 00 0700 030000 00 28000000 500000 00 76000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @28 → @50 → @76
9C5C 3F6E616D65txt "?name"
A20E 0D 00 0100 010000 00 9C000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @9C
AF5C 7768657265txt "where"
B50F 0A AF000000 8700 0000map leaf, size 10: @AF → @87
BF4C 66696E64txt "find"
C40F 0A BF000000 0A00 0000map leaf, size 10: @BF → @A
CE7C 6F726465724279txt "orderBy"
D60F 0A CE000000 A200 0000map leaf, size 10: @CE → @A2
E007 12 2A000000 B500 0000 C4000000 D600 0000map branch, size 18, depth 0 (root), slots 1, 3, 5: @B5 → @C4 → @D6
TRON89 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 6E616D65txt "name"
093C 416461txt "Ada"
0D0F 0A 04000000 0900 0000map leaf, size 10: @4 → @9
174C 6E616D65txt "name"
1C3C 426F62txt "Bob"
200F 0A 17000000 1C00 0000map leaf, size 10: @17 → @1C
2A4C 6E616D65txt "name"
2F2C 4379txt "Cy"
320F 0A 2A000000 2F00 0000map leaf, size 10: @2A → @2F
3C0E 15 00 0700 030000 00 0D000000 200000 00 32000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @D → @20 → @32

A mutation uses the same expansion rules in its selection query.

Current and pinned definitions

An unpinned call uses the current title mapping. Each accepted update records a mapping revision. A pin names that mapping revision, rather than the macro entity or its definition revision.

This update changes working-age to require an age of at least 40.

TRON216 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 76616C7565txt "value"
0A0E 0D 00 0100 010000 00 04000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @4
176C 696E73657274txt "insert"
1E5C 76616C7565txt "value"
240F 0A 17000000 1E00 0000map leaf, size 10: @17 → @1E
2E2C 3E3Dtxt ">="
3102 28000000000000 00i64 40
3A0E 15 00 0700 030000 00 2E000000 240000 00 31000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @2E → @24 → @31
4F6C 696E73657274txt "insert"
565C 76616C7565txt "value"
5C0F 0A 4F000000 5600 0000map leaf, size 10: @4F → @56
661C 3Ctxt "<"
6802 41000000000000 00i64 65
710E 15 00 0700 030000 00 66000000 5C0000 00 68000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @66 → @5C → @68
863C 616E64txt "and"
8A0E 15 00 0700 030000 00 86000000 3A0000 00 71000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @86 → @3A → @71
9F6C 706172616D73txt "params"
A60F 0A 9F000000 0A00 0000map leaf, size 10: @9F → @A
B07C 657870616E6473txt "expands"
B80F 0A B0000000 8A00 0000map leaf, size 10: @B0 → @8A
C207 0E 00050000 A600 0000 B8000000map branch, size 14, depth 0 (root), slots 8, 10: @A6 → @B8
TRON50 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
04BC 776F726B696E67 2D616765txt "working-age"
1002 24000000000000 00i64 36
190E 11 00 0300 020000 00 04000000 100000 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @4 → @10
TRON13 B
Offset (hex)Bytes (hex)Meaning
054 52 4F 4Emagic TRON
401bit false

The first recorded mapping revision of working-age is 13 in this fresh fixture. Read the actual revision from the saved definition in your database. A pinned call keeps that earlier rule.

TRON115 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
04FC 6D617070696E67 5265766973696F6Etxt "mappingRevision"
1402 0D000000000000 00i64 13
1D0F 0A 04000000 1400 0000map leaf, size 10: @4 → @14
275C 7469746C65txt "title"
2DBC 776F726B696E67 2D616765txt "working-age"
390F 0A 27000000 2D00 0000map leaf, size 10: @27 → @2D
4307 0E 08400000 1D00 0000 39000000map branch, size 14, depth 0 (root), slots 3, 14: @1D → @39
5102 24000000000000 00i64 36
5A0E 11 00 0300 020000 00 43000000 510000 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @43 → @51
TRON13 B
Offset (hex)Bytes (hex)Meaning
054 52 4F 4Emagic TRON
409bit true

A query can pin all calls of a title with its definitions member. Expansion consumes that metadata before query compilation.

TRON307 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
004BC 776F726B696E67 2D616765txt "working-age"
01002 0D000000000000 00i64 13
0190F 0A 04000000 1000 0000map leaf, size 10: @4 → @10
0235C 3F6E616D65txt "?name"
0290E 0D 00 0100 010000 00 23000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @23
0367C 3F706572736F6Etxt "?person"
03E3C 616765txt "age"
0424C 3F616765txt "?age"
0470E 15 00 0700 030000 00 36000000 3E0000 00 42000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @36 → @3E → @42
05C7C 3F706572736F6Etxt "?person"
0644C 6E616D65txt "name"
0695C 3F6E616D65txt "?name"
06F0E 15 00 0700 030000 00 5C000000 640000 00 69000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @5C → @64 → @69
084BC 776F726B696E67 2D616765txt "working-age"
0904C 3F616765txt "?age"
0950E 11 00 0300 020000 00 84000000 900000 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @84 → @90
0A60E 15 00 0700 030000 00 47000000 6F0000 00 95000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @47 → @6F → @95
0BB5C 3F6E616D65txt "?name"
0C10E 0D 00 0100 010000 00 BB000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @BB
0CE5C 7768657265txt "where"
0D40F 0A CE000000 A600 0000map leaf, size 10: @CE → @A6
0DE4C 66696E64txt "find"
0E30F 0A DE000000 2900 0000map leaf, size 10: @DE → @29
0ED7C 6F726465724279txt "orderBy"
0F50F 0A ED000000 C100 0000map leaf, size 10: @ED → @C1
0FFBC 646566696E6974 696F6E73txt "definitions"
10B0F 0A FF000000 1900 0000map leaf, size 10: @FF → @19
11507 16 2A020000 D400 0000 E3000000 F500 0000 0B010000map branch, size 22, depth 0 (root), slots 1, 3, 5, 9: @D4 → @E3 → @F5 → @10B
TRON89 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 6E616D65txt "name"
093C 416461txt "Ada"
0D0F 0A 04000000 0900 0000map leaf, size 10: @4 → @9
174C 6E616D65txt "name"
1C3C 426F62txt "Bob"
200F 0A 17000000 1C00 0000map leaf, size 10: @17 → @1C
2A4C 6E616D65txt "name"
2F2C 4379txt "Cy"
320F 0A 2A000000 2F00 0000map leaf, size 10: @2A → @2F
3C0E 15 00 0700 030000 00 0D000000 200000 00 32000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @D → @20 → @32

Expansion rejects an unknown mapping revision. It does not select the current rule.

Run it

build macro · expand macro.