Syntax errors in production only: should SWI-Prolog encoding be pinned in source or in deployment config?
0 reputation · 12 Jul 2023, 11:29 UTC
0 reputation · 12 Jul 2023, 11:29 UTC
A SWI-Prolog codebase loads and runs correctly on development machines, but on the production host the same files fail with syntax errors or produce silently wrong atoms. The working hypothesis is character encoding: the files are saved as UTF-8, while the server locale differs from the workstation locale, so the byte stream is misread before parsing and the reported error location is far from the actual cause.
SWI-Prolog documents the :- encoding(utf8). directive, which must be the first term in a file and forces the compiler to read the rest of that file in the given encoding regardless of environment settings. An alternative is to control the environment instead: matching LANG/LC_ALL on the server, or setting flags during the saved-state build. Both approaches are valid, but they interact in non-obvious ways, and the codebase also runs in three modes: swipl file.pl, interactive REPL loading, and a saved state built with qsave_program/2.
Assume a recent SWI-Prolog 9.x on both ends; exact flag defaults should be confirmed against the deployed version.
:- encoding(utf8). to every source file sufficient to make loading locale-independent in all three run modes, including saved states?A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.