Functions reads data from the Right to the Left...

BlitzMax Forums/BlitzMax Programming/Functions reads data from the Right to the Left...

Haramanai(Posted 2006) [#1]
Well I just found out this as I had trouble to load data from a stream and thought it will be good to tell to the community.
Here is the example code using a stream.
SuperStrict

Function SetLR( _L:String , _R:String)
	L = _L
	R = _R
End Function

Global L:String = "Left"
Global R:String = "Right"

Print "First L = " + L
Print "First R = " + R

'Now I save the Strings in file
Local out:TStream = WriteFile("tmp.txt")
WriteLine out , L
WriteLine out , R
CloseStream out

'now load the stream from the file and use the function to set L and R
Local in:TStream = OpenStream("tmp.txt")
SetLR( ReadLine(in) , ReadLine(in) )
Print "From the Function L = " + L
Print "From the Function R = " + R

'And now load the stream again to set them manual
in = OpenStream("tmp.txt")
L = ReadLine(in)
R = ReadLine(in)
Print "From Manual Set L = " + L
Print "From Manual Set R = " + R

CloseStream(in)
DeleteFile("tmp.txt")
End



tonyg(Posted 2006) [#2]
Isn't this readline within the call that makes the difference and not function? We *know* function works left to right. Change your manual test to..
Local in1:TStream = OpenStream("tmp.txt")
Local L1:String = ReadLine(in)
Local R1:String = ReadLine(in)
SETLR(L1,R1)
Print "From Manual Set L = " + L
Print "From Manual Set R = " + R
CloseStream(in)
DeleteFile("tmp.txt")
End

and it works as expected.

The problem seems to be calling readline within a call to a function. Print _L and _R within the function to check.


Brendane(Posted 2006) [#3]
Function parameters are evaluated right to left - it's like tonyg says.


Beaker(Posted 2006) [#4]
You should never assume any particular order of execution. It has been discussed before.