2016-07-25 13:39:56 +01:00
|
|
|
;;; -*-scheme-*-
|
|
|
|
|
2018-07-22 13:24:36 +01:00
|
|
|
;;; GNU Mes --- Maxwell Equations of Software
|
2019-03-02 13:33:58 +00:00
|
|
|
;;; Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2016-07-25 13:39:56 +01:00
|
|
|
;;;
|
2018-07-22 13:24:36 +01:00
|
|
|
;;; This file is part of GNU Mes.
|
2016-07-25 13:39:56 +01:00
|
|
|
;;;
|
2018-07-22 13:24:36 +01:00
|
|
|
;;; GNU Mes is free software; you can redistribute it and/or modify it
|
2016-07-25 13:39:56 +01:00
|
|
|
;;; 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.
|
|
|
|
;;;
|
2018-07-22 13:24:36 +01:00
|
|
|
;;; GNU Mes is distributed in the hope that it will be useful, but
|
2016-07-25 13:39:56 +01:00
|
|
|
;;; 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
|
2018-07-22 13:24:36 +01:00
|
|
|
;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
2016-07-25 13:39:56 +01:00
|
|
|
|
2016-10-12 22:40:11 +01:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
2016-12-07 19:26:41 +00:00
|
|
|
;;; base.mes is being loaded after base-0.mes. It provides the minimal
|
2016-10-12 22:40:11 +01:00
|
|
|
;;; set of scheme primitives to run lib/test.mes. It is safe to be
|
|
|
|
;;; run by Guile.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
core: Remove c3+r abbreviatons.
* lib.c (caaar, caadr, caddr, cdadr, cadar, cddar, cdddr, cadddr):
Remove.
* mes.c: Rewrite callers
* module/mes/read-0.mes: Rewrite callers.
* module/mes/base.mes (caaar, caadr, caddr, cdadr, cadar, cddar, cdddr,
cadddr): New function.
2016-12-24 13:21:36 +00:00
|
|
|
(define (caar x) (car (car x)))
|
|
|
|
(define (cadr x) (car (cdr x)))
|
|
|
|
(define (cdar x) (cdr (car x)))
|
|
|
|
(define (cddr x) (cdr (cdr x)))
|
2017-04-02 08:35:47 +01:00
|
|
|
|
|
|
|
|
core: Remove c3+r abbreviatons.
* lib.c (caaar, caadr, caddr, cdadr, cadar, cddar, cdddr, cadddr):
Remove.
* mes.c: Rewrite callers
* module/mes/read-0.mes: Rewrite callers.
* module/mes/base.mes (caaar, caadr, caddr, cdadr, cadar, cddar, cdddr,
cadddr): New function.
2016-12-24 13:21:36 +00:00
|
|
|
(define (caaar x) (car (car (car x))))
|
|
|
|
(define (caadr x) (car (car (cdr x))))
|
2017-04-02 08:35:47 +01:00
|
|
|
(define (cadar x) (car (cdr (car x))))
|
core: Remove c3+r abbreviatons.
* lib.c (caaar, caadr, caddr, cdadr, cadar, cddar, cdddr, cadddr):
Remove.
* mes.c: Rewrite callers
* module/mes/read-0.mes: Rewrite callers.
* module/mes/base.mes (caaar, caadr, caddr, cdadr, cadar, cddar, cdddr,
cadddr): New function.
2016-12-24 13:21:36 +00:00
|
|
|
(define (caddr x) (car (cdr (cdr x))))
|
2017-04-02 08:35:47 +01:00
|
|
|
|
|
|
|
(define (cdaar x) (cdr (car (car x))))
|
core: Remove c3+r abbreviatons.
* lib.c (caaar, caadr, caddr, cdadr, cadar, cddar, cdddr, cadddr):
Remove.
* mes.c: Rewrite callers
* module/mes/read-0.mes: Rewrite callers.
* module/mes/base.mes (caaar, caadr, caddr, cdadr, cadar, cddar, cdddr,
cadddr): New function.
2016-12-24 13:21:36 +00:00
|
|
|
(define (cdadr x) (cdr (car (cdr x))))
|
|
|
|
(define (cddar x) (cdr (cdr (car x))))
|
|
|
|
(define (cdddr x) (cdr (cdr (cdr x))))
|
2017-04-02 08:35:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (caaaar x) (car (car (car (car x)))))
|
|
|
|
(define (caaadr x) (car (car (car (cdr x)))))
|
|
|
|
(define (caadar x) (car (car (cdr (car x)))))
|
|
|
|
(define (caaddr x) (car (car (cdr (cdr x)))))
|
|
|
|
|
|
|
|
(define (cadaar x) (car (cdr (car (car x)))))
|
|
|
|
(define (cadadr x) (car (cdr (car (cdr x)))))
|
|
|
|
(define (caddar x) (car (cdr (cdr (car x)))))
|
core: Remove c3+r abbreviatons.
* lib.c (caaar, caadr, caddr, cdadr, cadar, cddar, cdddr, cadddr):
Remove.
* mes.c: Rewrite callers
* module/mes/read-0.mes: Rewrite callers.
* module/mes/base.mes (caaar, caadr, caddr, cdadr, cadar, cddar, cdddr,
cadddr): New function.
2016-12-24 13:21:36 +00:00
|
|
|
(define (cadddr x) (car (cdr (cdr (cdr x)))))
|
|
|
|
|
2017-04-02 08:35:47 +01:00
|
|
|
|
|
|
|
(define (cdaaar x) (cdr (car (car (car x)))))
|
|
|
|
(define (cdaadr x) (cdr (car (car (cdr x)))))
|
|
|
|
(define (cdadar x) (cdr (car (cdr (car x)))))
|
|
|
|
(define (cdaddr x) (cdr (car (cdr (cdr x)))))
|
|
|
|
|
|
|
|
(define (cddaar x) (cdr (cdr (car (car x)))))
|
|
|
|
(define (cddadr x) (cdr (cdr (car (cdr x)))))
|
|
|
|
(define (cdddar x) (cdr (cdr (cdr (car x)))))
|
|
|
|
(define (cddddr x) (cdr (cdr (cdr (cdr x)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-26 23:32:30 +01:00
|
|
|
(define (identity x) x)
|
2016-12-28 21:04:57 +00:00
|
|
|
(define call/cc call-with-current-continuation)
|
2016-07-26 23:32:30 +01:00
|
|
|
|
2016-12-28 21:26:07 +00:00
|
|
|
(define (command-line) %argv)
|
2018-02-03 20:43:52 +00:00
|
|
|
(define (read) (read-env (current-module)))
|
2017-01-03 22:41:11 +00:00
|
|
|
|
2016-07-27 07:49:45 +01:00
|
|
|
(define-macro (and . x)
|
2016-10-12 22:40:11 +01:00
|
|
|
(if (null? x) #t
|
|
|
|
(if (null? (cdr x)) (car x)
|
|
|
|
(list 'if (car x) (cons 'and (cdr x))
|
2016-07-27 07:49:45 +01:00
|
|
|
#f))))
|
|
|
|
|
2017-04-02 15:47:22 +01:00
|
|
|
(define-macro (or . x)
|
|
|
|
(if (null? x) #f
|
|
|
|
(if (null? (cdr x)) (car x)
|
|
|
|
(list (list 'lambda (list 'r)
|
|
|
|
(list 'if 'r 'r
|
|
|
|
(cons 'or (cdr x))))
|
|
|
|
(car x)))))
|
|
|
|
|
2016-12-20 08:03:05 +00:00
|
|
|
(define (and=> value procedure) (and value (procedure value)))
|
2016-12-20 06:51:50 +00:00
|
|
|
(define eqv? eq?)
|
|
|
|
|
2018-01-01 22:00:01 +00:00
|
|
|
(define (equal? . x)
|
|
|
|
(if (or (null? x) (null? (cdr x))) #t
|
|
|
|
(if (null? (cddr x)) (equal2? (car x) (cadr x))
|
|
|
|
(and (equal2? (car x) (cadr x))
|
|
|
|
(apply equal? (cdr x))))))
|
|
|
|
|
2016-10-16 08:44:52 +01:00
|
|
|
(define (list? x)
|
|
|
|
(or (null? x)
|
|
|
|
(and (pair? x) (list? (cdr x)))))
|
|
|
|
|
2018-11-11 15:25:36 +00:00
|
|
|
(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 else #t)
|
|
|
|
|
2018-04-29 17:29:26 +01:00
|
|
|
(define (map f h . t)
|
2019-03-02 13:33:58 +00:00
|
|
|
(if (or (null? h)
|
|
|
|
(and (pair? t) (null? (car t)))
|
|
|
|
(and (pair? t) (pair? (cdr t)) (null? (cadr t)))) '()
|
2018-04-29 17:29:26 +01:00
|
|
|
(if (null? t) (cons (f (car h)) (map f (cdr h)))
|
|
|
|
(if (null? (cdr t))
|
|
|
|
(cons (f (car h) (caar t)) (map f (cdr h) (cdar t)))
|
|
|
|
(if (null? (cddr t))
|
|
|
|
(cons (f (car h) (caar t) (caadr t)) (map f (cdr h) (cdar t) (cdadr t)))
|
|
|
|
(if (null? (cdddr t))
|
|
|
|
(cons (f (car h) (caar t) (caadr t) (car (caddr t))) (map f (cdr h) (cdar t) (cdadr t) (cdr (caddr t))))
|
|
|
|
(error 'unsupported (cons* "map 5:" f h t))) )))))
|