فهرست منبع

Amélioration and et or

Arthur Brandao 6 سال پیش
والد
کامیت
3c093c1b94
1فایلهای تغییر یافته به همراه8 افزوده شده و 6 حذف شده
  1. 8 6
      src/migl/lisp/LispImpl.java

+ 8 - 6
src/migl/lisp/LispImpl.java

@@ -45,17 +45,19 @@ public class LispImpl implements Lisp {
 			return LispElement.generate(result);
 		});
 		operators.put("and", (lisp) -> {
-			if(lisp.size() != 2) {
-				throw new LispError(LispError.ERR_NUM_ARG);
+			boolean result = true;
+			while(!lisp.isEmpty()) {
+				result = result && getElement(lisp.car()).toBoolean();
+				lisp = lisp.cdr();
 			}
-			boolean result = getElement(lisp.car()).toBoolean() && getElement(lisp.cdr().car()).toBoolean();
 			return LispElement.generate(result);
 		});
 		operators.put("or", (lisp) -> {
-			if(lisp.size() != 2) {
-				throw new LispError(LispError.ERR_NUM_ARG);
+			boolean result = false;
+			while(!lisp.isEmpty()) {
+				result = result || getElement(lisp.car()).toBoolean();
+				lisp = lisp.cdr();
 			}
-			boolean result = getElement(lisp.car()).toBoolean() || getElement(lisp.cdr().car()).toBoolean();
 			return LispElement.generate(result);
 		});
 		operators.put("cons", (lisp) -> {