Set Type

The Set Complex Type stores a collection of variable ids and exposes functional-style operations such as map, filter, and reduce. It is especially useful for reactive batch processing over variable groups.

Creation Syntax

@world0 := "World 0"
@world1 := "World 1"
@world2 := "World 2"
@worldSet new Set world0 world1 world2

@firstWorld worldSet.first
@secondWorld worldSet.getAt 1
@restSet worldSet.rest
@exported worldSet.export

first and getAt expose element references. rest returns a new Set. export returns a comma-separated list of member variable ids.

Example

@sayHello macro world hello
    @res := $hello $world
    return $res
end

@hello := Hello
@result worldSet.map sayHello $hello
@res0 result.getAt 0
@res1 result.getAt 1

This pattern comes from tests/pipelines/set/containersTest.mjs. map expands the macro per set member and creates output variables that stay linked to source members.

Step-by-Step Interaction

@worldFilter jsdef item
    return item === "World 1" || item === "World 2";
end
@filtered worldSet.filter worldFilter

@count jsdef item result
    if(result === undefined){ result = 0; }
    result++;
    return result;
end
@counter worldSet.reduce count

The interaction flow starts when a set is declared from variable ids and then transformed by higher-order methods. The map method executes a macro or jsdef function for each member and stores mapped outputs in a derived set. The filter method evaluates a predicate and retains members for which the predicate does not return false. The reduce method folds members into an accumulator in iteration order and returns one final value. These behaviors are validated in tests/pipelines/macros/advanced/filterTest.mjs and tests/pipelines/macros/advanced/reduceTest.mjs.

Runtime Role Notes

The Set type is the main collection primitive for macro/jsdef-based iteration. Because members are variable ids, updates to underlying variables propagate through mapped/filtered derived outputs.