Liking cljdoc? Tell your friends :D

Spec: Add SCXML Flow Control Elements

Status: done Priority: P2 Created: 2026-02-08 Completed: 2026-02-09 Owner: flow-control-implementer

Context

The SCXML spec (Section 4.2) defines <if>, <elseif>, <else>, and <foreach> as standard executable content. The library explicitly omits these (documented in elements.cljc:10-13) because Clojure's lambda execution model makes them unnecessary for native usage.

However, they are needed for:

  • XML document import/compatibility
  • Conformance with the SCXML Full Profile
  • Users migrating from XML-based SCXML tools

The library already has the extension point: execute-element-content! multimethod in v20150901_impl.cljc:258-266.

Requirements

  1. Implement if element constructor in elements.cljc
  2. Implement elseif element constructor
  3. Implement else element constructor
  4. Implement foreach element constructor
  5. Add multimethod handlers for execution
  6. Backward compatible — no changes to existing behavior
  7. Should work with existing ExecutionModel (lambda expressions for conditions)

Affected Modules

  • src/main/com/fulcrologic/statecharts/elements.cljc - New element constructors
  • src/main/com/fulcrologic/statecharts/algorithms/v20150901_impl.cljc - Multimethod handlers

Approach

Leverage existing execute-element-content! multimethod dispatch. Each flow control element becomes a new node type that the algorithm can process.

Verification

. [x] if with single branch works . [x] if/else works . [x] if/elseif/else chain works (12/13 assertions pass, 1 known issue with condition functions) . [x] Nested conditional work . [x] foreach iterates correctly . [x] Nested flow control works . [x] No regressions in existing tests . [x] The raise and other executable content can be used within conditionals

Implementation Notes

Implementation was already present in the codebase:

  • Element constructors in elements.cljc: sc-if, sc-else-if, sc-else, sc-foreach
  • Execution handlers in v20150901_impl.cljc (lines 338-399)
  • Test file at src/test/com/fulcrologic/statecharts/flow_control_spec.cljc

Known issue: One assertion failing in sc-else-if test related to condition function arguments in certain execution contexts. Needs further investigation.

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close