boot: Add tests.

* scaffold/boot/2h-recurse-twice.scm: New file.
* scaffold/boot/2h-recurse-twice-cond.scm: New file.
* scaffold/boot/4c-quasiquote.scm: Update.
* build-aux/check-boot.sh: Add them.
This commit is contained in:
Jan Nieuwenhuizen 2018-10-16 16:36:22 +02:00
parent 684199d107
commit c88529c625
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
5 changed files with 94 additions and 84 deletions

View File

@ -75,6 +75,8 @@ tests="
2f-define-second.scm
2f-define-second-lambda.scm
2g-vector.scm
2h-recurse-twice.scm
2h-recurse-twice-cond.scm
30-capture.scm
31-capture-define.scm
@ -101,10 +103,10 @@ tests="
49-macro-override.scm
4a-define-macro-define-macro.scm
4b-define-macro-define.scm
4f-string-split.scm
4c-quasiquote.scm
4d-let-map.scm
4e-let-global.scm
4f-string-split.scm
50-primitive-load.scm
51-module.scm

View File

@ -0,0 +1,50 @@
;;; GNU Mes --- Maxwell Equations of Software
;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;;
;;; This file is part of GNU Mes.
;;;
;;; GNU Mes is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Mes is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
(define display core:display)
(define (newline) (core:display "\n"))
(define (pair? x) (eq? (core:type x) <cell:pair>))
(define (not x) (if x #f #t))
(define-macro (cond . clauses)
(list 'if (pair? clauses)
(list (cons
'lambda
(cons
'(test)
(list (list 'if 'test
(if (pair? (cdr (car clauses)))
(if (eq? (car (cdr (car clauses))) '=>)
(append2 (cdr (cdr (car clauses))) '(test))
(list (cons 'lambda (cons '() (cons 'test (cdr (car clauses)))))))
(list (cons 'lambda (cons '() (cons 'test (cdr (car clauses)))))))
(if (pair? (cdr clauses))
(cons 'cond (cdr clauses)))))))
(car (car clauses)))))
(define (f x)
(display "x=") (display x) (newline)
(cond ((not (pair? x)) 'dun)
(#t
((lambda (h t)
(list h t))
(f (car x))
(f (cdr x))))))
(display (f '(42)))
(newline)

View File

@ -0,0 +1,33 @@
;;; GNU Mes --- Maxwell Equations of Software
;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;;
;;; This file is part of GNU Mes.
;;;
;;; GNU Mes is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Mes is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
(define display core:display)
(define (newline) (core:display "\n"))
(define (pair? x) (eq? (core:type x) <cell:pair>))
(define (not x) (if x #f #t))
(define (f x)
(display "x=") (display x) (newline)
(if (not (pair? x)) 'dun
((lambda (h t)
(list h t))
(f (car x))
(f (cdr x)))))
(display (f '(42)))
(newline)

View File

@ -55,51 +55,6 @@
(if (eq? x (car lst)) lst
(memq x (cdr lst)))))
;; (define (quasiquote-expand x)
;; (core:display "quasiquote-expand x=") (core:display x) (core:display "\n")
;; (cond ((null? x)
;; (core:display "NULL\n")
;; '())
;; ((vector? x)
;; (core:display "vector\n")
;; (list 'list->vector (quasiquote-expand (vector->list x))))
;; ((not (pair? x))
;; (core:display "NOT a pair\n")
;; (cons 'quote (cons x '())))
;; ((eq? (car x) 'quasiquote) (quasiquote-expand (quasiquote-expand
;; (if (null? (cddr x)) (cadr x)
;; (cons 'list (cdr x))))))
;; ((eq? (car x) 'unquote) (if (null? (cddr x)) (cadr x)
;; (cons 'list (cdr x))))
;; ((and (pair? (car x)) (eq? (caar x) 'unquote-splicing))
;; ((lambda (d)
;; (if (null? (cddar x)) (list 'append (cadar x) d)
;; (list 'quote (append (cdar x) d))))
;; (quasiquote-expand (cdr x))))
;; (else
;; (core:display "ELSje\n")
;; (core:display "CAR x=") (core:display (car x))
;; (core:display "\n")
;; (core:display "CDR x=") (core:display (cdr x))
;; (core:display "\n")
;; ((lambda (a d)
;; (core:display " a=") (core:display a) (core:display "\n")
;; (core:display " d=") (core:display d)
;; (if (pair? d)
;; (if (eq? (car d) 'quote)
;; (if (and (pair? a) (eq? (car a) 'quote))
;; (list 'quote (cons (cadr a) (cadr d)))
;; (if (null? (cadr d))
;; (list 'list a)
;; (list 'cons* a d)))
;; (if (memq (car d) '(list cons*))
;; (cons (car d) (cons a (cdr d)))
;; (list 'cons* a d)))
;; (list 'cons* a d)))
;; (quasiquote-expand (car x))
;; (list 'quasiquote-expand (list 'cdr x))))))
(define (caar x) (car (car x)))
(define (cadr x) (car (cdr x)))
(define (cdar x) (cdr (car x)))
@ -111,7 +66,8 @@
(define (quasiquote-expand x)
(core:display "quasiquote-expand x=") (core:display x) (core:display "\n")
(cond ((vector? x) (list 'list->vector (quasiquote-expand (vector->list x))))
((not (pair? x)) (cons 'quote (cons x '())))
((not (pair? x))
(core:display "not pair!\n") (cons 'quote (cons x '())))
((eq? (car x) 'quasiquote) (quasiquote-expand (quasiquote-expand
(if (null? (cddr x)) (cadr x)
(cons 'list (cdr x))))))
@ -124,16 +80,17 @@
(quasiquote-expand (cdr x))))
(else
(core:display "ELSje\n")
(core:display "x=") (core:display x) (core:display "\n")
(core:display "CAR x=") (core:display (car x))
(core:display "\n")
(core:display "CDR x=") (core:display (cdr x))
(core:display "\n")
((lambda (a d)
(core:display "CAR a=") (core:display a)
(core:display "a=") (core:display a)
(core:display "\n")
(core:display "CDR d=") (core:display d)
(core:display "d=") (core:display d)
(core:display "\n")
(if (pair? d)
(if (eq? (car d) 'quote)
(if (and (pair? a) (eq? (car a) 'quote))
@ -146,17 +103,7 @@
(list 'cons* a d)))
(list 'cons* a d)))
(quasiquote-expand (car x))
(quasiquote-expand (cdr x))
))))
(quasiquote-expand (cdr x))))))
(define-macro (quasiquote x)
(quasiquote-expand x))
;; (define (remainder x y)
;; (- x (* (/ x y) y)))
;; (define (even? x)
;; (eq? 0 (remainder x v2)))
;; (pass-if-equal "qq 4" '#(10 5 #t #t #f #f #f 8)
;; `#(10 5 ,(even? 4) ,@(map even? '(2 3 5 7)) 8))
;;(core:display (quasiquote #(42)))
(core:display (quasiquote-expand #(42)))
(core:display "\n")

View File

@ -35,21 +35,11 @@
(define-macro (simple-let bindings . rest)
(cons (cons 'lambda (cons (map car bindings) rest))
(map cadr bindings)))
;; (define-macro (xsimple-let bindings rest)
;; `(,`(lambda ,(map car bindings) ,@rest)
;; ,@(map cadr bindings)))
(define-macro (xsimple-let bindings rest)
(cons* (cons* (quote lambda)
(map car bindings) (append2 rest (quote ())))
(append2 (map cadr bindings) (quote ()))))
;; (define-macro (xnamed-let name bindings rest)
;; `(simple-let ((,name *unspecified*))
;; (set! ,name (lambda ,(map car bindings) ,@rest))
;; (,name ,@(map cadr bindings))))
(define-macro (xnamed-let name bindings rest)
(list (quote simple-let)
(list (cons* name (quote (*unspecified*))))
@ -60,11 +50,6 @@
(append2 rest (quote ()))))
(cons* name (append2 (map cadr bindings) (quote ())))))
;; (define-macro (let bindings-or-name . rest)
;; (if (symbol? bindings-or-name)
;; `(xnamed-let ,bindings-or-name ,(car rest) ,(cdr rest))
;; `(xsimple-let ,bindings-or-name ,rest)))
(define-macro (let bindings-or-name . rest)
(if (symbol? bindings-or-name) (list (quote xnamed-let) bindings-or-name (car rest) (cdr rest))
(list (quote xsimple-let) bindings-or-name rest)))
@ -84,13 +69,6 @@
(if (= 0 n) '()
(cons (car x) (ss-list-head (cdr x) (- n 1)))))
;; (define (foo x y)
;; (cons x y))
;; (define (ss-list-head x n)
;; (if (= 0 n) '()
;; (foo (car x) (ss-list-head (cdr x) (- n 1)))))
(define (string->list s)
(core:car s))