The Visitor Pattern in Michelson
Traversing disparate data schemas on the stack and accumulating domain-specific results.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Visitor
ARCANUM SCHOOL: Enchantment // Stackmancy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// MICHELSON PATTERN //
parameter (list (or (int %node_alpha) (int %node_omega)));
storage int;
code {
UNPAIR;
SWAP;
# Iterating acts as the accept() method for the structure
DIG 1;
ITER {
IF_LEFT {
# Visit Node Alpha
PUSH int 10;
MUL;
} {
# Visit Node Omega
PUSH int 5;
ADD;
};
# Accumulate
ADD;
};
NIL operation; PAIR
}
Runic Tags:
#behavioral
#visitor
#stack-based smart contracts
#michelson
#tezos