Hecl is not a replacement for Java, and is indeed meant to work hand in hand with Java. We attempt to make it as easy as possible to call Java from Hecl, via the creation of new Hecl commands that can call Java code, in addition to calling Hecl from Java, which is a matter of a few lines of code.
import org.hecl.files.HeclFile; import org.hecl.Eval; import org.hecl.Interp; import org.hecl.Thing; import org.hecl.ListThing; import org.hecl.HeclException; ... try { /* First, create a new interpreter, and pass it a * mechanism to load resources with - in this case, * files. */ Interp interp = new Interp(); /* Add the files package */ new HeclFile().loadModule(interp); /* Evaluate the file at args[0] */ HeclFile.sourceFile(interp, args[0]); /* Evaluate some code in a string. */ String helloworld = new String("puts {Hello, world!}"); interp.eval(new Thing(helloworld)); } catch (Exception e) { System.err.println(e); }
The above code first creates a new interpreter. Next, it
instantiates the HeclFile system. This isn't part of the Hecl
core, because some systems, like J2ME, may not have files. If
you don't have files, you can still use
interp.eval
to evaluate some code,
which could come from whatever source you desire.