
'----------
'PROCEDURES
'==========

'SUBROUTINES

float v
goto ncube
cube: 'subroutine
'print v*v*v
ret
ncube:

v=3 : gosub cube


'SUBS AND FUNCTIONS
'==================

sub cube(f as float, g as float)
  g=f*f*f
end sub

dim float a
cube 2,a
'print a

function cube(f as float) as float
  function=f*f*f
end function

function cube(f as float) as float
  return f*f*f
end function

'print cube 2

'METHODS (IN CLASSES)
'====================

class multipliers
  method cube(f as float) as float
    return f*f*f
  end method
end class

dim multipliers m
'print m.cube 4

'ALTERNATIVE SYNTAX
'==================

'USE OF {..}
'===========

function cube(f as float) as float {return f*f*f}

function cube(f as float) as float {
  return f*f*f
}

float cube(f as float) {
  return f*f*f
}

float cube(float f) {
  return f*f*f
}


'print cube 2


'PASSING PARAMETERS BY REFERENCE
'===============================

dim as float f()={1,2,3,4,5}

function cubes(f as float, byval n as int) 'default byref
  indexbase 1
  int i
  for i=1 to n
    v=f[i]
    print v*v*v
  next
end function

function cubes(float*f, int n)
  indexbase 1
  float v
  int i
  for i=1 to n
    v=f[i]
    print v*v*v
  next
end function

'cubes f(2),3
'cubes f, countof(f)


'OPTIONAL PARAMETERS
'===================

function cubes(f as float, optional byval n as int)
  if n=0 then n=1
  indexbase 1
  float v
  int i
  for i=1 to n
    v=f[i]
    print v*v*v
  next
end function

'cubes f(3)
'cubes f(3),1
'cubes float{1,2,3,4},countof  'PASSING LITERAL DATA SET


'DEFAULT PARAMETERS
'==================

function cubes(float*f, int n=2)
  indexbase 1
  float v
  int i
  for i=1 to n
    v=f[i]
    print v*v*v
  next
end function

'cubes f(3)
'cubes f(3),2

'ELLIPSIS ...
'============

function cuber(int n, ...)
  indexbase 0
  float v
  int i
  for i=1 to n
    v= (int) param[i]
    print v*v*v
  next
end function

'cuber 3, 2,3,4



