[futurebasic] Re: [FB] Function functionality

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 2011 : Group Archive : Group : All Groups

From: Bernie <fblist.bw@...>
Date: Tue, 10 May 2011 12:17:58 +0100
> '-----------------------
> toolbox fn atan2( double y, double x ) = double
> toolbox fn hypot( double x, double y ) = double
> 
> local fn XYToPolar( x as double, y as double, r as ^double, theta as ^double )
> r.0#     = fn hypot( x, y )
> theta.0# = fn atan2( y, x )
> end fn
> 
> local fn PolarToXY( r as double, theta as double, x as ^double, y as ^double )
> x.0# = r*cos( theta )
> y.0# = r*sin( theta )
> end fn
> '--------------------------

Not suggesting this as an alternative to the above but just curious if it is now safe to return a record from a function. I seem to remember that it was not recommended in FB4 (stale values).
'---------------
begin record MyStruct
dim as double x, y
end record

local fn PolarToXY( r as double, theta as double ) as MyStruct
dim as MyStruct st
st.x = r*cos( theta )
st.y = r*sin( theta )
end fn = st

dim as MyStruct st

st = fn PolarToXY( 24.0, pi/4 )
print st.x,st.y
'---------------

Bernie