More than one (two?) procedure return value
More than one (two?) procedure return value
It would be very useful for me if the procedure could return two values, e.g. the result of an operation and its status (error code). This possibility exists, for example, in the Golang. I know that a procedure can return more values through the objects used as arguments, but this is less convenient because I have to declare the appropriate objects first. And often the second value returned is a simple variable. I believe that this syntax would have no effect on backward compatibility, it would only extend the possibilities. So maybe we will get something like this someday, for the benefit of language development?
Re: More than one (two?) procedure return value
Pure Basic can only return a single value because it uses the RAX/EAX register for this.
There is no change to return multiple values, without changing the whole core language.
But let me ask you, how such syntax with two return values would look like in Pure Basic?
To my point of view, there is no disadvantage to use instead:
You do not need to declare an "appropriate objects first", you can use a simple variable with @
There is no change to return multiple values, without changing the whole core language.
But let me ask you, how such syntax with two return values would look like in Pure Basic?
Code: Select all
A, B = MyProcedure(C)
Code: Select all
Procedure MyProcedure(*Return.Integer, Value.i)
*Return\i = Value
ProcedureReturn #True
EndProcedure
Debug MyProcedure(@B, C)
Debug B
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: More than one (two?) procedure return value
STARGÅTE wrote:
"Pure Basic can only return a single value because it uses the RAX/EAX register for this."
With C backend in the situation changes.
It looks pretty good to me.
"To my point of view, there is no disadvantage to use instead:"
I did not know such a solution. Thanks for this example.
"Pure Basic can only return a single value because it uses the RAX/EAX register for this."
With C backend in the situation changes.
Code: Select all
A, B = MyProcedure(C)
"To my point of view, there is no disadvantage to use instead:"
I did not know such a solution. Thanks for this example.
Re: More than one (two?) procedure return value
In all languages it is always only one return value internally (rax/eax). In object-oriented languages, the return value is whether the function was successful and the result is always passed to a Result parameter as a ByRef.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: More than one (two?) procedure return value
Yes, but sometimes it's worth doing it differently than everyone else. PureBasic is a good example of this.
- NicTheQuick
- Addict
- Posts: 1227
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: More than one (two?) procedure return value
I really would like to have proper exception handling in Purebasic. I want to throw exceptions and then catching them somewhere later. It would make so much things more easy. And you could also see it as a secondary return value but of course it is more than that.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Re: More than one (two?) procedure return value
Yes to exception handling, no to multiple returns.
We have fully flexible structures and pointers to them.
Your procedures can return success or fail.
And the structures hold the stable result(s).
...If wishing...
I am more interested in functions that exist within mathematical operations.
y = myA(x().cmplx) * myB(z().cmplx)
How to handle complex math with function overloading.
See the parameter types within the call and then use the appropriate procedure.
We have fully flexible structures and pointers to them.
Your procedures can return success or fail.
And the structures hold the stable result(s).
...If wishing...
I am more interested in functions that exist within mathematical operations.
y = myA(x().cmplx) * myB(z().cmplx)
How to handle complex math with function overloading.
See the parameter types within the call and then use the appropriate procedure.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: More than one (two?) procedure return value
Code from the help file
Code: Select all
Structure TEST
s.s
x.i
EndStructure
Procedure CreateObject(x)
Protected *Res.TEST = AllocateStructure(TEST)
*Res\s = Str(x)
*Res\x = x
ProcedureReturn *Res
EndProcedure
*x1.TEST = CreateObject(1)
*x2.TEST = CreateObject(2)
*x3.TEST = CreateObject(3)
*x4.TEST = CreateObject(4)
Debug *x1\s
Debug *x1\x
Debug *x2\s
Debug *x2\x
Debug *x3\s
Debug *x3\x
Debug *x4\s
Debug *x4\x
FreeStructure(*x1)
FreeStructure(*x2)
FreeStructure(*x3)
FreeStructure(*x4)