Page 1 of 1

ProcedureReturn (bis) : return more than only one parameter

Posted: Wed Aug 29, 2007 6:17 pm
by Ollivier
There is already a post explaining this option but I read it. If you aren't french, it's harder to understand it...

Actually we can't get only one returned parameter from a procedure:

Code: Select all

output = Proc(input1, input2)
But usually, the stack keeps the value of the inputs until they are overwritten after the call of the procedure.

A new command (I invent a name for example : many) should allow to get these values.

Example:Syntax 1

Code: Select all

Many(p, q, r, s) = Proc(a, b, c, d)
Or Syntax 2(syntax like 'CallFunction')

Code: Select all

Many(Proc, a, b, c, d)
Application (syntax 2 only):

Code: Select all

;{
Macro ProcReturn
! Ret 
EndMacro 

Macro Func1(p, a)
  p(a)
! Pop [v_#a#]   
EndMacro

Macro Func2(p, a, b)
  p(a, b)
! Pop [v_#a#]   
! Pop [v_#b#]   
EndMacro

Macro Func3(p, a, b, c)
  p(a, b, c)
! Pop [v_#a#]   
! Pop [v_#b#]   
! Pop [v_#c#]   
EndMacro

Macro Func4(p, a, b, c, d)
  p(a, b, c, d)
! Pop [v_#a#]   
! Pop [v_#b#]   
! Pop [v_#c#]   
! Pop [v_#d#]   
EndMacro

Macro Func5(p, a, b, c, d, e)
  p(a, b, c, d, e)
! Pop [v_#a#]   
! Pop [v_#b#]   
! Pop [v_#c#]   
! Pop [v_#d#] 
! Pop [v_#e#] 
EndMacro
;}


; *** MAIN *** 

Declare MyProcedure(a, b, c, d, e) 

Func5(MyProcedure, a, b, c, d, e)
 
Debug a 
Debug b 
Debug c 
Debug d
Debug e

Procedure MyProcedure(One, Two, Three, Four, Five) 
  One = 111
  Two = 222
  Three = 333
  Four = 444
  Five = 555
  ProcReturn ; << /!\
EndProcedure
Reading this code, I think Fred could understand, in one kind, the simplicity to add such a function, and, in an other kind, my difficulty to create only one good macro respecting the syntax number one or a better syntax! :D

I know there's structures to answer such a problem but it could be a very good and simple solution.

Posted: Thu Aug 30, 2007 3:39 pm
by ZeHa
Well some languages have a "tuple" as a data type. This would be maybe a good concept to implement...

Posted: Thu Aug 30, 2007 3:47 pm
by Kale
ZeHa wrote:Well some languages have a "tuple" as a data type. This would be maybe a good concept to implement...
The trouble is that tuples (to me) denote a list containing untyped elements. Which is probably hard to implement in a strongly typed non-oop language. If such a thing was implemented then it would probably use pointers as the elements of the tuple. So you may as well use a long/pointer array instead?

Posted: Thu Aug 30, 2007 5:33 pm
by Kaeru Gaman
note that you can interprete e.g. a Long return-type as a COORD-structure containing two Word Coordinates.

so, you can put a return value of maximum 64bit (quad) into any desired structure of max 64bit.
you can return 8 values in one, if the 8 are bytes only.

Posted: Thu Aug 30, 2007 5:39 pm
by ts-soft
IMHO the best is to use PointerParameter (byref) for this and
ProcedureReturn only for Errorflag :wink: