Discussions related to Visual Prolog
dcgreenwood
Posts: 24
Joined: 16 Jan 2021 1:33

What does [out] mean?

Unread post 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.
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Re: What does [out] mean?

Unread post 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.
dcgreenwood
Posts: 24
Joined: 16 Jan 2021 1:33

Re: What does [out] mean?

Unread post 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.
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Re: What does [out] mean?

Unread post 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.
Post Reply