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
66 ;; non-primitive BUILTINS
74 #:renamer (symbol-prefix-proc 'guile:)))))
76 (define (logf port string . rest)
77 (guile:apply guile:format (guile:cons* port string rest))
78 (guile:force-output port)
81 (define (stderr string . rest)
82 (guile:apply logf (guile:cons* (guile:current-error-port) string rest)))
84 (define (stdout string . rest)
85 (guile:apply logf (guile:cons* (guile:current-output-port) string rest)))
87 (define (debug . x) #t)
88 ;;(define debug stderr)
98 (define car guile:car)
99 (define cdr guile:cdr)
100 (define cons guile:cons)
101 (define eq? guile:eq?)
102 (define null? guile:null?)
103 (define pair? guile:pair?)
104 (define builtin? guile:procedure?)
105 (define char? guile:char?)
106 (define number? guile:number?)
107 (define string? guile:number?)
108 (define call guile:apply)
110 (unread-byte (read-byte)))
112 (guile:char->integer (guile:read-char)))
113 (define (unread-byte x)
114 (guile:unread-char (guile:integer->char x))
118 (stderr "lookup x=~a\n" x)
123 (define (append2 x y)
125 (#t (cons (car x) (append2 (cdr x) y)))))
127 (define (eval-environment e a)
128 (eval e (append2 a environment)))
130 (define (apply-environment fn e a)
131 (apply-env fn e (append2 a environment)))
133 ;; READER: TODO lookup
135 (let ((x (guile:read)))
136 (if (guile:eof-object? x) '()
145 (*unspecified* . ,*unspecified*)
155 (pair? . ,guile:pair?)
163 (eval . ,eval-environment)
164 (apply-env . ,apply-environment)
167 (display . ,guile:display)
168 (newline . ,guile:newline)
170 (builtin? . ,builtin?)
197 (define (mes-define-lambda x a)
198 (cons (caadr x) (cons 'lambda (cons (cdadr x) (cddr x)))))
200 (define (mes-define x a)
202 (cons (cadr x) (eval (caddr x) a))
203 (mes-define-lambda x a)))
205 (define (mes-define-macro x a)
207 (cons (mes-define-lambda x a)
208 (cdr (assq '*macro* a)))))
213 (apply-env (cdr (assq 'loop a))
214 (cons *unspecified* (cons #t (cons a '())))
216 ((atom? e) (loop (eval e a) (readenv a) a))
217 ((eq? (car e) 'define)
218 (loop *unspecified* (readenv a) (cons (mes-define e a) a)))
219 ((eq? (car e) 'define-macro)
220 (loop *unspecified* (readenv a) (cons (mes-define-macro e a) a)))
221 (#t (loop (eval e a) (readenv a) a))))
223 (define (main arguments)
224 (let ((a (append2 environment `((*a* . ,environment)))))
225 ;;(guile:display (eval (readenv a) a))
226 (guile:display (loop *unspecified* (readenv a) a))
230 (guile:module-define! (guile:resolve-interface '(mes)) 'main main)