Debian Codegraph @

%3a156/srfi-156-impl.scm

raw symbols SCIP
1 ;; Reference Implementation from SRFI 156
2 ;;
3 ;; Copyright (C) Panicz Maciej Godek (2017). All Rights Reserved.
4 ;;
5 ;; Permission is hereby granted, free of charge, to any person obtaining a copy
6 ;; of this software and associated documentation files (the "Software"), to
7 ;; deal in the Software without restriction, including without limitation the
8 ;; rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 ;; sell copies of the Software, and to permit persons to whom the Software is
10 ;; furnished to do so, subject to the following conditions:
11 ;;
12 ;; The above copyright notice and this permission notice shall be included in
13 ;; all copies or substantial portions of the Software.
14 ;;
15 ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 ;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 ;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 ;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 ;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 ;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 ;; IN THE SOFTWARE.
22 ;;
23 ;; 12/31/2017 - AWK - shimmed extract-placehoders to allow for _ in R6RS scheme
24
25 (define-syntax infix/postfix
26 (syntax-rules ()
27 ((infix/postfix x somewhat?)
28 (somewhat? x))
29
30 ((infix/postfix left related-to? right)
31 (related-to? left right))
32
33 ((infix/postfix left related-to? right . likewise)
34 (let ((right* right))
35 (and (infix/postfix left related-to? right*)
36 (infix/postfix right* . likewise))))))
37
38 (define-syntax extract-placeholders
39 (lambda (x)
40 (syntax-case x ()
41 [(_ final () () body) #'(final (infix/postfix . body))]
42 [(_ final () args body) #'(lambda args (final (infix/postfix . body)))]
43 [(k final (underscore op . rest) (args ...) (body ...))
44 (eq? (syntax->datum #'underscore) '_)
45 #'(k final rest (args ... arg) (body ... arg op))]
46 [(k final (arg op . rest) args (body ...))
47 #'(k final rest args (body ... arg op))]
48 [(k final (underscore) (args ...) (body ...))
49 (eq? (syntax->datum #'underscore) '_)
50 #'(k final () (args ... arg) (body ... arg))]
51 [(k final (arg) args (body ...))
52 #'(k final () args (body ... arg))])))
53
54 #;(define-syntax extract-placeholders
55 (syntax-rules (_)
56 ((extract-placeholders final () () body)
57 (final (infix/postfix . body)))
58
59 ((extract-placeholders final () args body)
60 (lambda args (final (infix/postfix . body))))
61
62 ((extract-placeholders final (_ op . rest) (args ...) (body ...))
63 (extract-placeholders final rest (args ... arg) (body ... arg op)))
64
65 ((extract-placeholders final (arg op . rest) args (body ...))
66 (extract-placeholders final rest args (body ... arg op)))
67
68 ((extract-placeholders final (_) (args ...) (body ...))
69 (extract-placeholders final () (args ... arg) (body ... arg)))
70
71 ((extract-placeholders final (arg) args (body ...))
72 (extract-placeholders final () args (body ... arg)))))
73
74 (define-syntax identity-syntax
75 (syntax-rules ()
76 ((identity-syntax form)
77 form)))
78
79 (define-syntax is
80 (syntax-rules ()
81 ((is . something)
82 (extract-placeholders identity-syntax something () ()))))
83
84 (define-syntax isnt
85 (syntax-rules ()
86 ((isnt . something)
87 (extract-placeholders not something () ()))))