Lisp for Java Users: Eval Expression
An interpreter that only lets us process expressions with variables won't do much good!
We need something to express statements, loops, functions, definitions and everything else
that goes into a programming language. This should be enough.
public Object eval (final Object expression) throws Exception
if (expression instanceof Symbol)
return evalSymbol ((Symbol)expression);
if (expression instanceof List<?>)
final List<?> form = (List<?>)expression;
return evalExpression (form);
private Object evalExpression (final List<?> form) throws Exception
final Symbol function = (Symbol)form.get (0);
final FunctionCell functionCell = function.getFunctionCell ();
if (functionCell == null)
throw new Error ("Illegal function " + form.get (0));
return functionCell.evalExpression (this, form);
That's not much more. Actually most readers will notice that the FunctionCell is not defined.