diff options
author | Maxime Devos <maxime.devos@student.kuleuven.be> | 2020-11-08 17:41:15 +0000 |
---|---|---|
committer | Maxime Devos <maximedevos@telenet.be> | 2021-09-21 12:08:23 +0200 |
commit | cf1d5f4fc5d9e679daa95534a82fbdc2e6901095 (patch) | |
tree | c4ab6d0d4e97537941ad30ac45bc9587a6e16aa9 /gnu/gnunet/utils | |
parent | 9cbb96a29ace417c0256cd7614ce9d905dd5ffff (diff) | |
download | gnunet-scheme-cf1d5f4fc5d9e679daa95534a82fbdc2e6901095.tar.gz gnunet-scheme-cf1d5f4fc5d9e679daa95534a82fbdc2e6901095.zip |
Define a new binding construct
Diffstat (limited to 'gnu/gnunet/utils')
-rw-r--r-- | gnu/gnunet/utils/hat-let.scm | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/gnu/gnunet/utils/hat-let.scm b/gnu/gnunet/utils/hat-let.scm new file mode 100644 index 0000000..807dbab --- /dev/null +++ b/gnu/gnunet/utils/hat-let.scm | |||
@@ -0,0 +1,74 @@ | |||
1 | ;; This file is part of scheme-GNUnet, a partial Scheme port of GNUnet. | ||
2 | ;; Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010 GNUnet e.V. | ||
3 | ;; Copyright (C) 2020 Maxime Devos <maxime.devos@student.kuleuven.be> | ||
4 | ;; | ||
5 | ;; scheme-GNUnet is free software: you can redistribute it and/or modify it | ||
6 | ;; under the terms of the GNU Affero General Public License as published | ||
7 | ;; by the Free Software Foundation, either version 3 of the License, | ||
8 | ;; or (at your option) any later version. | ||
9 | ;; | ||
10 | ;; scheme-GNUnet is distributed in the hope that it will be useful, but | ||
11 | ;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | ;; Affero General Public License for more details. | ||
14 | ;; | ||
15 | ;; You should have received a copy of the GNU Affero General Public License | ||
16 | ;; along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | ;; | ||
18 | ;; SPDX-License-Identifier: AGPL-3.0-or-later | ||
19 | ;; | ||
20 | ;; As a special exception to the GNU Affero General Public License, | ||
21 | ;; the file may be relicensed under any license used for | ||
22 | ;; most source code of GNUnet 0.13.1, or later versions, as published by | ||
23 | ;; GNUnet e.V. | ||
24 | |||
25 | ;; Author: Maxime Devos | ||
26 | ;; Source: gnu/gnunet/utils/hat-let.scm | ||
27 | ;; Brief: a combination of various binding constructs | ||
28 | ;; Status: stable, exported, pure+assert | ||
29 | |||
30 | (library (gnu gnunet utils hat-let (0)) | ||
31 | (export let^) | ||
32 | (import (rnrs base)) | ||
33 | |||
34 | ;; A generalisation of let*, and-let*, receive, begin, | ||
35 | ;; and generalised let for avoiding nesting. | ||
36 | (define-syntax let^ | ||
37 | (syntax-rules (? ! !! _ <- /o/) | ||
38 | ((: () code ...) | ||
39 | (let () code ...)) | ||
40 | ;; if x, then return @var{esc} | ||
41 | ((: ((? x esc) etc ...) code ...) | ||
42 | (if x | ||
43 | esc | ||
44 | (let^ (etc ...) code ...))) | ||
45 | ;; Bind y to x | ||
46 | ((: ((! x y) etc ...) code ...) | ||
47 | (let ((x y)) | ||
48 | (let^ (etc ...) code ...))) | ||
49 | ;; Define a procedure | ||
50 | ((: ((! (x . args) body ...) etc ...) code ...) | ||
51 | (let ((x (lambda args body ...))) | ||
52 | (let^ (etc ...) | ||
53 | code ...))) | ||
54 | ;; Assert it is true! | ||
55 | ((: ((!! x) etc ...) code ...) | ||
56 | (begin | ||
57 | (assert x) | ||
58 | (let^ (etc ...) code ...))) | ||
59 | ;; Throw a result away | ||
60 | ((: ((_ x) etc ...) code ...) | ||
61 | (begin | ||
62 | x | ||
63 | (let^ (etc ...) code ...))) | ||
64 | ;; Assign multiple values | ||
65 | ((: ((<- (x ...) produce) etc ...) code ...) | ||
66 | (call-with-values produce | ||
67 | (lambda (x ...) | ||
68 | (let^ (etc ...) | ||
69 | code ...)))) | ||
70 | ;; Tail-call into a generalised let | ||
71 | ((: ((/o/ loop (x y) ...) etc ...) code ...) | ||
72 | (let loop ((x y) ...) | ||
73 | (let^ (etc ...) | ||
74 | code ...)))))) | ||