APL ⎕IO index origin portability across implementations and saved workspaces
0 reputation · 20 Jul 2024, 02:18 UTC
0 reputation · 20 Jul 2024, 02:18 UTC
Teams adopting APL for repeatable development environments face a configuration boundary: the session-wide index origin ⎕IO defaults to 1 in traditional code bases but 0 in scripts targeting Python interoperability. Dyalog APL, GNU APL, and NARS2000 all honor the variable, yet none persist its value in a saved workspace ()SAVE or ⎕CY copy). On restart, each implementation reverts to its own default or the user’s profile setting.
Changing ⎕IO after a workspace loads does not retroactively adjust existing constants or previously defined functions, so a single session can silently mix origins. Migration guides note the session scope but leave the default choice to the installer, giving no project-level enforcement.
Define a convention that guarantees identical indexing behavior when the same source is loaded in any supported implementation, without relying on manual ⎕IO assignment at every REPL start.
⎕LX latent expression, or wrapper script) most reliably sets ⎕IO before any user code executes across Dyalog, GNU APL, and NARS2000?⎕IO matches the expected origin and fail fast if it does not?35275 reputation · 20 Jul 2024, 06:55 UTC
1. Most reliable initialization method: a profile file that the interpreter reads before the first REPL prompt. For each major APL implementation the file names and paths are:
.aplrc (or aplrc in the installation directory).gaplrc in the user’s home directory.narsrc in the user’s home directoryPlacing ⎕IO←1 in these files guarantees that the origin is set before any user script, module, or interactive session starts. Even when a workspace is loaded, the interpreter will have already applied the profile setting.
2. Fallback if the profile cannot be trusted: a wrapper shell script that launches the interpreter with a command‑line option such as -c '⎕IO←1' (Dyalog, GNU APL) or -i '⎕IO←1' (NARS2000). This forces the origin before any code runs, independent of the user’s profile configuration.
Insert a tiny library module that is imported as the first line of every source file (or the main program). The module contains a single guard that aborts if the origin is not the expected value:
⎕IO←1 ⍝ Expected origin for the project
⍝ Guard – abort if the environment is mis‑configured
if ⎕IO≠1:⎕SIGNAL 101,'Unexpected index origin: ⎕IO='⍕⎕IO
Because the guard executes immediately upon import, any program that starts with the wrong origin will terminate with a clear error message before other code runs, preventing silent mixing of 0‑based and 1‑based indexing.
⎕IO←1 to each implementation’s profile file. Document the file locations for team members.checkIO.apl containing the guard shown above.⎕CY for dynamic import).run-project.sh that calls the interpreter with -c '⎕IO←1' to enforce the origin even if a user’s profile is missing or overridden.With this pattern, the origin is guaranteed to be set before any user code, and any deviation causes an immediate, descriptive failure.
-c (Dyalog, GNU APL) and -i (NARS2000) are supported in the versions used by the team. If not, the wrapper should document the alternative.⎕LX'⎕IO←1' are intentionally omitted because they are evaluated lazily and may be too late for early initialization.Using a profile file (or, as a safety net, a wrapper script) guarantees that ⎕IO is set before any user code runs across Dyalog, GNU APL, and NARS2000. A minimal load‑time guard module ensures that any mis‑configured environment fails fast with a clear message, preserving consistent indexing behaviour across all implementations.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.