3 ;; Copyright (C) 2014 <Dmitry Bogatov <KAction@gnu.org>>
5 ;; Author: <Dmitry Bogatov <KAction@gnu.org>>
7 ;; This program is free software; you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License
9 ;; as published by the Free Software Foundation; either version 3
10 ;; of the License, or (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
23 (define-module (syntax functional)
33 (use-modules (syntax implicit))
34 (use-modules (srfi srfi-1))
35 ;; TODO: Generalize on any amount of lists
36 (define (syntax-fold fn init list)
39 [(val rest ...) (syntax-fold fn (fn #'val init) #'(rest ...))]))
41 (define (syntax-fold-right fn init list)
44 [(val rest ...) (fn #'val (syntax-fold-right fn init #'(rest ...)))]))
46 (define (syntax-cons x y)
51 (define (syntax-xcons x y)
54 (define-transformer (syntax-car)
57 (define (syntax-map transformer syntax)
59 (lambda (el acc) (syntax-cons (transformer el) acc))
62 (define (syntax-map* transformer syntax)
63 (syntax-fold-right cons '() syntax))
65 (define (significant? x)
66 (not (or (eq? x *unspecified*)
69 (define (syntax-begin . args)
71 (fold-right syntax-cons '()
72 (filter significant? args))
75 (define-transformer (unsyntax-keywords)
78 (let ((key (syntax->datum #'key)))
79 (unless (keyword? key)
80 (syntax-violation 'unsyntax-keywords
81 "expected keyword as car" %syntax))
82 (append (list key #'value)
83 (unsyntax-keywords #'(rest ...))))])