How to resolve the algorithm Return multiple values step by step in the Picat programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Return multiple values step by step in the Picat programming language

Table of Contents

Problem Statement

Show how to return more than one value from a function.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Return multiple values step by step in the Picat programming language

Source code in the picat programming language

main =>
  [A,B,C] = fun(10),
  println([A,B,C]).

fun(N) = [2*N-1,2*N,2*N+1].

main => 
  pred(10, E,F,G),
  % ...

% A, B, and C are output variables
pred(N, A,B,C) =>
  A=2*N-1,
  B=2*N,
  C=2*N+1.

main =>   
  pred2(10, Ret),
  println(Ret),
  % or
  pred2(10,$ret(H,I,J)),
  println([H,I,J]).

% The structure $ret(A,B,C) contains the output values.
pred2(N, ret(A,B,C)) :-
  A=2*N-1,
  B=2*N,
  C=2*N+1.

  

You may also check:How to resolve the algorithm Runtime evaluation/In an environment step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Mutex step by step in the Wren programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the Ada programming language
You may also check:How to resolve the algorithm Evaluate binomial coefficients step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm String concatenation step by step in the jq programming language