Page 1 of 1

What does [out] mean?

Posted: 16 Jan 2021 1:37
by dcgreenwood
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.

Re: What does [out] mean?

Posted: 16 Jan 2021 18:22
by Harrison Pratt
[out] indicates that a value is returned from the predicate.

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.

Re: What does [out] mean?

Posted: 17 Jan 2021 0:35
by dcgreenwood
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.

Re: What does [out] mean?

Posted: 17 Jan 2021 4:00
by Harrison Pratt
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:

Code: Select all

demoPred : (integer Input , string Output) (i,o).
to this preferred form:

Code: Select all

demoPred : (integer Input, string Output [out]).
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.