An experimental wrapper around bits of LFE
This project is 1100100% experimentation.
Its sole purpose is to explore the possibility of slightly increasing programmer convenience when using LFE on Erjang (Erlang on the JVM).
Initially, chunks of LFE code were copied, but the latest version requires that one manually make a single change to a function (instructions below), and then does the rest in the jlfe code.
Development Information
This project assumes that you have lfetool installed somwhere in your
$PATH
. Also, we're not going to cover the installation of Java -- you
will need Java installed on your system in order to run jlfe ;-)
This project depends upon the following, which are saved to ./deps
when
you run make get-deps
:
- LFE (Lisp Flavored Erlang; needed only to compile)
- lfeunit (needed only to run the unit tests)
- lfe-utils
Dependencies not installed automatically:
- lfetool (click the link for installation instructions)
- kerl (see below)
- Erjang (see below)
- rlwrap (
readline
support for the Erjang shell; installable on many linux distros; on Mac OS X, install with Homebrew)
If you don't have rebar
, kerl
and Erlang installed:
$ lfetool install rebar
$ lfetool install kerl
$ lfetool install erlang R16B
$ . /opt/erlang/R16B/activate
Erjang installation is similarly easy:
$ lfetool install erjang
Building jlfe and its dependencies is as easy as this:
$ git clone https://github.com/oubiwann/jlfe.git
$ cd jlfe
$ make compile
That last make
target will do the following:
- Download all the project dependencies,
- Apply a patch to LFE to accept the jlfe form
(.XXX ...)
, and - Compile all the dependencies, the patched LFE, and jlfe.
With everything built, you're now ready to play. To run the examples below, start the jlfe REPL:
$ lfetool repl jlfe
> (.java.util.HashMap)
()
>
> (.java.lang.Double 42)
42.0
Or you can use the short-cut for all java.lang.*
classes:
> (.Double 42)
42.0
> (.java.lang.String:getName)
java.lang.String
or
> (.String:getName)
java.lang.String
>
> (.Math:sin 0.5)
0.479425538604203
e.g., constants:
> (.Math:PI)
3.141592653589793
>
> (.java.math.BigDecimal:ROUND_CEILING)
2
> (.java.util.AbstractMap$SimpleEntry "a" "b")
#B()
Some Java types from Erjang don't render anything useful when evaluated:
> (set bool (.Boolean true))
#B()
> (set flt (.Float 42))
#B()
> (set bigdec (.java.math.BigDecimal 42))
#B()
The value-of
function lets us treat Java objects as distinct values
while still keeping the object around, should we want to call any methods on
it, etc.:
> (jlfe-types:value-of bool)
true
> (jlfe-types:value-of flt)
42.0
> (jlfe-types:value-of bigdec)
42.0
Types that don't need special treatment are passed through, as-is:
> (jlfe-types:value-of (.Integer 42))
42