|
@@ -62,7 +62,31 @@ public class LispImpl implements Lisp {
|
|
|
if(lisp.size() != 2) {
|
|
|
throw new LispError(LispError.ERR_NUM_ARG);
|
|
|
}
|
|
|
- return null;
|
|
|
+ ConsList<Object> cl;
|
|
|
+ if(lisp.cdr().car() instanceof ConsList) {
|
|
|
+ //Recup + evaluation de la liste
|
|
|
+ cl = (ConsList<Object>) lisp.cdr().car();
|
|
|
+ cl = ConsListFactory.parse(evaluateList(cl).toString());
|
|
|
+ //Ajoute la valeur de gauche devant
|
|
|
+ if(lisp.car() instanceof ConsList) {
|
|
|
+ //Si la valeur gauche est aussi une liste on evalue sa valaue
|
|
|
+ ConsList<Object> cltemp = (ConsList<Object>) lisp.car();
|
|
|
+ cl = cl.prepend(evaluateList(cltemp).value);
|
|
|
+ } else {
|
|
|
+ cl = cl.prepend(lisp.car());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ LispElement le;
|
|
|
+ if(lisp.car() instanceof ConsList) {
|
|
|
+ //Si l'element est une liste on evalue sa valeur
|
|
|
+ ConsList<Object> cltemp = (ConsList<Object>) lisp.car();
|
|
|
+ le = evaluateList(cltemp);
|
|
|
+ } else {
|
|
|
+ le = LispElement.generate(lisp.car());
|
|
|
+ }
|
|
|
+ cl = ConsListFactory.asList(le + " . " + lisp.cdr().car());
|
|
|
+ }
|
|
|
+ return LispElement.generate(cl.toString());
|
|
|
});
|
|
|
operators.put(">", (lisp) -> {
|
|
|
if(lisp.size() == 0) {
|
|
@@ -404,6 +428,9 @@ public class LispImpl implements Lisp {
|
|
|
* @throws LispError
|
|
|
*/
|
|
|
private static LispElement evaluateList(ConsList<Object> lisp) throws LispError {
|
|
|
+ if(lisp.isEmpty()) {
|
|
|
+ return LispElement.generate("()");
|
|
|
+ }
|
|
|
LispOperator op = operators.get(LispElement.generate(lisp.car()).toStr());
|
|
|
if(op == null) {
|
|
|
throw new LispError(new UnsupportedOperationException("Unknow expression"));
|