BCX Console Demonstration Program s150.bas

 ' -------------------------------------------------------------- 
 ' BCX version 3.41 brought FUNCTION and SUB pointers to BCX 
 ' Wayne Halsdorf demonstrates how they work in the sample below 
 ' -------------------------------------------------------------- 
 
 DIM x AS DOUBLE
 DIM y AS DOUBLE
 DIM pf(a AS DOUBLE, b AS DOUBLE) AS FUNCTION DOUBLE
 
 x = 1.23
 y = 1.67
 pf = GeometricMean
 CALL Test
 
 pf = Average
 CALL Test
 
 SUB Test
   DIM z AS DOUBLE
   z = pf(x, y)
   ?  z
 END SUB
 
 FUNCTION GeometricMean(a AS DOUBLE, b AS DOUBLE) AS DOUBLE
   FUNCTION = SQRT(a * b)
 END FUNCTION
 
 FUNCTION Average(a AS DOUBLE, b AS DOUBLE) AS DOUBLE
   FUNCTION = (a + b) / 2
 END FUNCTION

Result:


  1.43321317325791
  1.45