From 5ad6b0733cec4f04d4200acef772fc75113b231f Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Sun, 7 Jul 2024 20:26:32 -0700 Subject: [PATCH] Add logic operations --- src/lisp/drawl.pla | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lisp/drawl.pla b/src/lisp/drawl.pla index 374fd6c..2dfb73c 100644 --- a/src/lisp/drawl.pla +++ b/src/lisp/drawl.pla @@ -552,6 +552,24 @@ def natv_eq(expr) return eval_pred(eval_expr(expr=>car) == eval_expr(expr=>cdr=>car)) end +def natv_not(expr) + return eval_pred(eval_expr(expr=>car) == @pred_false) +end + +def natv_and(expr) + while (expr and eval_expr(expr=>car) == @pred_true) + expr = expr=>cdr + loop + return eval_pred(!expr) +end + +def natv_or(expr) + while (expr and eval_expr(expr=>car) == @pred_false) + expr = expr=>cdr + loop + return eval_pred(expr) +end + def natv_cons(expr) var consptr @@ -748,6 +766,9 @@ def install_defaults#0 new_sym("CONS")=>natv = @natv_cons) new_sym("ATOM")=>natv = @natv_atom) new_sym("EQ")=>natv = @natv_eq) + new_sym("NOT")=>natv = @natv_not) + new_sym("AND")=>natv = @natv_and) + new_sym("OR")=>natv = @natv_or) new_sym("COND")=>natv = @natv_cond) new_sym("SET")=>natv = @natv_set) new_sym("SETQ")=>natv = @natv_setq)