From 7d3ef19190fafe50c8b5930ae53b4e9e5b7ffe1f Mon Sep 17 00:00:00 2001 From: Masaya Tojo Date: Sat, 21 Nov 2020 04:34:39 +0900 Subject: wip29 --- vikalpa/prelude.scm | 208 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 148 insertions(+), 60 deletions(-) (limited to 'vikalpa') diff --git a/vikalpa/prelude.scm b/vikalpa/prelude.scm index 8816131..c55ea48 100644 --- a/vikalpa/prelude.scm +++ b/vikalpa/prelude.scm @@ -17,23 +17,9 @@ ;;; along with Vikalpa. If not, see . (define-module (vikalpa prelude) - #:export (atom? size implies natural? prelude) + #:export (implies prelude) #:use-module (vikalpa)) -(define (atom? x) - (not (pair? x))) - -(define (natural? x) - (and (integer? x) - (not (negative? x)))) - -(define (size x) - (if (pair? x) - (+ 1 - (size (car x)) - (size (cdr x))) - 0)) - (define-syntax implies (syntax-rules () ((_ x y) (if x y #t)) @@ -41,8 +27,16 @@ (if x (implies y z rest ...) #t)))) (define-system prelude () - (define-function atom? (x) - (not (pair? x))) + (define-primitive-function pair? (x y)) + (define-primitive-function cons (x y)) + (define-primitive-function car (x)) + (define-primitive-function cdr (x)) + (define-primitive-function sub1 (x)) + (define-primitive-function add1 (x)) + (define-primitive-function < (x y)) + (define-primitive-function natural? (x)) + (define-totality-claim natural? natural? <) + (define-syntax-rules list () ((list) '()) ((list x . y) (cons x (list . y)))) @@ -62,23 +56,23 @@ ((implies x y) (if x y #t)) ((implies x y z . rest) (if x (implies y z . rest) #t))) - + (define-axiom equal-same (x) (equal? (equal? x x) '#t)) (define-axiom equal-swap (x y) (equal? (equal? x y) (equal? y x))) (define-axiom equal-if (x y) (implies (equal? x y) (equal? x y))) - (define-axiom atom/cons (x y) - (equal? (atom? (cons x y)) '#f)) + (define-axiom pair/cons (x y) + (equal? (pair? (cons x y)) '#t)) (define-axiom car/cons (x y) (equal? (car (cons x y)) x)) (define-axiom cdr/cons (x y) (equal? (cdr (cons x y)) y)) (define-axiom cons/car+cdr (x) - (if (atom? x) - '#t - (equal? (cons (car x) (cdr x)) x))) + (if (pair? x) + (equal? (cons (car x) (cdr x)) x) + '#t)) (define-axiom if-nest (x y z) (if x (equal? (if x y z) y) @@ -89,65 +83,153 @@ (equal? (if '#f x y) y)) (define-axiom if-same (x y) (equal? (if x y y) y)) - (define-axiom natural?/size (x) - (equal? (natural? (size x)) - '#t)) - (define-axiom