Prolog systems aiming at iso-prolog conformity do not have to support compound terms with arbitrarily large arities. The Prolog flag max_arity
reflects this.
According to ISO/IEC 13211-1:1995:
7.11.2.3 Flag: max_arity
Possible values: The default value only
Default value: implementation defined
Changeable: No
Description: The maximum arity allowed for any compound term, or
unbounded
when the processor has no limit for the number of arguments for a compound term.
So Prolog systems may or may not impose an upper limit on max_arity
... but what about the lower limit? Is, say, 5
okay?
NO!
ISO/IEC 13211-1:1995/Cor.2:2012, Technical Corrigendum 2, defines call/2..8
as:
8.15.4 call/2..8
...
NOTE — A standard-conforming processor may implement call/N in one of the following ways because error condition d is implementation dependent (3.91).
All of these ways only imply Max_arity >= 8
—but nothing more.
So my question has (at least) two sides:
Prolog User:
"What is the maximum arity I may use if I want to avoid vendor lock-in?"
Prolog Implementor:
"What is the smallest Max_arity
I must support if I aim1 at ISO-Prolog conformity?"
Right now, I'm quite sure the answer is this:
Yes,
Max_arity = 8
is okay.
But is it in fact so? Are there clues I am missing?
Footnotes:
1) I do.
There is a gap somehow. max_arity only covers the compound size. But there is no flag for predicate size. The two things might vary as SWI-Prolog shows. But SWI-Prolog names the limit wrongly max_arity, although its not its max_arity flag:
/* SWI-Prolog 8.3.19 */
?- functor(_,f,10000).
true.
?- functor(F,f,10000), assertz(F).
ERROR: Cannot represent due to `max_arity' (limit is 1024, request = 10000)
?- current_prolog_flag(max_arity, X).
X = unbounded.
The predicate size limit might be more relevant to call/n than the compound size. The ISO core standard definition is a little unsatisfactory.
But its not thoroughly checked, but a fix on SWI-Prologs side is underway:
?- functor(F,f,10000), assertz(test:-F).
F = f(_ ...)
?- functor(F,f,10000), call(F,a).
%%% crash
Edit 25.02.2021:
The glitch in the error message is only explained when you look at the C-Code of SWI-Prolog, which has a C Constant MAXARITY with the meaning of predicate size. This Constant and the Error Message possibly predates the ISO core standard, which introduced another constant.