<?php

define("JAVA_PREFER_VALUES", true);
require_once "java/Java.inc";
$system = new java("java.lang.System");
$t1 = $system->currentTimeMillis();
$here = getcwd();
// load scheme interpreter
// try to load local ~/lib/kawa.jar, otherwise load it from sf.net
try {
    java_require("kawa.jar");
} catch (JavaException $e) {
    java_require("http://php-java-bridge.sourceforge.net/kawa.jar");
}
$s = new java("kawa.standard.Scheme");
for ($i = 0; $i < 100; $i++) {
    $res = java_cast($s->eval("\n\n(letrec\n ((f (lambda(v)\n       (if \n\t   (= v 0)\n\t   1\n\t (*\n\t  (f\n\t   (- v 1))\n\t  v)))))\n (f {$i}))\n\n"), "D");
    if ($ex = java_last_exception_get()) {
        $res = $ex->toString();
    }
    java_last_exception_clear();
    echo "fact({$i}) ==> {$res}\n";
}
$t2 = $system->currentTimeMillis();
$delta = ($t2 - $t1) / 1000.0;
$now = new java("java.sql.Timestamp", $system->currentTimeMillis());
echo "Evaluation took {$delta} s -- at: {$now}\n";
 /**
  * Get all the groups with the specified search criteria and search Type.
  * 
  * @param object mixed $searchCriteria (original type: java.io.Serializable)
  * @param object Type $groupSearchType
  *	
  * @return object AgentIterator
  * 
  * @throws object AgentException An exception with one of the
  *		   following messages defined in org.osid.agent.AgentException may
  *		   be thrown:  {@link
  *		   org.osid.agent.AgentException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.agent.AgentException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.agent.AgentException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  *		   {@link org.osid.agent.AgentException#NULL_ARGUMENT
  *		   NULL_ARGUMENT}, {@link
  *		   org.osid.agent.AgentException#UNKNOWN_TYPE UNKNOWN_TYPE}
  * 
  * @access public
  */
 function getGroupsBySearch($searchCriteria, $groupSearchType)
 {
     $result = $this->_javaClass->getGroupsBySearch($searchCriteria, $groupSearchType);
     $ex = java_last_exception_get();
     if ($ex) {
         java_last_exception_clear();
         return $ex->toString();
     }
     java_last_exception_clear();
     return $result;
 }