Functor/3 not working for a()

Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.4-11-g1db629e24)
On Windows 10

?- functor(a(),N,A).
ERROR: Domain error: `compound_non_zero_arity' expected, found `a()'
ERROR:   [10] functor(a(),_18014,_18016)
ERROR:    [9] <user>

The example in the documentation shows it working.

This works

?- functor(a,N,A).
N = a,
A = 0.


This fails as per the documentation.

?- a() =.. List.
ERROR: Domain error: `compound_non_zero_arity' expected, found `a()'
ERROR:   [10] a()=.._20256
ERROR:    [9] <user>

This works as per the documentation

?- compound_name_arguments(a(),N,A).
N = a,
A = [].

This also works

?- compound_name_arity(a(),Name,Arity).
Name = a,
Arity = 0.

But the docs also state the exception explicitly and claim the example as hypothetical, showing what would happen if we did not raise an exception. Nevertheless, removed the example as people tend not to read the text around an example carefully and showing examples of what doesn’t work or what is bad is thus highly confusing :frowning:

1 Like


Now for the minimum 20 characters.

1 Like

The power of overview:

PDF and ODS (LibreOffice Calc) are here for great usage!