From f373e5ae76b025dc5ed5ec47bf37565b2c3188a2 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 10 Jul 2016 13:04:10 +0200 Subject: [PATCH] add not, if. --- scm.mes | 11 +++++++++++ test.mes | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/scm.mes b/scm.mes index e13eedc7..e9ddef52 100755 --- a/scm.mes +++ b/scm.mes @@ -64,3 +64,14 @@ ((null? r) (cons (f (car l)) (map f (cdr l)))) ((null? (cdr r)) (cons (f (car l) (caar r)) (map f (cdr l) (cdar r)))))) + +(define (not x) + (cond (x #f) + (#t #t))) + +(define-macro (if expr then . else) + (cond ((not (eq? (c:eval expr (current-module)) #f)) + then) + (#t + (cond ((pair? else) (car else)) + (#t *unspecified*))))) diff --git a/test.mes b/test.mes index 619f25a0..96a0fe23 100644 --- a/test.mes +++ b/test.mes @@ -124,4 +124,11 @@ (display (= 3 '3)) (newline) +(display (if #t 'true)) +(newline) +(display (if (eq? 0 '0) 'true 'false)) +(newline) +(display (if (= 1 2) 'true 'false)) +(newline) + '()