From: Ken A. <kan...@bb...> - 2003-10-17 15:17:10
|
Bottom Secret (Don't tell managment) At the International Lisp Conference, http://www.international-lisp-conference.org/ there was a nice presentation about Linj a Lisp to Java compiler. The code is not available yet, but there is a nice tutorial: http://www.evaluator.pt/downloads/tutorial.html One of the goals is to make human readable Java code, so your clients can't tell that you're not programming in Java (though some suspect that something strange is going on). So, for example, this Common Lisp code: (defun fact (n) (if (= n 0) 1 (* n (fact (1- n))))) (defun main () (dotimes (i 6) (let ((n (* i 10))) (format t "(fact ~A) -> ~A~%" n (fact n))))) compiles to this Java code: import linj.Bignum; public class Factorial extends Object { public static Bignum fact(Bignum n) { if (n.compareTo(Bignum.valueOf(0)) == 0) { return Bignum.valueOf(1); } else { return n.multiply(fact(n.subtract(Bignum.valueOf(1)))); } } public static void main(String[] outsideArgs) { for (int i = 0; i < 6; ++i) { int n = i * 10; System.out.print("(fact "); System.out.print(n); System.out.print(") -> "); System.out.println(fact(Bignum.valueOf(n))); } } } Notice the nice type inference! You can add type declarations like this: (defun fact (n/int) (if (= n 0) 1L (* n (fact (1- n))))) One of the real powers of this is that you can define a minilanguage in Lisp macros and have Linj generate Java code for you! You can even put a comment in Java code that Linj will transform into Java code. I can even imagine writing the JScheme primitives in Linj and maybe even a JScheme compiler and ... k |