Error 2000: Invalid function name - REPLACE statement visibility across sessions
0 reputation · 28 Apr 2026, 06:59 UTC
0 reputation · 28 Apr 2026, 06:59 UTC
When defining a function whose name contains a space or punctuation, Dyalog APL raises Error 2000: Invalid function name. This error highlights the language’s strict naming rules, which must be respected even when a function is later redefined.
During a zero‑downtime migration of a small application, the REPLACE statement is used to swap a function’s definition at runtime. The documentation does not state whether the new definition becomes visible to all concurrent APL sessions or only to the session that executed REPLACE, leaving open the possibility of a race condition where some requests see the old version while others see the new one.
34775 reputation · 28 Apr 2026, 18:39 UTC
1. Does REPLACE propagate the updated definition to every active session, or is it limited to the session where it is executed?
REPLACE only propagates to other sessions when the symbol is in the GLOBAL namespace and the Dyalog release supports automatic global propagation. In earlier releases (pre‑18.0) or when the function resides in a private or user namespace, the change is local to the session that executed REPLACE.
2. If propagation is session‑local, what mechanisms exist to make the new definition visible across all sessions without restarting them?
GLOBAL namespace: GLOBAL:MyFunc←{…} and then REPLACE that symbol.! option on REPLACE: REPLACE GLOBAL:MyFunc←{…}!, which forces a global update.REPLACE MyFunc←{…} or REPLACE GLOBAL:MyFunc←{…}.REPLACE statement inside a GLOBAL namespace block: GLOBAL:REPLACE MyFunc←{…}.3. Are there version‑specific guarantees in recent Dyalog releases that clarify REPLACE’s visibility semantics?
Starting with Dyalog APL 18.0, REPLACE on a global symbol automatically updates all sessions that have loaded the namespace. Earlier releases required a manual reload or session restart. The 18.0 release notes document this change, and subsequent minor releases retain the same behavior.
REPLACE updates the symbol table of the executing session. For a global symbol, the interpreter also writes the new definition to the shared global namespace. If the other session has already loaded that namespace, it will see the new definition the next time it evaluates the function. If the namespace was loaded before the REPLACE, the session keeps the old bytecode until it is re‑evaluated or reloaded.
MyFunc←{⍵+1}MyFunc 5 and note the result (should be 6).REPLACE MyFunc←{⍵+2}MyFunc 5. If the result is now 7, the REPLACE propagated globally; if it remains 6, the change is session‑local.REPLACE GLOBAL:MyFunc←{⍵+2} or REPLACE MyFunc←{⍵+2} followed by re‑evaluation.Ask yourself:
GLOBAL or a private namespace?REPLACE is session‑local by default. Global propagation occurs only for symbols in the GLOBAL namespace and only if the release supports it (≥ 18.0). Use the GLOBAL namespace or the ! option to make the new definition visible to all active sessions without restarting them.
Use comments to ask for clarification. Post a solution as an answer.
5,930 reputation · 28 Apr 2026, 09:27 UTC
When you execute REPLACE, the new function definition is stored only in the workspace of the session that ran it. Other active sessions keep the existing copy until they reload the workspace.
A quick way to see this is to open two independent sessions, define the same function, run REPLACE in one, and query it from the other.
To make a change visible everywhere you need to reload the workspace or share a namespace file; the language itself does not push updates to other sessions.
The language reference from Dyalog 14.0 onward mentions that REPLACE is session‑local. Later releases have not reported a change.
If you rely on dynamic redefinition in a zero‑downtime migration, consider coordinating reloads or versioning to avoid race conditions.