# Singleton warnings, multitons warning

**URL:** <https://swi-prolog.discourse.group/t/singleton-warnings-multitons-warning/5392>\
**Category:** Discussion\
**Created:** [May 14, 2022, 4:02pm UTC](https://swi-prolog.discourse.group/t/singleton-warnings-multitons-warning/5392 "2022-05-14T16:02:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgondan1](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/mgondan1/32/803_2.png) [@mgondan1](https://swi-prolog.discourse.group/u/mgondan1)\
**Post date:** [May 14, 2022, 4:02pm UTC](https://swi-prolog.discourse.group/t/singleton-warnings-multitons-warning/5392/1 "2022-05-14T16:02:54Z")

</div>

I am wondering if pred5 should also raise a warning because the same variable name is used as-is and “underscored”. What do you think?

```prolog
a :- pred1(Flags). % singleton
a :- pred2(_Flags). % no warning
a :- pred3(_Flags, _Flags). % "multiton"
a :- pred4(_Flags, Flags). % singleton
a :- pred5(_Flags, Flags, Flags). % should this raise a warning?

```

---

<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:** [May 15, 2022, 8:24am UTC](https://swi-prolog.discourse.group/t/singleton-warnings-multitons-warning/5392/2 "2022-05-15T08:24:59Z")

</div>

Surely the current behavior is on purpose. `Flags` and `_Flags` have no relation to one another. Thus, in pred5 there is `_Flags` as a singleton, which is fine and two instances of `Flags`, which is fine too.

Of course, one could argue that if `_Name` is there only to avoid a singleton warning it is a good idea to have a warning if both `_Name` and `Name` appear in a clause. This would require another type of message ☹

The main question is whether this is a common (enough) problem to justify the check and explain it? Experiences?

---

<div class="post-metadata">

**Author:** ![mgondan1](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/mgondan1/32/803_2.png) [@mgondan1](https://swi-prolog.discourse.group/u/mgondan1)\
**Post date:** [May 15, 2022, 8:52am UTC](https://swi-prolog.discourse.group/t/singleton-warnings-multitons-warning/5392/3 "2022-05-15T08:52:23Z")

</div>

I fall into this trap from time to time. Not super often, though.

(This is why I asked the forum, to get an impression if it is relevant.)

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [May 16, 2022, 7:32pm UTC](https://swi-prolog.discourse.group/t/singleton-warnings-multitons-warning/5392/4 "2022-05-16T19:32:42Z")

</div>

I’ve made this mistake from time to time, or something similar, typically when I’m modifying existing code by adding parameters or an intermediate goal, especially for debugging. Next time I encounter it, I’ll try to remember to write down the sequence that led to the mistake. 😉
