-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathportability.scm
151 lines (138 loc) · 3.79 KB
/
portability.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
;;; ----------------------------------------------------------------------
;;; Copyright 2007-2008 Alexey Radul.
;;; ----------------------------------------------------------------------
;;; This file is part of Test Manager.
;;;
;;; Test Manager 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.
;;;
;;; Test Manager 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 Test Manager. If not, see <http://www.gnu.org/licenses/>.
;;; ----------------------------------------------------------------------
;; Macros
(cond-expand
(guile
(use-modules (ice-9 syncase)))
(else))
;; SRFI-9: define-record-type
(cond-expand
(guile
(use-modules (srfi srfi-9)))
(srfi-9))
;; Structured conditions
(cond-expand
(guile
(load-relative "guile-conditions"))
(else ;; The MIT Scheme that knows it is 'mit' isn't in Debian Stable yet
(load-relative "mitscheme-conditions")))
;; SRFI-69: Hash tables
(cond-expand
(srfi-69)
(else ; Do I want to use Guile's hash tables instead?
(load-relative "srfi-69-hash-tables")))
;; Optional arguments
(cond-expand
(guile
(use-modules (ice-9 optargs)))
(else ;; The MIT Scheme that knows it is 'mit' isn't in Debian Stable yet
(define-syntax let-optional
(syntax-rules ()
((_ arg-list () expr ...)
(begin expr ...))
((_ arg-list ((variable1 default1) binding ...) expr ...)
(if (null? arg-list)
(let ((variable1 default1) binding ...)
expr ...)
(let ((variable1 (car arg-list))
(arg-list (cdr arg-list)))
(let-optional
arg-list
(binding ...)
expr ...))))
((_ arg-list (variable1 binding ...) expr ...)
(let ((variable1 (car arg-list))
(arg-list (cdr arg-list)))
(let-optional
arg-list
(binding ...)
expr ...)))
))
))
;; Fluid-let (in the MIT Scheme sense of the word 'fluid'.
(cond-expand
(guile
(define-syntax fluid-let
(syntax-rules ()
((_ () expr ...)
(begin expr ...))
((_ ((variable1 value1) binding ...) expr ...)
(let ((out-value variable1)
(in-value value1))
(dynamic-wind
(lambda ()
(set! out-value variable1)
(set! variable1 in-value))
(lambda ()
(fluid-let (binding ...)
expr ...))
(lambda ()
(set! in-value variable1)
(set! variable1 out-value))))))))
(else))
;; Regexes (using MIT Scheme's name for no good reason)
(cond-expand
(guile
(use-modules (ice-9 regex))
(define re-string-search-forward string-match))
(else
(load-option 'regular-expression)))
(cond-expand
(guile
(define (string-search-forward pattern string)
(string-contains string pattern)))
(else
'ok))
;; Pretty printing
(cond-expand
(guile
;; TODO Does Guile have pretty printing?
(define (pp thing) (display thing) (newline)))
(else))
;; Object system
(cond-expand
(guile
'ok)
(else
(load-option 'sos)))
;; Symbols
(cond-expand
(guile
(define (generate-uninterned-symbol)
(make-symbol "symbol"))
(define (make-synthetic-identifier prefix)
(make-symbol (symbol->string prefix))))
(else
'ok))
;; Hackery to make syntactic-closures macro code work (with less
;; hygiene!) in Guile's defmacro system.
(cond-expand
(guile
(define (close-syntax form env)
form))
(else
'ok))
;; Faking out the repl history. (produces foo) will not work at the
;; Guile repl.
(cond-expand
(guile
(define (out)
#f))
(else
'ok))