how are variables passed from functions?

Jacques Hausser jacques.hausser at unil.ch
Fri Nov 14 04:49:37 EST 2014


Interesting. If I modify foo1 like that:

function foo1
   put foo2() into myvar2
   put "anotherTest" into myvar3
end foo1

the process still returns “Test”.

I can only guess that ‘return’ saves the returned value in a  ‘last in, first out’ pile somewhere and that the top value is used by the calling script(s) as long as a new one is not put on the pile by another ‘return’… the pile being cleared only at iddle time.

Just a guess.


> Le 14 nov. 2014 à 09:47, Tiemo Hollmann TB <toolbook at kestner.de> a écrit :
> 
> By accident I noticed that I don't have a return at a certain point of a
> function but nevertheless the value was passed back without a return to the
> calling handler.
> 
> I can reproduce the issue to this scenario:
> 
> 
> 
> --Btn script
> 
> on mouseUp
> 
>    put foo1() into myVar1 -- I get the value "Test"           
> 
> end mouseUp
> 
> 
> 
> --script in stack
> 
> function foo1
> 
>   put foo2() into myVar2 -- no return in this function
> 
> end foo1
> 
> 
> 
> function foo2
> 
>   return "Test" -- return here in second level
> 
> end foo2
> 
> 
> 
> Up to now I thought that every function has to have a return statement if
> you want anything getting back.
> 
> Can somebody explain to me what is going on here? How is the value from
> function foo2 passed back to the mouseup handler, even with different var
> names?
> 
> Is this a bug or just an accident or even wanted?
> 
> Thanks for enlightening
> 
> Tiemo
> 
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

******************************************
Prof. Jacques Hausser
Department of Ecology and Evolution
Biophore / Sorge
University of Lausanne
CH 1015 Lausanne
please use my private address:
6 route de Burtigny
CH-1269 Bassins
tel: 	++ 41 22 366 19 40
mobile:	++ 41 79 757 05 24
E-Mail:	jacques.hausser at unil.ch
*******************************************





More information about the use-livecode mailing list