Return multiple values: Difference between revisions

Content added Content deleted
Line 2,657: Line 2,657:


=={{header|Plain English}}==
=={{header|Plain English}}==
Since parameters are passed by reference by default in Plain English, returning values ends up being unnecessary in most cases. The only functions that actually return a value are Boolean functions, called deciders.
Returning multiple values is natural. There are no limits to which parameters may be used for inputs and which parameters may be used for outputs. It's all the same to Plain English. You choose which slot(s) to put your return value(s) into.


It is possible, however, to call an auxiliary routine to change fields in a record and:
Notice that the outputs actually come before the inputs in this case. (You could even have the outputs overwrite the inputs if you want.) In the calling scope, <code>a product</code> and <code>a quotient</code> introduce new local variables containing the values placed into them by the routine.
<syntaxhighlight lang="plainenglish">To run:
Start up.
Compute a product and a quotient given 15 and 3.
Write "The product is " then the product on the console.
Write "The quotient is " then the quotient on the console.
Wait for the escape key.
Shut down.


# Concatenate these values, assigning the concatenated string to a new string (see code below);
A product is a number.
# Write the concatenated string on the console; or
# As is done in C style, obtain the address of the registers and save the value in a number for later manipulation.


<syntaxhighlight line="1" start="1">The example record is a record with
To compute a product and a quotient given a number and another number:
Put the number times the other number into the product.
A number called first field,
A string called second field,
Put the number divided by the other number into the quotient.</syntaxhighlight>
A flag called third field.
{{out}}
To run:
Start up.
Fill the example record.
Write the example record on the console.
Shut down.

To fill the example record:
Put 123 into the example's record's first field.
Put "Hello World!" into the example's record's second field.
Set the example's record's third field.

To Write the example record on the console:
Convert the example's example's record's first field to a string.
Convert the example's example's record's third field to another string.
Put the string then " "
then the example's record's second field
then " " then other string into a return string.
Write the return string on the console.
</syntaxhighlight>When it is necessary to get the return value of a Win 32 API function, the syntax is as follows:

''Call "dllname.dll" "FunctionNameHereIsCaseSensitive" returning a <type>.''

Example:s

''Call "gdi32.dll" "GetCurrentObject" with the printer canvas and 6 [obj_font] returning a handle.''

''Call "kernel32.dll" "SetFilePointer" with the file and 0 and 0 and 2 [file_end] returning a result number.''

''Call "kernel32.dll" "WriteFile" with the file and the buffer's first and the buffer's length and a number's whereabouts and 0 returning the result number.''

''Call "kernel32.dll" "HeapAlloc" with the heap pointer and 8 [heap_zero_memory] and the byte count returning the pointer.''{{out}}
<pre>
<pre>
123 Hello World! yes
The product is 45
The quotient is 5
</pre>
</pre>