Positional vs. named parameters
Definition
Both forms are legal IEC 61131-3:
- Positional:
fc(a, b, c)— arguments are matched to parameters by their position in the parameter list. Concise but fragile against parameter-list refactors. - Named:
fc(IN1 := a, IN2 := b, MODE := c)— arguments are matched by name. Verbose but stable across refactors and self-documenting.
The two forms cannot be mixed within a single call.
Syntax
Positional
result := fname ( expr1 , expr2 , ... );
Arguments must appear in the order declared on the function / FB. Trailing optional inputs may be omitted (matiec extension — the IEC standard requires all positional arguments to be present).
Named
result := fname ( param1 := expr1 , param2 := expr2 , ... );
Arguments may appear in any order. Optional inputs may be
omitted. The parameter name on the left of := must match the
callee’s declaration exactly (case-sensitive in matiec).
When to prefer which
| Situation | Recommended form |
|---|---|
Single-argument standard function (ABS, SQRT, NOT) | Positional — concise, no ambiguity |
Multi-argument standard function with stable parameter list (SEL, MUX, LIMIT) | Either; named for clarity in non-trivial cases |
Multi-argument FB call (TON, CTU, RS) | Named — the parameter list (IN/PT/Q/ET) is meaningful and the order is non-obvious to a reader |
| User-written FB or function | Named — defends the call site against later parameter-list refactors |
| Existing call site under maintenance | Match the surrounding style |
Examples
(* Positional — concise, fine for single-arg standard FUNs *)
iAbs := ABS(-3);
rRoot := SQRT(2.0);
xNotted := NOT xFlag;
(* Named — multi-arg FB, documents itself *)
stepTimer(IN := xStart,
PT := T#100ms);
(* Mixed — IEC-illegal, matiec rejects *)
(* ✗ stepTimer(xStart, PT := T#100ms); *)
(* Both forms work; pick named for FBs by default *)
edgeRise(CLK := xButton); (* named *)
edgeFall(xButton); (* positional — also legal *)
IEC reference
- Calling functions: clause 6.6.2.1 of IEC 61131-3 third edition (2013).
- Calling function blocks: clause 6.6.2.2.
matiec conformance
matiec accepts both forms as required. Two strict points worth flagging:
- No mixing within one call. matiec rejects
fc(a, p := v)even though some vendor compilers accept it. - Case-sensitive parameter names in the named form.
stepTimer(in := x, pt := t)is rejected even though IEC identifiers are case-insensitive in general. Always match the spelling reported bylibrary.read_block.
ForgeIEC notes
- The MCP tool
library.read_block(name)returns the canonical parameter list for any FB or function. Use it before writing a multi-arg call to look up the exact parameter spelling, especially for built-ins likeTON(parameters:IN,PT,Q,ET) or for user FBs whose parameter list might have changed since the last call site was written. - The auto-completion in the ForgeIEC editor suggests
parameter names in named form by default. If you typed a
positional argument and hit
Tab, the completion converts to named.