Return multiple values: Difference between revisions

add BLC solution
imported>Tromp
(add BLC solution)
 
(7 intermediate revisions by 5 users not shown)
Line 467:
150 LET C=A+B:LET D=A-B
160 END DEF</syntaxhighlight>
==={{header|uBasic/4tH}}===
{{Trans|Forth}}
uBasic/4tH shares many features with Forth - like a stack. Parameters of functions and procedures are passed through this stack, so there is no difference between pushing the values on the stack ''or'' passing them as function parameters. Return values are passed by the stack as well, so if we push additional values ''before'' calling '''RETURN''' we can retrieve them using '''POP()'''.
<syntaxhighlight lang="eulerqbasic">a = FUNC (_MulDiv (33, 11))
b = Pop()
 
Print "a * b = ";a, "a / b = ";b
 
Push 33, 11 : Proc _MulDiv
a = Pop() : b = Pop()
 
Print "a * b = ";a, "a / b = ";b
End
 
_MulDiv
Param (2)
 
Push a@ / b@
Return (a@ * b@)</syntaxhighlight>
{{Out}}
<pre>a * b = 363 a / b = 3
a * b = 363 a / b = 3
 
0 OK, 0:226 </pre>
 
=={{header|Binary Lambda Calculus}}==
In the lambda calculus, one can return a tuple, which when applied to a function f, applies f to all the tuple elements. For example, <A,B,C> is <code>\f.f A B C</code>. Alternatively, one can use continuation-passing-style (cps), in which the function f is not applied the tuple return value, but instead is passed as an extra initial argument, and then the function can return f applied to the multiple values.
 
=={{header|BQN}}==
Line 550 ⟶ 577:
 
=={{header|C sharp|C#}}==
The preferred way to return multiple values in C# is to use "out" paremetersparameters on the method. This can be in addition to the value returned by the method.
<syntaxhighlight lang="c sharp">using System;
using System.Collections.Generic;
Line 1,002 ⟶ 1,029:
 
=={{header|Elena}}==
ELENA 56.0x :
<syntaxhighlight lang="elena">import system'routines;
import extensions;
Line 1,024 ⟶ 1,051:
console.printLine("Min: ",min," Max: ",max)
}</syntaxhighlight>
=== Using Tuples syntax ===
<syntaxhighlight lang="elena">import system'routines;
import extensions;
extension op
{
::(int, int) MinMax()
{
var ordered := self.ascendant();
^ (ordered.FirstMember, ordered.LastMember);
}
}
public program()
{
var values := new int[]{4, 51, 1, -3, 3, 6, 8, 26, 2, 4};
(int min, int max) := values.MinMax();
console.printLine("Min: ",min," Max: ",max)
}</syntaxhighlight>
{{out}}
Line 1,085 ⟶ 1,134:
<br>
Lists are constructed by placing the values between ( and ). Once assigned to a variable, the list can be subscripted to access the individual elements (which can themselves be lists).
'''begin'''
<syntaxhighlight lang="euler">
'''new''' mv; '''new''' getMV;
begin
new mv; new getMV;
getMV <&lt;- ` '''formal''' v; ( v, v * v, v * v * v ) '&apos;;
 
getMV <- ` formal v; ( v, v * v, v * v * v ) ';
mv <&lt;- getMV( 3 );
 
mv <- getMV( 3 );
'''out''' mv[ 31 ];
 
'''out''' mv[ 12 ];
'''out''' mv[ 23 ];
'''end''' $
out mv[ 3 ]
end $
</syntaxhighlight>
 
=={{header|Euphoria}}==
Line 3,387 ⟶ 3,434:
=={{header|Wren}}==
In Wren, one would return multiple values from a function or method by using some sort of Sequence object, usually a List though a Map could be used if you needed ''named'' returns.
<syntaxhighlight lang="ecmascriptwren">var splitName = Fn.new { |fullName| fullName.split(" ") }
 
var names = splitName.call("George Bernard Shaw")
Anonymous user