|
@@ -22,6 +22,11 @@ public class DefineOperator implements LispOperator {
|
|
|
define.clear();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Indique si un Objet est la representation d'une expression lambda
|
|
|
+ * @param elt L'objet à evaluer
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public static boolean isLambda(Object elt) {
|
|
|
if(!(elt instanceof String)) {
|
|
@@ -43,6 +48,12 @@ public class DefineOperator implements LispOperator {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Evalue un objet
|
|
|
+ * @param elt
|
|
|
+ * @return
|
|
|
+ * @throws LispError
|
|
|
+ */
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public static LispElement eval(Object elt) throws LispError {
|
|
|
if(elt instanceof ConsList) {
|
|
@@ -66,6 +77,11 @@ public class DefineOperator implements LispOperator {
|
|
|
return LispElement.generate(cl.car());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Evalue une liste
|
|
|
+ * @param lisp
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public static LispElement eval(ConsList<Object> lisp) {
|
|
|
if(lisp.car() instanceof ConsList) {
|
|
|
String res = lisp.car().toString();
|
|
@@ -86,6 +102,12 @@ public class DefineOperator implements LispOperator {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Operateur lisp define
|
|
|
+ * @param lisp
|
|
|
+ * @return
|
|
|
+ * @throws LispError
|
|
|
+ */
|
|
|
private LispElement define(ConsList<Object> lisp) throws LispError {
|
|
|
if(lisp.size() != 2) {
|
|
|
throw new LispError(LispError.ERR_NUM_ARG);
|
|
@@ -106,6 +128,12 @@ public class DefineOperator implements LispOperator {
|
|
|
return eval(lisp.cdr());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Operateur lisp set!
|
|
|
+ * @param lisp
|
|
|
+ * @return
|
|
|
+ * @throws LispError
|
|
|
+ */
|
|
|
private LispElement set(ConsList<Object> lisp) throws LispError {
|
|
|
if(lisp.size() != 2) {
|
|
|
throw new LispError(LispError.ERR_NUM_ARG);
|
|
@@ -129,6 +157,13 @@ public class DefineOperator implements LispOperator {
|
|
|
return eval(lisp.cdr());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Evalue une expression lambda
|
|
|
+ * @param operator Le nom de l'expression
|
|
|
+ * @param lisp Les parametres de l'expression
|
|
|
+ * @return La valeur de l'expression
|
|
|
+ * @throws LispError
|
|
|
+ */
|
|
|
@SuppressWarnings("unchecked")
|
|
|
private LispElement lambda(String operator, ConsList<Object> lisp) throws LispError {
|
|
|
if(!isLambda(operator)) {
|