3 exec guile -L $(pwd) -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
67 #:renamer (symbol-prefix-proc 'guile:)))))
69 (define (logf port string . rest)
70 (guile:apply guile:format (guile:cons* port string rest))
71 (guile:force-output port)
74 (define (stderr string . rest)
75 (guile:apply logf (guile:cons* (guile:current-error-port) string rest)))
77 (define (stdout string . rest)
78 (guile:apply logf (guile:cons* (guile:current-output-port) string rest)))
80 (define (debug . x) #t)
81 ;;(define debug stderr)
91 (define car guile:car)
92 (define cdr guile:cdr)
93 (define cons guile:cons)
94 (define eq? guile:eq?)
95 (define null? guile:null?)
96 (define pair? guile:pair?)
97 (define builtin? guile:procedure?)
98 (define number? guile:number?)
99 (define call guile:apply)
103 (define (pairlis x y a)
104 ;;(debug "pairlis x=~a y=~a a=~a\n" x y a)
107 ((atom? x) (cons (cons x y) a))
108 (#t (cons (cons (car x) (car y))
109 (pairlis (cdr x) (cdr y) a)))))
112 ;;(stderr "assq x=~a\n" x)
113 ;;(debug "assq x=~a a=~a\n" x a)
116 ((eq? (caar a) x) (car a))
117 (#t (assq x (cdr a)))))
121 (#t (cons (car x) (append (cdr x) y)))))
123 (define (eval-environment e a)
124 (eval e (append a environment)))
126 (define (apply-environment fn e a)
127 (apply fn e (append a environment)))
130 (let ((x (guile:read)))
131 (if (guile:eof-object? x) '()
140 (*unspecified* . ,*unspecified*)
150 (pair? . ,guile:pair?)
158 (eval . ,eval-environment)
159 (apply . ,apply-environment)
162 (display . ,guile:display)
163 (newline . ,guile:newline)
165 (builtin? . ,builtin?)
192 (define (mes-define-lambda x a)
193 (cons (caadr x) (cons 'lambda (cons (cdadr x) (cddr x)))))
195 (define (mes-define x a)
197 (cons (cadr x) (eval (caddr x) a))
198 (mes-define-lambda x a)))
200 (define (mes-define-macro x a)
202 (cons (mes-define-lambda x a)
203 (cdr (assq '*macro* a)))))
208 (apply (cdr (assq 'loop a))
209 (cons *unspecified* (cons #t (cons a '())))
211 ((atom? e) (loop (eval e a) (readenv a) a))
212 ((eq? (car e) 'define)
213 (loop *unspecified* (readenv a) (cons (mes-define e a) a)))
214 ((eq? (car e) 'define-macro)
215 (loop *unspecified* (readenv a) (cons (mes-define-macro e a) a)))
216 (#t (loop (eval e a) (readenv a) a))))
218 (define (main arguments)
219 (let ((a (append environment `((*a* . ,environment)))))
220 ;;(guile:display (eval (readenv a) a))
221 (guile:display (loop *unspecified* (readenv a) a))
225 (guile:module-define! (guile:resolve-interface '(mes)) 'main main)