3 exec guile -L $(pwd)/module -e '(mes)' -s "$0" "$@"
6 ;;; Mes --- The Maxwell Equations of Software
7 ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
9 ;;; This file is part of GNU Guix.
11 ;;; Mes is free software; you can redistribute it and/or modify it
12 ;;; under the terms of the GNU General Public License as published by
13 ;;; the Free Software Foundation; either version 3 of the License, or (at
14 ;;; your option) any later version.
16 ;;; Mes is distributed in the hope that it will be useful, but
17 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;;; GNU General Public License for more details.
21 ;;; You should have received a copy of the GNU General Public License
22 ;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
24 ;; The Maxwell Equations of Software -- John McCarthy page 13
25 ;; http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf
31 (make-module 10 `(,(resolve-interface
46 with-input-from-string
60 ;; ADDITIONAL PRIMITIVES
66 #:renamer (symbol-prefix-proc 'guile:)))))
68 (define (logf port string . rest)
69 (guile:apply guile:format (guile:cons* port string rest))
70 (guile:force-output port)
73 (define (stderr string . rest)
74 (guile:apply logf (guile:cons* (guile:current-error-port) string rest)))
76 (define (stdout string . rest)
77 (guile:apply logf (guile:cons* (guile:current-output-port) string rest)))
79 (define (debug . x) #t)
80 ;;(define debug stderr)
90 (define car guile:car)
91 (define cdr guile:cdr)
92 (define cons guile:cons)
93 (define eq? guile:eq?)
94 (define null? guile:null?)
95 (define pair? guile:pair?)
96 (define builtin? guile:procedure?)
97 (define number? guile:number?)
98 (define call guile:apply)
100 (include-from-path "mes/mes.mes")
102 (define (pairlis x y a)
103 ;;(debug "pairlis x=~a y=~a a=~a\n" x y a)
106 ((atom? x) (cons (cons x y) a))
107 (#t (cons (cons (car x) (car y))
108 (pairlis (cdr x) (cdr y) a)))))
111 ;;(stderr "assq x=~a\n" x)
112 ;;(debug "assq x=~a a=~a\n" x a)
115 ((eq? (caar a) x) (car a))
116 (#t (assq x (cdr a)))))
120 (#t (cons (car x) (append (cdr x) y)))))
122 (define (eval-environment e a)
123 (eval e (append a environment)))
125 (define (apply-environment fn e a)
126 (apply-env fn e (append a environment)))
129 (let ((x (guile:read)))
130 (if (guile:eof-object? x) '()
139 (*unspecified* . ,*unspecified*)
149 (pair? . ,guile:pair?)
157 (eval . ,eval-environment)
158 (apply-env . ,apply-environment)
161 (display . ,guile:display)
162 (newline . ,guile:newline)
164 (builtin? . ,builtin?)
191 (define (mes-define-lambda x a)
192 (cons (caadr x) (cons 'lambda (cons (cdadr x) (cddr x)))))
194 (define (mes-define x a)
196 (cons (cadr x) (eval (caddr x) a))
197 (mes-define-lambda x a)))
199 (define (mes-define-macro x a)
201 (cons (mes-define-lambda x a)
202 (cdr (assq '*macro* a)))))
207 (apply-env (cdr (assq 'loop a))
208 (cons *unspecified* (cons #t (cons a '())))
210 ((atom? e) (loop (eval e a) (readenv a) a))
211 ((eq? (car e) 'define)
212 (loop *unspecified* (readenv a) (cons (mes-define e a) a)))
213 ((eq? (car e) 'define-macro)
214 (loop *unspecified* (readenv a) (cons (mes-define-macro e a) a)))
215 (#t (loop (eval e a) (readenv a) a))))
217 (define (main arguments)
218 (let ((a (append environment `((*a* . ,environment)))))
219 ;;(guile:display (eval (readenv a) a))
220 (guile:display (loop *unspecified* (readenv a) a))
224 (guile:module-define! (guile:resolve-interface '(mes)) 'main main)