From: Timothy H. <tim...@ma...> - 2002-05-31 00:46:16
|
Hi Paul, Here is a Java version, but it assumes that you have jscheme.jar on the classpath.... Object foo = JS.eval("(lambda(n) (lambda(i) (set! n (+ n i))))"); There are two possible reasons that I see for this not qualifying as a valid example: 1) it assumes a library (which would make add about 100K characters to the solution) 2) it interprets numbers as Java numbers and addition as Java addition (but perhaps you want to modify your statement to be more precise about what what you mean by number and increment!) Cheers, ---Tim--- Here is the test code for this function, /* Foo.java */ import jscheme.JS; import jscheme.SchemeProcedure; public class Foo { private static Object foo = JS.eval("(lambda(n) (lambda(i) (set! n (+ n i))))"); /* call Scheme object with an integer parameter */ private static Object FN(Object F, Object N) {return JS.call((SchemeProcedure)F,N);} public static void main(String[] args) { Object x = FN(foo,new Integer("355113")); System.out.println(FN(x,new Double("0.00001"))); System.out.println(FN(x,new Long("100000000000000"))); System.out.println(FN(x,new Byte("12"))); } } and here is the output of running the test program. tim% java -cp jscheme.jar:. Foo 355113.00001 1.00000000355113E14 1.00000000355125E14 tim% On Thursday, May 30, 2002, at 12:31 PM, Paul Graham wrote: > Since I put Revenge of the Nerds online, a number of people > have sent me implementations of the accumulator generator > benchmark in other languages. I've collected these all > together on their own page for comparison: > > http://www.paulgraham.com/accgen.html > > If you know how to write this program in some other language > that I don't have listed, please send it to me. > > (Though this seems obvious, try to be sure first that the > code actually solves the problem. Many of the implementations > I've been sent have been broken or incomplete.) > > Thanks! > > --pg > |