-
- Posts: 24
- Joined: 16 Jan 2021 1:33
What does [out] mean?
I am learning prolog, going though the fundamentals, but I cannot find any description of what the [out] parameter is that I see in some of the example predicates.
-
- VIP Member
- Posts: 458
- Joined: 5 Nov 2000 0:01
Re: What does [out] mean?
[out] indicates that a value is returned from the predicate.
For example:
For example:
Code: Select all
class predicates
demoPred : (integer Input, string Output [out]).
clauses
demoPred(Input, OutPut) :-
if Input < 0 then
OutPut = "Negative"
elseif Input = 0 then
OutPut = "Zero"
else
OutPut = "Positive"
end if.
-
- Posts: 24
- Joined: 16 Jan 2021 1:33
Re: What does [out] mean?
Thanks. Since most examples in the fundementals don't include it and allow a term to be either input or output, I assume it is and optional declaration.
-
- VIP Member
- Posts: 458
- Joined: 5 Nov 2000 0:01
Re: What does [out] mean?
The default specification for predicate definitions is [in], so you don't need to specify that a parameter is an input.
You may be surprised to see that the IDE will change a valid definition like this:
to this preferred form:
The IDE does a nice job of standardizing code format. I would recommend you have that turned on in the Project Settings > Build Options. It makes it easier to compare your code to that of others or your own earlier code.
You may be surprised to see that the IDE will change a valid definition like this:
Code: Select all
demoPred : (integer Input , string Output) (i,o).
Code: Select all
demoPred : (integer Input, string Output [out]).