diff options
Diffstat (limited to 'gnu/gnunet/utils/cut-syntax.scm')
-rw-r--r-- | gnu/gnunet/utils/cut-syntax.scm | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/gnu/gnunet/utils/cut-syntax.scm b/gnu/gnunet/utils/cut-syntax.scm new file mode 100644 index 0000000..bc4ee9d --- /dev/null +++ b/gnu/gnunet/utils/cut-syntax.scm | |||
@@ -0,0 +1,38 @@ | |||
1 | ;; This file is part of Scheme-GNUnet | ||
2 | ;; Copyright © 2022 GNUnet e.V. | ||
3 | ;; | ||
4 | ;; Scheme-GNUnet is free software: you can redistribute it and/or modify it | ||
5 | ;; under the terms of the GNU Affero General Public License as published | ||
6 | ;; by the Free Software Foundation, either version 3 of the License, | ||
7 | ;; or (at your option) any later version. | ||
8 | ;; | ||
9 | ;; Scheme-GNUnet is distributed in the hope that it will be useful, but | ||
10 | ;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | ;; Affero General Public License for more details. | ||
13 | ;; | ||
14 | ;; You should have received a copy of the GNU Affero General Public License | ||
15 | ;; along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | ;; | ||
17 | ;; SPDX-License-Identifier: AGPL-3.0-or-later | ||
18 | |||
19 | ;; TODO: eliminate (gnu gnunet netstruct syntactic), use a compiler pass instead | ||
20 | ;; for inlining, then ‘cut-syntax’ can be deprecated in favour of a ‘cut’. | ||
21 | (define-library (gnu gnunet utils cut-syntax) | ||
22 | (export cut-syntax) | ||
23 | (import (only (rnrs base) ... begin define-syntax syntax-rules)) | ||
24 | (begin | ||
25 | (define-syntax substitute | ||
26 | (syntax-rules (<>) | ||
27 | ((_ (substituted ...) (<> . foos) (bar . bars)) | ||
28 | (substitute (substituted ... bar) foos bars)) | ||
29 | ((_ (substituted ...) (foo . foos) bars) | ||
30 | (substitute (substituted ... foo) foos bars)) | ||
31 | ((_ (substituted ...) () ()) | ||
32 | (substituted ...)))) | ||
33 | |||
34 | (define-syntax cut-syntax | ||
35 | (syntax-rules () | ||
36 | ((_ . foos) | ||
37 | (syntax-rules () | ||
38 | ((_ . bars) (substitute () foos bars)))))))) | ||