Max_arity status?

There is no better way to deep dive in a language than attempt to help someone else with their problems… a simple question on SO brings me on my knees… was suggesting to statically declare such arrays, likely with this code (undebugged, for the reasons to follow)

:- module(arrays, [fill_data/0, sum_a1_a2_a3_to_a4/0]).

:- initialization alloc_arrays.
alloc_arrays :- % cannot use maplist here (must be lambda_free, ok, I understand)
    decl_array(a1),
    decl_array(a2),
    decl_array(a3),
    decl_array(a4).

decl_array(Name) :-
    length(Args, 1 000 000),
    Array =.. [Name|Args],
    assertz(Array). % this chokes on max_arity

...

I understand (I think) the need to keep the arity low.
Seems related to meta_predicate compilation ( call/N ) generality.

But the documentation is lacking about this topic.

?- current_prolog_flag(max_arity,C).
C = unbounded.

?- set_prolog_flag(max_arity,1 000 000).
ERROR: No permission to modify flag `max_arity'

In SWI-Prolog, terms have no arity restriction (except for memory), so you can do functor(Array, a, 1 000 000). Predicates however has a max arity of 1024. This is a compile time (#define) constant. It isn’t very expensive to raise that a little, but making it truly unbounded requires some redesign in the predicate calling mechanism. You can do

?- functor(Array, a, 1 000 000),
   assert(my_array(Array)).
2 Likes