Further to our recent discussions, I wanted to concretise a point I was trying to make. I can see 3 different contexts in which we want to use +/-/? mode indicators:
- Descriptive mode alternatives: these are provided by the designer/implementor of a predicate; often there are several of them for one predicate, possibly with a determinism indicator; ISO uses these and requires them to be mutually exclusive. E.g.
string_code(+,+,-) is det “can be called like this...”
string_code(-,+,?) is nondet “...or like that (else error/undefined)”
- Descriptive mode summary: also provided by the designer/implementor of a predicate; only one per predicate (which can ideally be obtained by generalising from the above alternatives); the purpose is to have a compact (although imprecise) one-line description for a predicate. E.g.
string_code(?,+,?) “anything else is error/undefined”
- Mode promise: this would be provided by an application writer or by a code analyzer; one or multiple alternatives. E.g.
string_code(-,+,-) “I promise to only make calls like this”
All of these are in current use, for example
- the ISO standard uses (1) only
- Ciao declarations support (1), albeit without requiring mutual exclusivity
- SWI and SICStus use (2) in their documentation
- ECLiPSe uses (1) and (2) in its documentation, and (3) in its mode/1 declaration
- …
The ‘-’ mode
To distinguish between these contexts is helpful when discussing the various meanings of the ‘-’ mode, which Manuel documented in his draft.
-
“The argument is/shall be a variable” (ISO, GP):
This simple meaning makes sense in context (1), because it can serve to distinguish between mode alternatives (often there will be an alternative mode where the corresponding argument has ‘+’ mode). On the other hand, in context (2) and (3) this meaning is rarely useful. -
“An output argument. It may or may not be bound at call-time. If the argument is bound at call time, the goal behaves as if the argument were unbound, and then unified with that term after the goal succeeds” (SWI,ECL/doc):
This makes sense in context (2), where it describes the common case of a steadfast output argument. Such arguments would otherwise have to be described with ‘?’, and the steadfastness aspect would be lost. In contexts (1) and (3) this meaning makes no sense. -
“A free variable without any constraints, especially it must not occur in any other argument and it cannot be a suspending (or constrained) variable”. (ECL/decl):
This very strict meaning is only useful as a promise in context (3), because it enables compiler optimizations such as improved indexing, reordering unifications, determinism detection etc.
Does this sound right? If yes, one would have to decide whether it is ok to have different meanings of ‘-’ depending on context, or whether one should use 3 different symbols…