60 lines
2.4 KiB
Scheme
60 lines
2.4 KiB
Scheme
;;; -*-scheme-*-
|
|
|
|
;;; Mes --- Maxwell Equations of Software
|
|
;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
|
|
;;;
|
|
;;; This file is part of Mes.
|
|
;;;
|
|
;;; Mes is free software; you can redistribute it and/or modify it
|
|
;;; 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.
|
|
;;;
|
|
;;; Mes is distributed in the hope that it will be useful, but
|
|
;;; 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
|
|
;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;;; quasiquote.mes is loaded after base. It provides quasiquote
|
|
;;; written in Scheme.
|
|
|
|
;;; Code:
|
|
|
|
(mes-use-module (mes base))
|
|
|
|
(define-macro (quasiquote x)
|
|
(define (loop x)
|
|
(cond ((vector? x) (list 'list->vector (loop (vector->list x))))
|
|
((not (pair? x)) (cons 'quote (cons x '())))
|
|
;;((eq? (car x) 'quasiquote) (loop (loop (cadr x))))
|
|
((eq? (car x) 'quasiquote) (loop (loop
|
|
(if (null? (cddr x)) (cadr x)
|
|
(cons 'list (cdr x))))))
|
|
((eq? (car x) 'unquote) (if (null? (cddr x)) (cadr x)
|
|
(cons 'list (cdr x))))
|
|
((and (pair? (car x)) (eq? (caar x) 'unquote-splicing))
|
|
((lambda (d)
|
|
(if (null? (cddar x)) (list 'append (cadar x) d)
|
|
(list 'quote (append (cdar x) d))))
|
|
(loop (cdr x))))
|
|
(else ((lambda (a d)
|
|
(if (pair? d)
|
|
(if (eq? (car d) 'quote)
|
|
(if (and (pair? a) (eq? (car a) 'quote))
|
|
(list 'quote (cons (cadr a) (cadr d)))
|
|
(if (null? (cadr d))
|
|
(list 'list a)
|
|
(list 'cons* a d)))
|
|
(if (memq (car d) '(list cons*))
|
|
(cons (car d) (cons a (cdr d)))
|
|
(list 'cons* a d)))
|
|
(list 'cons* a d)))
|
|
(loop (car x))
|
|
(loop (cdr x))))))
|
|
(loop x))
|