3 ;;; Mes --- Maxwell Equations of Software
4 ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;; base-0.mes: This file is part of Mes.
8 ;;; Mes is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; Mes is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
23 ;;; base-0.mes is the first file being loaded from the Mes core. It
24 ;;; provides primitives that use Mes internals to create the illusion
25 ;;; of compatibility with Guile. It is not safe to be run by Guile.
29 (define (apply f x) (apply-env f x (current-module)))
30 (define (primitive-eval e) (eval e (current-module)))
31 (define (expand-macro e) (expand-macro-env e (current-module)))
35 (define-macro (defined? x)
36 (list 'assq x '(cddr (current-module))))
38 (define (current-input-port) 0)
39 (define (current-output-port) 1)
40 (define (current-error-port) 2)
41 (define (port-filename port) "<stdin>")
42 (define (port-line port) 0)
43 (define (port-column port) 0)
44 (define (ftell port) 0)
45 (define (false-if-exception x) x)
47 (define (cons* x . rest)
49 (if (null? (cdr rest)) (car rest)
50 (cons (car rest) (loop (cdr rest)))))
53 (define-macro (cond . clauses)
54 (list 'if (null? clauses) *unspecified*
55 (if (null? (cdr clauses))
56 (list 'if (car (car clauses))
57 (list (cons 'lambda (cons '() (cons (car (car clauses)) (cdr (car clauses))))))
59 (if (eq? (car (cadr clauses)) 'else)
60 (list 'if (car (car clauses))
61 (list (cons 'lambda (cons '() (car clauses))))
62 (list (cons 'lambda (cons '() (cons *unspecified* (cdr (cadr clauses)))))))
63 (list 'if (car (car clauses))
64 (list (cons 'lambda (cons '() (car clauses))))
65 (cons 'cond (cdr clauses)))))))
71 (if (null? r) (cons (f (car l)) (map f (cdr l)))
73 (cons (f (car l) (caar r)) (map f (cdr l) (cdar r)))))))
75 (define-macro (simple-let bindings . rest)
76 (cons (cons 'lambda (cons (map car bindings) rest))
79 (define-macro (let bindings . rest)
80 (cons 'simple-let (cons bindings rest)))