= #JxnPortable/docs/programmer_examples/demos/gcd_print_Demo.jxn ...

#function gcd( a, b )  ! greatest common divisor
   print( "gcd called with: a = " + a + ", b = " + b )
!  #if gt( abs b, 1E-10 abs a )  ! possible generalization of gcd
   #if ne( b, 0 )
      #return gcd( b, a % b )  ! recursive call
   #else
      #return a
   #endif
#endfunction

print = @JxnFunction( $this, "o -> o" )
 = ( o ) -> o (JxnFunction)
print.setDebug 1  ! allow output from print
 = 0 (int)


gcd( 96, 60 )
: o
:  = gcd called with: a = 96, b = 60 (java.lang.String)
: o
:  = gcd called with: a = 60, b = 36 (java.lang.String)
: o
:  = gcd called with: a = 36, b = 24 (java.lang.String)
: o
:  = gcd called with: a = 24, b = 12 (java.lang.String)
: o
:  = gcd called with: a = 12, b = 0 (java.lang.String)
 = 12 (int)


gcd.setDebug 2
 = 0 (int)
gcd( 96, 60 )
: o
:  = gcd called with: a = 96, b = 60 (java.lang.String)
: #if ne( b, 0 )
: #return gcd( b, a % b )  ! recursive call
: o
:  = gcd called with: a = 60, b = 36 (java.lang.String)
: #if ne( b, 0 )
: #return gcd( b, a % b )  ! recursive call
: o
:  = gcd called with: a = 36, b = 24 (java.lang.String)
: #if ne( b, 0 )
: #return gcd( b, a % b )  ! recursive call
: o
:  = gcd called with: a = 24, b = 12 (java.lang.String)
: #if ne( b, 0 )
: #return gcd( b, a % b )  ! recursive call
: o
:  = gcd called with: a = 12, b = 0 (java.lang.String)
: #if ne( b, 0 )
: #else
: #return a
 = 12 (int)


! try also
! gcd( 2.5, 1.75 )  ! works for binary fraction
! gcd( 2.2, 1.7 )   ! does not work properly for decimal fractions