Menu

[r665]: / branches / sparc-64-test / php-java-bridge / scheme-demo.php  Maximize  Restore  History

Download this file

38 lines (33 with data), 874 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
if (!extension_loaded('java')) {
echo "Please permanently activate the extension. Loading java extension now...\n";
if (!dl('java.so')&&!dl('java.dll')) {
echo "java extension not installed.";
exit;
}
}
$system = new java("java.lang.System");
$t1=$system->currentTimeMillis();
java_set_jar_library_path("http://www.pagesmiths.com/kawa/kawa-20021212.jar"); //load scheme interpreter
$s = new java("kawa.standard.Scheme");
for($i=0; $i<100; $i++) {
$res=$s->eval("
(letrec
((f (lambda(v)
(if
(= v 0)
1
(*
(f
(- v 1))
v)))))
(f $i))
");
if($ex=java_last_exception_get()) $res=$ex->toString();
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->toString() . "\n";
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.