# Functor/3 not working for a()

**URL:** <https://swi-prolog.discourse.group/t/functor-3-not-working-for-a/2680>\
**Category:** Predicate\
**Tags:** read-the-docs\
**Created:** [July 22, 2020, 1:03pm UTC](https://swi-prolog.discourse.group/t/functor-3-not-working-for-a/2680 "2020-07-22T13:03:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [July 22, 2020, 1:03pm UTC](https://swi-prolog.discourse.group/t/functor-3-not-working-for-a/2680/1 "2020-07-22T13:03:10Z")

</div>

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

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

```

The example in the [documentation](https://www.swi-prolog.org/pldoc/man?predicate=functor/3) shows it working.

This works

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

```

* * *

**EDIT**

This fails as per the documentation.

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

```

This works as per the documentation

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

```

This also works

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

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [July 22, 2020, 2:12pm UTC](https://swi-prolog.discourse.group/t/functor-3-not-working-for-a/2680/2 "2020-07-22T14:12:51Z")

</div>

> [@EricGT](#):
>
> The example in the [documentation](https://www.swi-prolog.org/pldoc/man?predicate=functor/3) shows it working.

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 ☹

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [July 22, 2020, 2:14pm UTC](https://swi-prolog.discourse.group/t/functor-3-not-working-for-a/2680/3 "2020-07-22T14:14:20Z")

</div>

> [@jan](#):
>
> as people tend not to read the text around an example carefully

Guilty!

Now for the minimum 20 characters.

---

<div class="post-metadata">

**Author:** ![dtonhofer](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/dtonhofer/32/902_2.png) [@dtonhofer](https://swi-prolog.discourse.group/u/dtonhofer)\
**Post date:** [July 23, 2020, 7:23pm UTC](https://swi-prolog.discourse.group/t/functor-3-not-working-for-a/2680/4 "2020-07-23T19:23:56Z")

</div>

The power of overview:

 ![Analysis/Assembly predicates](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/b/b6672d35f317192a55db7a9a6517e655641a2575.png)

PDF and ODS (LibreOffice Calc) are [here](https://github.com/dtonhofer/prolog_notes/tree/master/swipl_notes/about_term_analysis_and_construction) for great usage!
