# On type error of \`arg(1, a, \_)\`

**URL:** <https://swi-prolog.discourse.group/t/on-type-error-of-arg-1-a/5912>\
**Category:** General\
**Tags:** atom, arity\
**Created:** [November 6, 2022, 10:48am UTC](https://swi-prolog.discourse.group/t/on-type-error-of-arg-1-a/5912 "2022-11-06T10:48:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kuniaki.mukai](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kuniaki.mukai](https://swi-prolog.discourse.group/u/kuniaki.mukai)\
**Post date:** [November 6, 2022, 10:48am UTC](https://swi-prolog.discourse.group/t/on-type-error-of-arg-1-a/5912/1 "2022-11-06T10:48:51Z")

</div>

I have found an uxpected type error.

```prolog
?- arg(1, a, X).
ERROR: Type error: `compound' expected, found `a' (an atom)
ERROR: In:
ERROR: [10] arg(1,a,_102)
ERROR: [9] toplevel_call('<garbage_collected>') at /Users/cantor/lib/swipl/boot/toplevel.pl:1173

```

I expected it should be simply false because related queries on `arg/3`, `functor/3`, and `=../2` suggested it should simply fail.

```prolog
% ?- arg(2, a(1), X).
%@ false.

?- functor(T, a, 0).
T = a.

?- functor(T, a, 1).
T = a(_).

?- a =.. U.
U = [a].

?- a(1)=.. U.
U = [a, 1].

```

Perhaps I prefer to view atoms as a special case in which terms of arity is 0 as suggested by `functor/3`, and `=../2`. I hope the query `arg(1, a, _)` simply fails in the future version.

---

<div class="post-metadata">

**Author:** ![CapelliC](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/capellic/32/17_2.png) [@CapelliC](https://swi-prolog.discourse.group/u/CapelliC)\
**Post date:** [November 6, 2022, 11:36am UTC](https://swi-prolog.discourse.group/t/on-type-error-of-arg-1-a/5912/2 "2022-11-06T11:36:06Z")

</div>

The syntax of SWI-Prolog is rather more complex that ISO Prolog. Did you considered

```prolog
?- arg(1,a(),X).
false.

```

Basically, I interpret this feature as an attempt to better separate **atomic** terms - that get their semantic by metalanguage (i.e. builtins) - from compounds (except unification).

I don’t think there are many chances Jan will change the arg/3 behaviour… but you could wrap your own preferred behaviour by means of term rewriting, no ?

---

<div class="post-metadata">

**Author:** ![kuniaki.mukai](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kuniaki.mukai](https://swi-prolog.discourse.group/u/kuniaki.mukai)\
**Post date:** [November 6, 2022, 1:33pm UTC](https://swi-prolog.discourse.group/t/on-type-error-of-arg-1-a/5912/3 "2022-11-06T13:33:38Z")

</div>

> [@CapelliC](#):
>
> Basically, I interpret this feature as an attempt to better separate **atomic** terms - that get their semantic by metalanguage (i.e. builtins) - from compounds (except unification).

I am not sure I fully understand the meaning of f(). But it was useful for converting S-expressions in lisp and prolog terms. In particular, S-expression (a) to the swi-prolog term a(). Without the form a(), it was difficult to convert lisp atom a in to prolog term. That is, my understanding is that a() was the call form of predicate a without argument, though I am far from sure for the semantics of a().

As your suggestion, there is an easy workaoound for that type error. Thanks for comment.
