# Some clarifications for "mode indicators" needed

**URL:** <https://swi-prolog.discourse.group/t/some-clarifications-for-mode-indicators-needed/3340>\
**Category:** Discussion\
**Tags:** discussion\
**Created:** [December 4, 2020, 8:48pm UTC](https://swi-prolog.discourse.group/t/some-clarifications-for-mode-indicators-needed/3340 "2020-12-04T20:48:37Z")\
**Posts on this page:** 2\
**Page:** 1

<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:** [December 4, 2020, 8:48pm UTC](https://swi-prolog.discourse.group/t/some-clarifications-for-mode-indicators-needed/3340/1 "2020-12-04T20:48:37Z")

</div>

I’m going through the list of “mode indicators” again:

> **[SWI-Prolog -- Manual](https://eu.swi-prolog.org/pldoc/man?section=preddesc)**

And created a little cheatsheet:

 ![mode indicators](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/f/fc983fc7d979ca9934839daafe970239eb0ea74a.png)

… and have a few question, which should be easy to answer (cough):

* * *

**Q1**

Currently the text (which I remember to have partially written myself, so any errors extant are mine) says: “partial term (a term which may or may not be ground)”.

Is this true? Are all of `_`, `[a|X]` and `[a,b]` considered _partial terms_?

* * *

**Q2**

I never got that I am not supposed to pass an unbound variable at parameter positions marked with a `+` (that’s so, right?)

But I _can_ pass open lists, still?

For example, for `foldl(:Goal, +List, +V0, -V)`, an unbound variable at `List` position is a not supported (although it _does_ work)

```prolog
?-
foldl([E,FL,x]>>true,X,start,Final).
X = [],
Final = start ;
X = [_6450],
Final = x ;
X = [_6450, _11086],
Final = x 

```

but an open list is still ok? It _is_ a special kind of nonground term (and so is an open tree or open graph) and the _empty open list_ is just an unbound variable and indistinguishable from any other domain. So maybe `+` also means that open lists are disallowed, too, to keep the domains apart?

```prolog
?-
foldl([E,FL,x]>>true,[a,b|X],start,Final).
X = [],
Final = x ;
X = [_8596],
Final = x ;
X = [_8596, _9992],
Final = x ;
X = [_8596, _9992, _11388],
Final = x 

```

Here is another thought:

`foldl(:Goal, +List, +V0, -V)`

… should not have any opinion on the mode of `V0` and `V` because the mode of these depends on `Goal`. They could be anything (this is where the type expression in Haskell gets complex I imagine?)

* * *

**Q3**

Somewhat related, the mode indicators for [`is_list/2`](https://eu.swi-prolog.org/pldoc/doc_for?object=is_list/1) is

`is_list(+Term)`.

I do think this should be `is_list(@Term)`?

---

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [December 5, 2020, 6:51am UTC](https://swi-prolog.discourse.group/t/some-clarifications-for-mode-indicators-needed/3340/2 "2020-12-05T06:51:45Z")

</div>

Disclaimer: the usual disclaimers apply.

Could it be that you are overthinking this? Remember that the mode indicators, in SWI-Prolog, are only for documentation purposes, with all the ambiguity and edge cases that follow.

> [@dtonhofer](#):
>
> Are all of `_` , `[a|X]` and `[a,b]` considered _partial terms_ ?

**A1** : when you talk about argument instantiation, a _partially bound term_ is **not** fully instantiated because it has free variables in it. This would mean that `[a,b]` is not partially instantiated; it is fully instantiated.

**A2** : The plus signifies that the predicate is meant to be used with an argument that has _some_ type or shape, _usually_. This is because that shape of the input argument is part of the algorithm that the predicate implements.

The `foldl` example is interesting, because it exposes one of the many weaknesses of the mode indicators (margin note: those weaknesses are probably somewhat understood, since the mode indicators are only used to communicate intent from one programmer to another…).

In the `foldl` case, the implementation of _Goal_ in the first argument might take the shape of any of its arguments and use that to supply shape to any other argument. One demonstration is this example of converting a list of goals to a conjunction from the material hiding in the [“see also”](http://www.cs.otago.ac.nz/staffpriv/ok/pllib.htm) at the top of the [docs for library(apply)](https://eu.swiprolog.org/pldoc/man?section=apply).

```prolog
flip_conj(Goal, (Goal,Conj), Conj).

?- foldl(flip_conj, [p,q,r], Conj, true).
=> Conj = (p, q, r, true).

```

(this is somewhere in the middle there)

So basically the only shape in the _Goal_ is in the second argument, and in the `foldl` invocation the third argument is actually the “output”. But this is fine.

**A3** : It seems this should indeed be changed to `is_list(@Term)`. I wonder if the `+` there isn’t just an artifact of an earlier implementation of `is_list/1`.

* * *

This topic is very closely related to how you talk about determinism in the docs. I don’t think the language in the docs strictly follows something like [RFC 2119](https://tools.ietf.org/html/rfc2119), and again, this is fine. When I read MUST, I understand “When I implemented this predicate, I did not put unnecessary effort in figuring out what might happen if you do otherwise”. And this is also fine. For example, `partition/5` says “_Pred_ must be deterministic”, but you can ignore this MUST and still get what you asked for:

```prolog
any_place(_, <).
any_place(_, =).
any_place(_, >).

?- partition(any_place, [x], Less, Equal, Greater).
Less = [x],
Equal = Greater, Greater = [] ;
Less = Greater, Greater = [],
Equal = [x] ;
Less = Equal, Equal = [],
Greater = [x].

```
