I've now had the chance to test your latest ErsatzLisp, on a Linux
machine. When I tried "(data @)" in your Example below, I got "data --
Undefined". Did you change something lately? Will this 'java' function
be documented somewhere? ;-)
Do you now if it would be possible, or easy, to build a simple HTTP
server in ErsatzLisp? Or, maybe a better solution would be to combine
ErsatzLisp with a standard HTTP server. Maybe a combination of
ErsatzLisp and the Play framework (www.playframework.org) could be
On 04-11-10 19:53 , Alexander Burger wrote:
here is an update.
Besides the basic I/O system and half-baked network functions (until now
only 'connect', 'accept' and a partial 'port'), we have now a set of
functions interfacing to the Java Reflection API.
I'd like to describe them shortly, and hear your opinions. You can try
it if you like if you download the current testing release.
The central function is called 'java'. It comes in three forms:
(java 'cls 'T 'any ..) -> obj
This is a constructor call, returning a Java object. 'cls' is the
name of a Java class, like "java.lang.StringBuilder".
(java 'cls 'msg 'any ..) -> obj
This calls a static method 'msg' for a class 'cls'.
(java 'obj 'msg 'any ..) -> obj
This calls a dynamic method 'msg' for an object 'obj'
: (setq Sb (java "java.lang.StringBuilder" T "abc"))
: (java Sb "append" (char: 44))
: (java Sb "append" 123)
: (java Sb "toString")
: (data @)
The function 'data' in the last line converts back from Java objects to
Then we have 'public', it supports two forms:
(public 'obj 'any) -> obj
Returns the value of a public field 'any' in object 'obj'
(public 'cls 'any) -> obj
Returns the value of a public field 'any' in class 'cls'
: (public "java.lang.System" "err")
: (java @ "println" "Hello world")
Finally, we have a set of type conversion functions, to produce Java
objects from Lisp data:
(byte: 'num|sym) -> obj
(char: 'num|sym) -> obj
(int: 'num) -> obj
(long: 'num) -> obj
(big: 'num) -> obj
We saw the usage of 'char:' in the StringBuilder example above.
So the 'any' arguments to the 'java' function can either be
- 'T' or 'NIL', then the type is boolean
- A number, then it must fit in 32 bits and will be passed as 'int'
- A normal symbol, then it will be passed as 'String'
- A Java object, as returned by 'java' or one of the 'xxx:'
- A list, then all elements must be of the same type and will be
passed as 'Array'
I hope this reflection interface is a good compromise between simplicity