eval.c closures are now applicable smobs, not tc3s
[bpt/guile.git] / module / ice-9 / deprecated.scm
CommitLineData
86d88a22 1;;;; Copyright (C) 2003, 2005, 2006, 2009 Free Software Foundation, Inc.
5d3af6f2 2;;;;
73be1d9e
MV
3;;;; This library is free software; you can redistribute it and/or
4;;;; modify it under the terms of the GNU Lesser General Public
5;;;; License as published by the Free Software Foundation; either
53befeb7 6;;;; version 3 of the License, or (at your option) any later version.
73be1d9e
MV
7;;;;
8;;;; This library is distributed in the hope that it will be useful,
5d3af6f2 9;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
10;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11;;;; Lesser General Public License for more details.
12;;;;
13;;;; You should have received a copy of the GNU Lesser General Public
14;;;; License along with this library; if not, write to the Free Software
92205699 15;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
5d3af6f2
MV
16;;;;
17
18;;;; Deprecated definitions.
19
5b943a3f
MV
20(define substring-move-left! substring-move!)
21(define substring-move-right! substring-move!)
22
5d3af6f2 23;; This method of dynamically linking Guile Extensions is deprecated.
877f06c3 24;; Use `load-extension' explicitly from Scheme code instead.
5d3af6f2
MV
25
26(define (split-c-module-name str)
27 (let loop ((rev '())
28 (start 0)
29 (pos 0)
30 (end (string-length str)))
31 (cond
32 ((= pos end)
33 (reverse (cons (string->symbol (substring str start pos)) rev)))
34 ((eq? (string-ref str pos) #\space)
35 (loop (cons (string->symbol (substring str start pos)) rev)
36 (+ pos 1)
37 (+ pos 1)
38 end))
39 (else
40 (loop rev start (+ pos 1) end)))))
41
42(define (convert-c-registered-modules dynobj)
43 (let ((res (map (lambda (c)
44 (list (split-c-module-name (car c)) (cdr c) dynobj))
45 (c-registered-modules))))
46 (c-clear-registered-modules)
47 res))
48
49(define registered-modules '())
50
51(define (register-modules dynobj)
52 (set! registered-modules
53 (append! (convert-c-registered-modules dynobj)
54 registered-modules)))
55
56(define (warn-autoload-deprecation modname)
57 (issue-deprecation-warning
58 "Autoloading of compiled code modules is deprecated."
59 "Write a Scheme file instead that uses `load-extension'.")
60 (issue-deprecation-warning
61 (simple-format #f "(You just autoloaded module ~S.)" modname)))
62
63(define (init-dynamic-module modname)
64 ;; Register any linked modules which have been registered on the C level
65 (register-modules #f)
66 (or-map (lambda (modinfo)
67 (if (equal? (car modinfo) modname)
68 (begin
69 (warn-autoload-deprecation modname)
70 (set! registered-modules (delq! modinfo registered-modules))
71 (let ((mod (resolve-module modname #f)))
72 (save-module-excursion
73 (lambda ()
74 (set-current-module mod)
75 (set-module-public-interface! mod mod)
76 (dynamic-call (cadr modinfo) (caddr modinfo))
77 ))
78 #t))
79 #f))
80 registered-modules))
81
82(define (dynamic-maybe-call name dynobj)
83 (catch #t ; could use false-if-exception here
84 (lambda ()
85 (dynamic-call name dynobj))
86 (lambda args
87 #f)))
88
89(define (dynamic-maybe-link filename)
90 (catch #t ; could use false-if-exception here
91 (lambda ()
92 (dynamic-link filename))
93 (lambda args
94 #f)))
95
96(define (find-and-link-dynamic-module module-name)
97 (define (make-init-name mod-name)
98 (string-append "scm_init"
99 (list->string (map (lambda (c)
100 (if (or (char-alphabetic? c)
101 (char-numeric? c))
102 c
103 #\_))
104 (string->list mod-name)))
105 "_module"))
106
107 ;; Put the subdirectory for this module in the car of SUBDIR-AND-LIBNAME,
108 ;; and the `libname' (the name of the module prepended by `lib') in the cdr
109 ;; field. For example, if MODULE-NAME is the list (inet tcp-ip udp), then
110 ;; SUBDIR-AND-LIBNAME will be the pair ("inet/tcp-ip" . "libudp").
111 (let ((subdir-and-libname
112 (let loop ((dirs "")
113 (syms module-name))
114 (if (null? (cdr syms))
115 (cons dirs (string-append "lib" (symbol->string (car syms))))
116 (loop (string-append dirs (symbol->string (car syms)) "/")
117 (cdr syms)))))
118 (init (make-init-name (apply string-append
119 (map (lambda (s)
120 (string-append "_"
121 (symbol->string s)))
122 module-name)))))
123 (let ((subdir (car subdir-and-libname))
124 (libname (cdr subdir-and-libname)))
125
126 ;; Now look in each dir in %LOAD-PATH for `subdir/libfoo.la'. If that
127 ;; file exists, fetch the dlname from that file and attempt to link
128 ;; against it. If `subdir/libfoo.la' does not exist, or does not seem
129 ;; to name any shared library, look for `subdir/libfoo.so' instead and
130 ;; link against that.
131 (let check-dirs ((dir-list %load-path))
132 (if (null? dir-list)
133 #f
134 (let* ((dir (in-vicinity (car dir-list) subdir))
135 (sharlib-full
136 (or (try-using-libtool-name dir libname)
137 (try-using-sharlib-name dir libname))))
138 (if (and sharlib-full (file-exists? sharlib-full))
139 (link-dynamic-module sharlib-full init)
140 (check-dirs (cdr dir-list)))))))))
141
142(define (try-using-libtool-name libdir libname)
143 (let ((libtool-filename (in-vicinity libdir
144 (string-append libname ".la"))))
145 (and (file-exists? libtool-filename)
146 libtool-filename)))
147
148(define (try-using-sharlib-name libdir libname)
149 (in-vicinity libdir (string-append libname ".so")))
150
151(define (link-dynamic-module filename initname)
152 ;; Register any linked modules which have been registered on the C level
153 (register-modules #f)
154 (let ((dynobj (dynamic-link filename)))
155 (dynamic-call initname dynobj)
156 (register-modules dynobj)))
157
158(define (try-module-linked module-name)
159 (init-dynamic-module module-name))
160
161(define (try-module-dynamic-link module-name)
162 (and (find-and-link-dynamic-module module-name)
163 (init-dynamic-module module-name)))
726571e0
MV
164
165(define (list* . args)
166 (issue-deprecation-warning "'list*' is deprecated. Use 'cons*' instead.")
167 (apply cons* args))
2042e178
MV
168
169;; The strange prototype system for uniform arrays has been
170;; deprecated.
171
b15dea68
AW
172(define-macro (eval-case . clauses)
173 (issue-deprecation-warning
174 "`eval-case' is deprecated. Use `eval-when' instead.")
175 ;; Practically speaking, eval-case only had load-toplevel and else as
176 ;; conditions.
177 (cond
178 ((assoc-ref clauses '(load-toplevel))
179 => (lambda (exps)
180 ;; the *unspecified so that non-toplevel definitions will be
181 ;; caught
182 `(begin *unspecified* . ,exps)))
183 ((assoc-ref clauses 'else)
184 => (lambda (exps)
185 `(begin *unspecified* . ,exps)))
186 (else
187 `(begin))))
10fab724
AW
188
189(read-hash-extend
190 #\y
191 (lambda (c port)
192 (issue-deprecation-warning
b0fae4ec 193 "The `#y' bitvector syntax is deprecated. Use `#*' instead.")
10fab724
AW
194 (let ((x (read port)))
195 (cond
196 ((list? x)
197 (list->bitvector
198 (map (lambda (x)
199 (cond ((zero? x) #f)
200 ((eqv? x 1) #t)
201 (else (error "invalid #y element" x))))
202 x)))
203 (else
204 (error "#y needs to be followed by a list" x))))))
b7742c6b
AW
205
206(define (unmemoize-expr . args)
207 (issue-deprecation-warning
208 "`unmemoize-expr' is deprecated. Use `unmemoize-expression' instead.")
209 (apply unmemoize-expression args))
ad79736c
AW
210
211(define ($asinh z) (asinh z))
212(define ($acosh z) (acosh z))
213(define ($atanh z) (atanh z))
214(define ($sqrt z) (sqrt z))
215(define ($abs z) (abs z))
216(define ($exp z) (exp z))
217(define ($log z) (log z))
218(define ($sin z) (sin z))
219(define ($cos z) (cos z))
220(define ($tan z) (tan z))
221(define ($asin z) (asin z))
222(define ($acos z) (acos z))
223(define ($atan z) (atan z))
224(define ($sinh z) (sinh z))
225(define ($cosh z) (cosh z))
226(define ($tanh z) (tanh z))
314b8716
AW
227(define (closure? x)
228 (issue-deprecation-warning
229 "`closure?' is deprecated. Use `procedure?' instead.")
230 (procedure? x))