A multilingual input method framework
Revision | 017a368115a4668dc159eb073c2ba16d926459c2 (tree) |
---|---|
Time | 2006-12-27 04:50:35 |
Author | yamaken <yamaken@ff9a...> |
Commiter | yamaken |
* scm/slib-comlist.scm
* scm/slib-mulapply.scm
* scm/slib-sc2.scm
* scm/slib-srfi-1.scm
* uim/uim-scm.c
* uim/uim-compat-scm.c
* uim/uim.c
* uim/uim-internal.h
* uim/uim-scm.h
* scm/im-custom.scm
* xim/canddisp.cpp
@@ -327,8 +327,8 @@ | ||
327 | 327 | (list 'right |
328 | 328 | (_ "Right end of preedit area") |
329 | 329 | (_ "Right end of preedit area"))) |
330 | - (_ "Candidate window position") | |
331 | - (_ "long description will be here.")) | |
330 | + (_ "Candidate window position") | |
331 | + (_ "long description will be here.")) | |
332 | 332 | |
333 | 333 | (define-custom 'enable-lazy-loading? #t |
334 | 334 | '(global advanced) |
@@ -1,338 +0,0 @@ | ||
1 | -;;"comlist.scm" Implementation of COMMON LISP list functions for Scheme | |
2 | -; Copyright (C) 1991, 1993, 1995, 2001, 2003 Aubrey Jaffer. | |
3 | -; Copyright (C) 2000 Colin Walters | |
4 | -; | |
5 | -;Permission to copy this software, to modify it, to redistribute it, | |
6 | -;to distribute modified versions, and to use it for any purpose is | |
7 | -;granted, subject to the following restrictions and understandings. | |
8 | -; | |
9 | -;1. Any copy made of this software must include this copyright notice | |
10 | -;in full. | |
11 | -; | |
12 | -;2. I have made no warranty or representation that the operation of | |
13 | -;this software will be error-free, and I am under no obligation to | |
14 | -;provide any services, by way of maintenance, update, or otherwise. | |
15 | -; | |
16 | -;3. In conjunction with products arising from the use of this | |
17 | -;material, there shall be no use of my name in any advertising, | |
18 | -;promotional, or sales literature without prior written consent in | |
19 | -;each case. | |
20 | - | |
21 | -;;; Some of these functions may be already defined in your Scheme. | |
22 | -;;; Comment out those definitions for functions which are already defined. | |
23 | - | |
24 | -;;;; LIST FUNCTIONS FROM COMMON LISP | |
25 | - | |
26 | -;;; Some tail-recursive optimizations made by | |
27 | -;;; Colin Walters <walters@cis.ohio-state.edu> | |
28 | -;;; AGJ restored order July 2001. | |
29 | - | |
30 | -;;;@ From: hugh@ear.mit.edu (Hugh Secker-Walker) | |
31 | -(define (make-list k . init) | |
32 | - (set! init (if (pair? init) (car init))) | |
33 | - (do ((k (+ -1 k) (+ -1 k)) | |
34 | - (result '() (cons init result))) | |
35 | - ((negative? k) result))) | |
36 | -;@ | |
37 | -(define (copy-list lst) (append lst '())) | |
38 | -;@ | |
39 | -(define (adjoin obj lst) (if (memv obj lst) lst (cons obj lst))) | |
40 | -;@ | |
41 | -(define union | |
42 | - (letrec ((onion | |
43 | - (lambda (lst1 lst2) | |
44 | - (if (null? lst1) | |
45 | - lst2 | |
46 | - (onion (cdr lst1) (comlist:adjoin (car lst1) lst2)))))) | |
47 | - (lambda (lst1 lst2) | |
48 | - (cond ((null? lst1) lst2) | |
49 | - ((null? lst2) lst1) | |
50 | - ((null? (cdr lst1)) (comlist:adjoin (car lst1) lst2)) | |
51 | - ((null? (cdr lst2)) (comlist:adjoin (car lst2) lst1)) | |
52 | - ((< (length lst2) (length lst1)) (onion (reverse lst2) lst1)) | |
53 | - (else (onion (reverse lst1) lst2)))))) | |
54 | -;@ | |
55 | -(define (intersection lst1 lst2) | |
56 | - (if (null? lst2) | |
57 | - lst2 | |
58 | - (let build-intersection ((lst1 lst1) | |
59 | - (result '())) | |
60 | - (cond ((null? lst1) (reverse result)) | |
61 | - ((memv (car lst1) lst2) | |
62 | - (build-intersection (cdr lst1) (cons (car lst1) result))) | |
63 | - (else | |
64 | - (build-intersection (cdr lst1) result)))))) | |
65 | -;@ | |
66 | -(define (set-difference lst1 lst2) | |
67 | - (if (null? lst2) | |
68 | - lst1 | |
69 | - (let build-difference ((lst1 lst1) | |
70 | - (result '())) | |
71 | - (cond ((null? lst1) (reverse result)) | |
72 | - ((memv (car lst1) lst2) (build-difference (cdr lst1) result)) | |
73 | - (else (build-difference (cdr lst1) (cons (car lst1) result))))))) | |
74 | -;@ | |
75 | -(define (subset? lst1 lst2) | |
76 | - (or (eq? lst1 lst2) | |
77 | - (let loop ((lst1 lst1)) | |
78 | - (or (null? lst1) | |
79 | - (and (memv (car lst1) lst2) | |
80 | - (loop (cdr lst1))))))) | |
81 | -;@ | |
82 | -(define (position obj lst) | |
83 | - (define pos (lambda (n lst) | |
84 | - (cond ((null? lst) #f) | |
85 | - ((eqv? obj (car lst)) n) | |
86 | - (else (pos (+ 1 n) (cdr lst)))))) | |
87 | - (pos 0 lst)) | |
88 | -;@ | |
89 | -(define (reduce-init pred? init lst) | |
90 | - (if (null? lst) | |
91 | - init | |
92 | - (comlist:reduce-init pred? (pred? init (car lst)) (cdr lst)))) | |
93 | -;@ | |
94 | -(define (reduce pred? lst) | |
95 | - (cond ((null? lst) lst) | |
96 | - ((null? (cdr lst)) (car lst)) | |
97 | - (else (comlist:reduce-init pred? (car lst) (cdr lst))))) | |
98 | -;@ | |
99 | -(define (some pred lst . rest) | |
100 | - (cond ((null? rest) | |
101 | - (let mapf ((lst lst)) | |
102 | - (and (not (null? lst)) | |
103 | - (or (pred (car lst)) (mapf (cdr lst)))))) | |
104 | - (else (let mapf ((lst lst) (rest rest)) | |
105 | - (and (not (null? lst)) | |
106 | - (or (apply pred (car lst) (map car rest)) | |
107 | - (mapf (cdr lst) (map cdr rest)))))))) | |
108 | -;@ | |
109 | -(define (every pred lst . rest) | |
110 | - (cond ((null? rest) | |
111 | - (let mapf ((lst lst)) | |
112 | - (or (null? lst) | |
113 | - (and (pred (car lst)) (mapf (cdr lst)))))) | |
114 | - (else (let mapf ((lst lst) (rest rest)) | |
115 | - (or (null? lst) | |
116 | - (and (apply pred (car lst) (map car rest)) | |
117 | - (mapf (cdr lst) (map cdr rest)))))))) | |
118 | -;@ | |
119 | -(define (notany pred . ls) (not (apply comlist:some pred ls))) | |
120 | -;@ | |
121 | -(define (notevery pred . ls) (not (apply comlist:every pred ls))) | |
122 | -;@ | |
123 | -(define (list-of?? predicate . bound) | |
124 | - (define (errout) (apply slib:error 'list-of?? predicate bound)) | |
125 | - (case (length bound) | |
126 | - ((0) | |
127 | - (lambda (obj) | |
128 | - (and (list? obj) | |
129 | - (comlist:every predicate obj)))) | |
130 | - ((1) | |
131 | - (set! bound (car bound)) | |
132 | - (cond ((negative? bound) | |
133 | - (set! bound (- bound)) | |
134 | - (lambda (obj) | |
135 | - (and (list? obj) | |
136 | - (<= bound (length obj)) | |
137 | - (comlist:every predicate obj)))) | |
138 | - (else | |
139 | - (lambda (obj) | |
140 | - (and (list? obj) | |
141 | - (<= (length obj) bound) | |
142 | - (comlist:every predicate obj)))))) | |
143 | - ((2) | |
144 | - (let ((low (car bound)) | |
145 | - (high (cadr bound))) | |
146 | - (cond ((or (negative? low) (negative? high)) (errout)) | |
147 | - ((< high low) | |
148 | - (set! high (car bound)) | |
149 | - (set! low (cadr bound)))) | |
150 | - (lambda (obj) | |
151 | - (and (list? obj) | |
152 | - (<= low (length obj) high) | |
153 | - (comlist:every predicate obj))))) | |
154 | - (else (errout)))) | |
155 | -;@ | |
156 | -(define (find-if pred? lst) | |
157 | - (cond ((null? lst) #f) | |
158 | - ((pred? (car lst)) (car lst)) | |
159 | - (else (comlist:find-if pred? (cdr lst))))) | |
160 | -;@ | |
161 | -(define (member-if pred? lst) | |
162 | - (cond ((null? lst) #f) | |
163 | - ((pred? (car lst)) lst) | |
164 | - (else (comlist:member-if pred? (cdr lst))))) | |
165 | -;@ | |
166 | -(define (remove obj lst) | |
167 | - (define head (list '*head*)) | |
168 | - (let remove ((lst lst) | |
169 | - (tail head)) | |
170 | - (cond ((null? lst)) | |
171 | - ((eqv? obj (car lst)) (remove (cdr lst) tail)) | |
172 | - (else | |
173 | - (set-cdr! tail (list (car lst))) | |
174 | - (remove (cdr lst) (cdr tail))))) | |
175 | - (cdr head)) | |
176 | -;@ | |
177 | -(define (remove-if pred? lst) | |
178 | - (let remove-if ((lst lst) | |
179 | - (result '())) | |
180 | - (cond ((null? lst) (reverse result)) | |
181 | - ((pred? (car lst)) (remove-if (cdr lst) result)) | |
182 | - (else (remove-if (cdr lst) (cons (car lst) result)))))) | |
183 | -;@ | |
184 | -(define (remove-if-not pred? lst) | |
185 | - (let remove-if-not ((lst lst) | |
186 | - (result '())) | |
187 | - (cond ((null? lst) (reverse result)) | |
188 | - ((pred? (car lst)) (remove-if-not (cdr lst) (cons (car lst) result))) | |
189 | - (else (remove-if-not (cdr lst) result))))) | |
190 | -;@ | |
191 | -(define nconc | |
192 | - (if (provided? "rev2-procedures") append! | |
193 | - (lambda args | |
194 | - (cond ((null? args) '()) | |
195 | - ((null? (cdr args)) (car args)) | |
196 | - ((null? (car args)) (apply comlist:nconc (cdr args))) | |
197 | - (else | |
198 | - (set-cdr! (last-pair (car args)) | |
199 | - (apply comlist:nconc (cdr args))) | |
200 | - (car args)))))) | |
201 | - | |
202 | -;;;@ From: hugh@ear.mit.edu (Hugh Secker-Walker) | |
203 | -(define (nreverse rev-it) | |
204 | -;;; Reverse order of elements of LIST by mutating cdrs. | |
205 | - (cond ((null? rev-it) rev-it) | |
206 | - ((not (list? rev-it)) | |
207 | - (slib:error "nreverse: Not a list in arg1" rev-it)) | |
208 | - (else (do ((reved '() rev-it) | |
209 | - (rev-cdr (cdr rev-it) (cdr rev-cdr)) | |
210 | - (rev-it rev-it rev-cdr)) | |
211 | - ((begin (set-cdr! rev-it reved) (null? rev-cdr)) rev-it))))) | |
212 | -;@ | |
213 | -(define (last lst n) | |
214 | - (comlist:nthcdr (- (length lst) n) lst)) | |
215 | -;@ | |
216 | -(define (butlast lst n) | |
217 | - (comlist:butnthcdr (- (length lst) n) lst)) | |
218 | -;@ | |
219 | -(define (nthcdr n lst) | |
220 | - (if (zero? n) lst (comlist:nthcdr (+ -1 n) (cdr lst)))) | |
221 | -;@ | |
222 | -(define (butnthcdr k lst) | |
223 | - (cond ((negative? k) lst) ;(slib:error "negative argument to butnthcdr" k) | |
224 | - ; SIMSYNCH FIFO8 uses negative k. | |
225 | - ((or (zero? k) (null? lst)) '()) | |
226 | - (else (let ((ans (list (car lst)))) | |
227 | - (do ((lst (cdr lst) (cdr lst)) | |
228 | - (tail ans (cdr tail)) | |
229 | - (k (+ -2 k) (+ -1 k))) | |
230 | - ((or (negative? k) (null? lst)) ans) | |
231 | - (set-cdr! tail (list (car lst)))))))) | |
232 | - | |
233 | -;;;; CONDITIONALS | |
234 | -;@ | |
235 | -(define (and? . args) | |
236 | - (cond ((null? args) #t) | |
237 | - ((car args) (apply comlist:and? (cdr args))) | |
238 | - (else #f))) | |
239 | -;@ | |
240 | -(define (or? . args) | |
241 | - (cond ((null? args) #f) | |
242 | - ((car args) #t) | |
243 | - (else (apply comlist:or? (cdr args))))) | |
244 | - | |
245 | -;;;@ Checks to see if a list has any duplicate MEMBERs. | |
246 | -(define (has-duplicates? lst) | |
247 | - (cond ((null? lst) #f) | |
248 | - ((member (car lst) (cdr lst)) #t) | |
249 | - (else (comlist:has-duplicates? (cdr lst))))) | |
250 | - | |
251 | -;;;@ remove duplicates of MEMBERs of a list | |
252 | -(define remove-duplicates | |
253 | - (letrec ((rem-dup | |
254 | - (lambda (lst nlst) | |
255 | - (cond ((null? lst) (reverse nlst)) | |
256 | - ((member (car lst) nlst) (rem-dup (cdr lst) nlst)) | |
257 | - (else (rem-dup (cdr lst) (cons (car lst) nlst))))))) | |
258 | - (lambda (lst) | |
259 | - (rem-dup lst '())))) | |
260 | -;@ | |
261 | -(define list* | |
262 | - (letrec ((list*1 (lambda (obj) | |
263 | - (if (null? (cdr obj)) | |
264 | - (car obj) | |
265 | - (cons (car obj) (list*1 (cdr obj))))))) | |
266 | - (lambda (obj1 . obj2) | |
267 | - (if (null? obj2) | |
268 | - obj1 | |
269 | - (cons obj1 (list*1 obj2)))))) | |
270 | -;@ | |
271 | -(define (atom? obj) | |
272 | - (not (pair? obj))) | |
273 | -;@ | |
274 | -(define (delete obj lst) | |
275 | - (let delete ((lst lst)) | |
276 | - (cond ((null? lst) '()) | |
277 | - ((equal? obj (car lst)) (delete (cdr lst))) | |
278 | - (else | |
279 | - (set-cdr! lst (delete (cdr lst))) | |
280 | - lst)))) | |
281 | -;@ | |
282 | -(define (delete-if pred lst) | |
283 | - (let delete-if ((lst lst)) | |
284 | - (cond ((null? lst) '()) | |
285 | - ((pred (car lst)) (delete-if (cdr lst))) | |
286 | - (else | |
287 | - (set-cdr! lst (delete-if (cdr lst))) | |
288 | - lst)))) | |
289 | -;@ | |
290 | -(define (delete-if-not pred lst) | |
291 | - (let delete-if ((lst lst)) | |
292 | - (cond ((null? lst) '()) | |
293 | - ((not (pred (car lst))) (delete-if (cdr lst))) | |
294 | - (else | |
295 | - (set-cdr! lst (delete-if (cdr lst))) | |
296 | - lst)))) | |
297 | - | |
298 | -;;; internal versions safe from name collisions. | |
299 | - | |
300 | -;;(define comlist:make-list make-list) | |
301 | -;;(define comlist:copy-list copy-list) | |
302 | -(define comlist:adjoin adjoin) | |
303 | -;;(define comlist:union union) | |
304 | -;;(define comlist:intersection intersection) | |
305 | -;;(define comlist:set-difference set-difference) | |
306 | -;;(define comlist:subset? subset?) | |
307 | -;;(define comlist:position position) | |
308 | -(define comlist:reduce-init reduce-init) | |
309 | -;;(define comlist:reduce reduce) ; reduce is also in collect.scm | |
310 | -(define comlist:some some) | |
311 | -(define comlist:every every) | |
312 | -;;(define comlist:notevery notevery) | |
313 | -;;(define comlist:notany notany) | |
314 | -(define comlist:find-if find-if) | |
315 | -(define comlist:member-if member-if) | |
316 | -;;(define comlist:remove remove) | |
317 | -;;(define comlist:remove-if remove-if) | |
318 | -;;(define comlist:remove-if-not remove-if-not) | |
319 | -(define comlist:nconc nconc) | |
320 | -;;(define comlist:nreverse nreverse) | |
321 | -;;(define comlist:last last) | |
322 | -;;(define comlist:butlast butlast) | |
323 | -(define comlist:nthcdr nthcdr) | |
324 | -(define comlist:butnthcdr butnthcdr) | |
325 | -(define comlist:and? and?) | |
326 | -(define comlist:or? or?) | |
327 | -(define comlist:has-duplicates? has-duplicates?) | |
328 | -;;(define comlist:remove-duplicates remove-duplicates) | |
329 | -;;(define comlist:delete-if-not delete-if-not) | |
330 | -;;(define comlist:delete-if delete-if) | |
331 | -;;(define comlist:delete delete) | |
332 | -;;(define comlist:atom? atom?) | |
333 | -;;(define atom atom?) | |
334 | -;;(define comlist:atom atom?) | |
335 | -;;(define comlist:list* list*) | |
336 | -;;(define comlist:list-of?? list-of??) | |
337 | - | |
338 | -(provide "comlist") |
@@ -1,30 +0,0 @@ | ||
1 | -; "mulapply.scm" Redefine APPLY take more than 2 arguments. | |
2 | -;Copyright (C) 1991, 2003 Aubrey Jaffer | |
3 | -; | |
4 | -;Permission to copy this software, to modify it, to redistribute it, | |
5 | -;to distribute modified versions, and to use it for any purpose is | |
6 | -;granted, subject to the following restrictions and understandings. | |
7 | -; | |
8 | -;1. Any copy made of this software must include this copyright notice | |
9 | -;in full. | |
10 | -; | |
11 | -;2. I have made no warranty or representation that the operation of | |
12 | -;this software will be error-free, and I am under no obligation to | |
13 | -;provide any services, by way of maintenance, update, or otherwise. | |
14 | -; | |
15 | -;3. In conjunction with products arising from the use of this | |
16 | -;material, there shall be no use of my name in any advertising, | |
17 | -;promotional, or sales literature without prior written consent in | |
18 | -;each case. | |
19 | -;@ | |
20 | -(define apply | |
21 | - (letrec ((apply-2 apply) | |
22 | - (append-to-last | |
23 | - (lambda (lst) | |
24 | - (if (null? (cdr lst)) | |
25 | - (car lst) | |
26 | - (cons (car lst) (append-to-last (cdr lst))))))) | |
27 | - (lambda args | |
28 | - (apply-2 (car args) (append-to-last (cdr args)))))) | |
29 | - | |
30 | -(provide "mulapply") |
@@ -1,69 +0,0 @@ | ||
1 | -;"sc2.scm" Implementation of rev2 procedures eliminated in subsequent versions. | |
2 | -; Copyright (C) 1991, 1993 Aubrey Jaffer | |
3 | -; | |
4 | -;Permission to copy this software, to modify it, to redistribute it, | |
5 | -;to distribute modified versions, and to use it for any purpose is | |
6 | -;granted, subject to the following restrictions and understandings. | |
7 | -; | |
8 | -;1. Any copy made of this software must include this copyright notice | |
9 | -;in full. | |
10 | -; | |
11 | -;2. I have made no warranty or representation that the operation of | |
12 | -;this software will be error-free, and I am under no obligation to | |
13 | -;provide any services, by way of maintenance, update, or otherwise. | |
14 | -; | |
15 | -;3. In conjunction with products arising from the use of this | |
16 | -;material, there shall be no use of my name in any advertising, | |
17 | -;promotional, or sales literature without prior written consent in | |
18 | -;each case. | |
19 | - | |
20 | -;@ | |
21 | -(define (substring-move-left! string1 start1 end1 string2 start2) | |
22 | - (do ((i start1 (+ i 1)) | |
23 | - (j start2 (+ j 1)) | |
24 | - (l (- end1 start1) (- l 1))) | |
25 | - ((<= l 0)) | |
26 | - (string-set! string2 j (string-ref string1 i)))) | |
27 | -;@ | |
28 | -(define (substring-move-right! string1 start1 end1 string2 start2) | |
29 | - (do ((i (+ start1 (- end1 start1) -1) (- i 1)) | |
30 | - (j (+ start2 (- end1 start1) -1) (- j 1)) | |
31 | - (l (- end1 start1) (- l 1))) | |
32 | - ((<= l 0)) | |
33 | - (string-set! string2 j (string-ref string1 i)))) | |
34 | -;@ | |
35 | -(define (substring-fill! string start end char) | |
36 | - (do ((i start (+ i 1)) | |
37 | - (l (- end start) (- l 1))) | |
38 | - ((<= l 0)) | |
39 | - (string-set! string i char))) | |
40 | -;@ | |
41 | -(define (string-null? str) | |
42 | - (= 0 (string-length str))) | |
43 | -;@ | |
44 | -(define append! | |
45 | - (lambda args | |
46 | - (cond ((null? args) '()) | |
47 | - ((null? (cdr args)) (car args)) | |
48 | - ((null? (car args)) (apply append! (cdr args))) | |
49 | - (else | |
50 | - (set-cdr! (last-pair (car args)) | |
51 | - (apply append! (cdr args))) | |
52 | - (car args))))) | |
53 | - | |
54 | -;;;; need to add code for OBJECT-HASH and OBJECT-UNHASH | |
55 | -;@ | |
56 | -(define 1+ | |
57 | - (let ((+ +)) | |
58 | - (lambda (n) (+ n 1)))) | |
59 | -(define -1+ | |
60 | - (let ((+ +)) | |
61 | - (lambda (n) (+ n -1)))) | |
62 | -;@ | |
63 | -(define <? <) | |
64 | -(define <=? <=) | |
65 | -(define =? =) | |
66 | -(define >? >) | |
67 | -(define >=? >=) | |
68 | - | |
69 | -(provide "rev2-procedures") |
@@ -1,645 +0,0 @@ | ||
1 | -;;; "srfi-1.scm" SRFI-1 list-processing library -*-scheme-*- | |
2 | -;; Copyright 2001 Aubrey Jaffer | |
3 | -;; Copyright 2003 Sven Hartrumpf | |
4 | -;; Copyright 2003-2004 Lars Buitinck | |
5 | -; | |
6 | -;Permission to copy this software, to modify it, to redistribute it, | |
7 | -;to distribute modified versions, and to use it for any purpose is | |
8 | -;granted, subject to the following restrictions and understandings. | |
9 | -; | |
10 | -;1. Any copy made of this software must include this copyright notice | |
11 | -;in full. | |
12 | -; | |
13 | -;2. I have made no warranty or representation that the operation of | |
14 | -;this software will be error-free, and I am under no obligation to | |
15 | -;provide any services, by way of maintenance, update, or otherwise. | |
16 | -; | |
17 | -;3. In conjunction with products arising from the use of this | |
18 | -;material, there shall be no use of my name in any advertising, | |
19 | -;promotional, or sales literature without prior written consent in | |
20 | -;each case. | |
21 | - | |
22 | -; Some pieces from: | |
23 | -;;; | |
24 | -;;; Copyright (c) 1998, 1999 by Olin Shivers. You may do as you please with | |
25 | -;;; this code as long as you do not remove this copyright notice or | |
26 | -;;; hold me liable for its use. Please send bug reports to shivers@ai.mit.edu. | |
27 | -;;; -Olin | |
28 | - | |
29 | -;;@code{(require 'srfi-1)} | |
30 | -;;@ftindex srfi-1 | |
31 | -;; | |
32 | -;;@noindent | |
33 | -;;Implements the @dfn{SRFI-1} @dfn{list-processing library} as described | |
34 | -;;at @url{http://srfi.schemers.org/srfi-1/srfi-1.html} | |
35 | - | |
36 | -(require "slib-mulapply.scm") | |
37 | -(require "slib-sc2.scm") ;for append! | |
38 | -(require "slib-comlist.scm") | |
39 | - | |
40 | -;;@subheading Constructors | |
41 | - | |
42 | -;;@body | |
43 | -;; @code{(define (xcons d a) (cons a d))}. | |
44 | -(define (xcons d a) (cons a d)) | |
45 | - | |
46 | -;;@body | |
47 | -;; Returns a list of length @1. Element @var{i} is | |
48 | -;;@code{(@2 @var{i})} for 0 <= @var{i} < @1. | |
49 | -(define (list-tabulate len proc) | |
50 | - (do ((i (- len 1) (- i 1)) | |
51 | - (ans '() (cons (proc i) ans))) | |
52 | - ((< i 0) ans))) | |
53 | - | |
54 | -;;@args obj1 obj2 | |
55 | -(define cons* list*) | |
56 | - | |
57 | -;;@args flist | |
58 | -(define list-copy copy-list) | |
59 | - | |
60 | -;;@args count start step | |
61 | -;;@args count start | |
62 | -;;@args count | |
63 | -;;Returns a list of @1 numbers: (@2, @2+@3, @dots{}, @2+(@1-1)*@3). | |
64 | -(define (iota count . args) | |
65 | - (let ((start (if (null? args) 0 (car args))) | |
66 | - (step (if (or (null? args) (null? (cdr args))) 1 (cadr args)))) | |
67 | - (list-tabulate count (lambda (idx) (+ start (* step idx)))))) | |
68 | - | |
69 | -;;@body | |
70 | -;;Returns a circular list of @1, @2, @dots{}. | |
71 | -(define (circular-list obj1 . obj2) | |
72 | - (let ((ans (cons obj1 obj2))) | |
73 | - (set-cdr! (last-pair ans) ans) | |
74 | - ans)) | |
75 | - | |
76 | -;;@subheading Predicates | |
77 | - | |
78 | -;;@args obj | |
79 | -(define proper-list? list?) | |
80 | - | |
81 | -;;@body | |
82 | -(define (circular-list? x) | |
83 | - (let lp ((x x) (lag x)) | |
84 | - (and (pair? x) | |
85 | - (let ((x (cdr x))) | |
86 | - (and (pair? x) | |
87 | - (let ((x (cdr x)) | |
88 | - (lag (cdr lag))) | |
89 | - (or (eq? x lag) (lp x lag)))))))) | |
90 | - | |
91 | -;;@body | |
92 | -(define (dotted-list? obj) | |
93 | - (not (or (proper-list? obj) (circular-list? obj)))) | |
94 | - | |
95 | -;;@args obj | |
96 | -(define null-list? null?) | |
97 | - | |
98 | -;;@body | |
99 | -(define (not-pair? obj) (not (pair? obj))) | |
100 | - | |
101 | -;;@body | |
102 | -(define (list= =pred . lists) | |
103 | - (or (null? lists) ; special case | |
104 | - (let lp1 ((list-a (car lists)) (others (cdr lists))) | |
105 | - (or (null? others) | |
106 | - (let ((list-b (car others)) | |
107 | - (others (cdr others))) | |
108 | - (if (eq? list-a list-b) ; EQ? => LIST= | |
109 | - (lp1 list-b others) | |
110 | - (let lp2 ((list-a list-a) (list-b list-b)) | |
111 | - (if (null-list? list-a) | |
112 | - (and (null-list? list-b) | |
113 | - (lp1 list-b others)) | |
114 | - (and (not (null-list? list-b)) | |
115 | - (=pred (car list-a) (car list-b)) | |
116 | - (lp2 (cdr list-a) (cdr list-b))))))))))) | |
117 | - | |
118 | -;;@subheading Selectors | |
119 | - | |
120 | -;;@args pair | |
121 | -(define first car) | |
122 | -;;@args pair | |
123 | -(define second cadr) | |
124 | -;;@args pair | |
125 | -(define third caddr) | |
126 | -;;@args pair | |
127 | -(define fourth cadddr) | |
128 | -;;@body | |
129 | -(define (fifth pair) (car (cddddr pair))) | |
130 | -(define (sixth pair) (cadr (cddddr pair))) | |
131 | -(define (seventh pair) (caddr (cddddr pair))) | |
132 | -(define (eighth pair) (cadddr (cddddr pair))) | |
133 | -(define (ninth pair) (car (cddddr (cddddr pair)))) | |
134 | -(define (tenth pair) (cadr (cddddr (cddddr pair)))) | |
135 | - | |
136 | -;;@body | |
137 | -(define (car+cdr pair) (values (car pair) (cdr pair))) | |
138 | - | |
139 | -;;@args lst k | |
140 | -(define (drop lst k) (nthcdr k lst)) | |
141 | -(define (take lst k) (butnthcdr k lst)) | |
142 | -(define (take! lst k) | |
143 | - (if (or (null? lst) (<= k 0)) | |
144 | - '() | |
145 | - (begin (set-cdr! (drop (- k 1) lst) '()) lst))) | |
146 | -;;@args lst k | |
147 | -(define take-right last) | |
148 | -;;@args lst k | |
149 | -(define drop-right butlast) | |
150 | -;;@args lst k | |
151 | -(define drop-right! drop-right) | |
152 | - | |
153 | -;;@body | |
154 | -(define (split-at lst k) | |
155 | - (let loop ((l '()) (r lst) (k k)) | |
156 | - (if (or (null? r) (= k 0)) | |
157 | - (values (reverse! l) r) | |
158 | - (loop (cons (car r) l) (cdr r) (- k 1))))) | |
159 | -(define (split-at! lst k) | |
160 | - (if (= k 0) | |
161 | - (values '() lst) | |
162 | - (let* ((half (drop lst (- k 1))) | |
163 | - (r (cdr half))) | |
164 | - (set-cdr! half '()) | |
165 | - (values lst r)))) | |
166 | - | |
167 | -;;@body | |
168 | -(define (last lst . k) | |
169 | - (if (null? k) | |
170 | - (car (last-pair lst)) | |
171 | - (apply take-right lst k))) | |
172 | - | |
173 | -;;@subheading Miscellaneous | |
174 | - | |
175 | -;;@body | |
176 | -(define (length+ clist) (and (list? clist) (length clist))) | |
177 | - | |
178 | -;;Append and append! are provided by R4RS and rev2-procedures. | |
179 | - | |
180 | -;;@body | |
181 | -(define (concatenate lists) (reduce-right append '() lists)) | |
182 | -(define (concatenate! lists) (reduce-right append! '() lists)) | |
183 | - | |
184 | -;;Reverse is provided by R4RS. | |
185 | -;;@args lst | |
186 | -(define reverse! nreverse) | |
187 | - | |
188 | -;;@body | |
189 | -(define (append-reverse rev-head tail) | |
190 | - (let lp ((rev-head rev-head) (tail tail)) | |
191 | - (if (null-list? rev-head) tail | |
192 | - (lp (cdr rev-head) (cons (car rev-head) tail))))) | |
193 | -(define (append-reverse! rev-head tail) | |
194 | - (let lp ((rev-head rev-head) (tail tail)) | |
195 | - (if (null-list? rev-head) tail | |
196 | - (let ((next-rev (cdr rev-head))) | |
197 | - (set-cdr! rev-head tail) | |
198 | - (lp next-rev rev-head))))) | |
199 | - | |
200 | -;;@body | |
201 | -(define (zip list1 . list2) (apply map list list1 list2)) | |
202 | - | |
203 | -;;@body | |
204 | -(define (unzip1 lst) (map car lst)) | |
205 | -(define (unzip2 lst) (values (map car lst) (map cadr lst))) | |
206 | -(define (unzip3 lst) (values (map car lst) (map cadr lst) (map caddr lst))) | |
207 | -(define (unzip4 lst) (values (map car lst) (map cadr lst) (map caddr lst) | |
208 | - (map cadddr lst))) | |
209 | -(define (unzip5 lst) (values (map car lst) (map cadr lst) (map caddr lst) | |
210 | - (map cadddr lst) (map fifth lst))) | |
211 | - | |
212 | -;;@body | |
213 | -(define (count pred list1 . list2) | |
214 | - (cond ((null? list2) | |
215 | - (let mapf ((l list1) (count 0)) | |
216 | - (if (null? l) | |
217 | - count (mapf (cdr l) | |
218 | - (+ count (if (pred (car l)) 1 0)))))) | |
219 | - (else (let mapf ((l list1) (rest list2) (count 0)) | |
220 | - (if (null? l) | |
221 | - count | |
222 | - (mapf (cdr l) | |
223 | - (map cdr rest) | |
224 | - (+ count (if (apply pred (car l) (map car rest)) | |
225 | - 1 0)))))))) | |
226 | - | |
227 | -;;@subheading Fold and Unfold | |
228 | - | |
229 | -;;@args kons knil clist1 clist2 ... | |
230 | -(define (fold f z l1 . l) | |
231 | - (set! l (cons l1 l)) | |
232 | - (if (any null? l) | |
233 | - z | |
234 | - (apply fold (cons* f (apply f (append! (map car l) (list z))) | |
235 | - (map cdr l))))) | |
236 | -;;@args kons knil clist1 clist2 ... | |
237 | -(define (fold-right f z l1 . l) | |
238 | - (set! l (cons l1 l)) | |
239 | - (if (any null? l) | |
240 | - z | |
241 | - (apply f (append! (map car l) | |
242 | - (list (apply fold-right (cons* f z (map cdr l)))))))) | |
243 | -;;@args kons knil clist1 clist2 ... | |
244 | -(define (pair-fold f z l) ;XXX should be multi-arg | |
245 | - (if (null? l) | |
246 | - z | |
247 | - (let ((tail (cdr l))) | |
248 | - (pair-fold f (f l z) tail)))) | |
249 | -;;@args kons knil clist1 clist2 ... | |
250 | -(define (pair-fold-right f z l) ;XXX should be multi-arg | |
251 | - (if (null? l) | |
252 | - z | |
253 | - (f l (pair-fold-right f z (cdr l))))) | |
254 | - | |
255 | -;;@body | |
256 | -(define (reduce f ridentity list) | |
257 | - (if (null? list) ridentity (fold f (car list) (cdr list)))) | |
258 | -(define (reduce-right f ridentity list) | |
259 | - (if (null? list) | |
260 | - ridentity | |
261 | - (let red ((l (cdr list)) (ridentity (car list))) | |
262 | - (if (null? list) | |
263 | - ridentity | |
264 | - (f ridentity (red (cdr list) (car list))))))) | |
265 | - | |
266 | -;;; We stop when CLIST1 runs out, not when any list runs out. | |
267 | -;;@args f clist1 clist2 ... | |
268 | -(define (map! f clist1 . lists) | |
269 | - (if (pair? lists) | |
270 | - (let lp ((clist1 clist1) (lists lists)) | |
271 | - (if (not (null-list? clist1)) | |
272 | - (call-with-values ; expanded a receive call | |
273 | - (lambda () (%cars+cdrs/no-test lists)) | |
274 | - (lambda (heads tails) | |
275 | - (set-car! clist1 (apply f (car clist1) heads)) | |
276 | - (lp (cdr clist1) tails))))) | |
277 | - ;; Fast path. | |
278 | - (pair-for-each (lambda (pair) (set-car! pair (f (car pair)))) clist1)) | |
279 | - clist1) | |
280 | -;;@args f clist1 clist2 ... | |
281 | -(define (pair-for-each proc clist1 . lists) | |
282 | - (if (pair? lists) | |
283 | - (let lp ((lists (cons clist1 lists))) | |
284 | - (let ((tails (%cdrs lists))) | |
285 | - (if (pair? tails) | |
286 | - (begin (apply proc lists) | |
287 | - (lp tails))))) | |
288 | - ;; Fast path. | |
289 | - (let lp ((lis clist1)) | |
290 | - (if (not (null-list? lis)) | |
291 | - (let ((tail (cdr lis))) ; Grab the cdr now, | |
292 | - (proc lis) ; in case PROC SET-CDR!s LIS. | |
293 | - (lp tail)))))) | |
294 | - | |
295 | -(define (filter-map f l1 . l) | |
296 | - (let loop ((l (cons l1 l)) (r '())) | |
297 | - (if (any null? l) | |
298 | - (reverse! r) | |
299 | - (let ((x (apply f (map car l)))) | |
300 | - (loop (map! cdr l) (if x (cons x r) r)))))) | |
301 | - | |
302 | - | |
303 | -;;@subheading Filtering and Partitioning | |
304 | - | |
305 | -;;@args pred list | |
306 | -(define (filter pred lis) ; Sleazing with EQ? makes this one faster. | |
307 | - (let recur ((lis lis)) | |
308 | - (if (null-list? lis) lis ; Use NOT-PAIR? to handle dotted lists. | |
309 | - (let ((head (car lis)) | |
310 | - (tail (cdr lis))) | |
311 | - (if (pred head) | |
312 | - (let ((new-tail (recur tail))) ; Replicate the RECUR call so | |
313 | - (if (eq? tail new-tail) lis | |
314 | - (cons head new-tail))) | |
315 | - (recur tail)))))) ; this one can be a tail call. | |
316 | -;;@args pred list | |
317 | -(define (filter! p? l) | |
318 | - (call-with-values (lambda () (partition! p? l)) | |
319 | - (lambda (x y) x))) | |
320 | - | |
321 | -;;@args pred list | |
322 | -(define (partition pred lis) | |
323 | - (let recur ((lis lis)) | |
324 | - (if (null-list? lis) (values lis lis) ; Use NOT-PAIR? to handle dotted lists. | |
325 | - (let ((elt (car lis)) | |
326 | - (tail (cdr lis))) | |
327 | - (call-with-values ; expanded a receive call | |
328 | - (lambda () (recur tail)) | |
329 | - (lambda (in out) | |
330 | - (if (pred elt) | |
331 | - (values (if (pair? out) (cons elt in) lis) out) | |
332 | - (values in (if (pair? in) (cons elt out) lis))))))))) | |
333 | - | |
334 | -;;@args pred list | |
335 | -(define remove | |
336 | - (let ((comlist:remove remove)) | |
337 | - (lambda (pred l) | |
338 | - (if (procedure? pred) | |
339 | - (filter (lambda (x) (not (pred x))) l) | |
340 | - (comlist:remove pred l))))) ; 'remove' has incompatible semantics in comlist of SLIB! | |
341 | - | |
342 | -;;@args pred list | |
343 | -(define (partition! p? l) | |
344 | - (if (null? l) | |
345 | - (values l l) | |
346 | - (let ((p-ptr (cons '*unused* l)) (not-ptr (cons '*unused* l))) | |
347 | - (let loop ((l l) (p-prev p-ptr) (not-prev not-ptr)) | |
348 | - (cond ((null? l) (values (cdr p-ptr) (cdr not-ptr))) | |
349 | - ((p? (car l)) (begin (set-cdr! not-prev (cdr l)) | |
350 | - (loop (cdr l) l not-prev))) | |
351 | - (else (begin (set-cdr! p-prev (cdr l)) | |
352 | - (loop (cdr l) p-prev l)))))))) | |
353 | - | |
354 | -;;@args pred list | |
355 | -(define (remove! pred l) (filter! (lambda (x) (not (pred x))) l)) | |
356 | - | |
357 | - | |
358 | -;;@subheading Searching | |
359 | - | |
360 | -;;@args pred clist | |
361 | -(define find find-if) | |
362 | -;;@args pred clist | |
363 | -(define find-tail member-if) | |
364 | - | |
365 | -;;@args pred list | |
366 | -(define (span pred lis) | |
367 | - (let recur ((lis lis)) | |
368 | - (if (null-list? lis) (values '() '()) | |
369 | - (let ((x (car lis))) | |
370 | - (if (pred x) | |
371 | - (call-with-values ; eliminated a receive call | |
372 | - (lambda () (recur (cdr lis))) | |
373 | - (lambda (prefix suffix) | |
374 | - (values (cons x prefix) suffix))) | |
375 | - (values '() lis)))))) | |
376 | - | |
377 | -;;@args pred list | |
378 | -(define (span! p? lst) | |
379 | - (let loop ((l lst) (prev (cons '*unused* lst))) | |
380 | - (cond ((null? l) (values lst '())) | |
381 | - ((p? (car l)) (loop (cdr l) l)) | |
382 | - (else (begin (set-cdr! prev '()) (values lst l)))))) | |
383 | - | |
384 | -;;@args pred list | |
385 | -(define (break p? l) (span (lambda (x) (not (p? x))) l)) | |
386 | -;;@args pred list | |
387 | -(define (break! p? l) (span! (lambda (x) (not (p? x))) l)) | |
388 | - | |
389 | -;;@args pred clist1 clist2 ... | |
390 | -(define (any pred lis1 . lists) | |
391 | - (if (pair? lists) | |
392 | - ;; N-ary case | |
393 | - (call-with-values ; expanded a receive call | |
394 | - (lambda () (%cars+cdrs (cons lis1 lists))) | |
395 | - (lambda (heads tails) | |
396 | - (and (pair? heads) | |
397 | - (let lp ((heads heads) (tails tails)) | |
398 | - (call-with-values ; expanded a receive call | |
399 | - (lambda () (%cars+cdrs tails)) | |
400 | - (lambda (next-heads next-tails) | |
401 | - (if (pair? next-heads) | |
402 | - (or (apply pred heads) (lp next-heads next-tails)) | |
403 | - (apply pred heads)))))))) ; Last PRED app is tail call. | |
404 | - ;; Fast path | |
405 | - (and (not (null-list? lis1)) | |
406 | - (let lp ((head (car lis1)) (tail (cdr lis1))) | |
407 | - (if (null-list? tail) | |
408 | - (pred head) ; Last PRED app is tail call. | |
409 | - (or (pred head) (lp (car tail) (cdr tail)))))))) | |
410 | -;;@args pred clist1 clist2 ... | |
411 | -(define (list-index pred lis1 . lists) | |
412 | - (if (pair? lists) | |
413 | - ;; N-ary case | |
414 | - (let lp ((lists (cons lis1 lists)) (n 0)) | |
415 | - (call-with-values ; expanded a receive call | |
416 | - (lambda () (%cars+cdrs lists)) | |
417 | - (lambda (heads tails) | |
418 | - (and (pair? heads) | |
419 | - (if (apply pred heads) n | |
420 | - (lp tails (+ n 1))))))) | |
421 | - ;; Fast path | |
422 | - (let lp ((lis lis1) (n 0)) | |
423 | - (and (not (null-list? lis)) | |
424 | - (if (pred (car lis)) n (lp (cdr lis) (+ n 1))))))) | |
425 | - | |
426 | -;;@args obj list = | |
427 | -;;@args obj list | |
428 | -(define member | |
429 | - (let ((old-member member)) | |
430 | - (lambda (obj list . pred) | |
431 | - (if (null? pred) | |
432 | - (old-member obj list) | |
433 | - (let ((pred (car pred))) | |
434 | - (find-tail (lambda (ob) (pred ob obj)) list)))))) | |
435 | - | |
436 | -;;@subheading Deleting | |
437 | - | |
438 | -;;@args x list = | |
439 | -;;@args x list | |
440 | -(define (delete-duplicates l =?) | |
441 | - (let loop ((l l) (r '())) | |
442 | - (if (null? l) | |
443 | - (reverse! r) | |
444 | - (loop (cdr l) | |
445 | - (if (member (car l) r =?) r (cons (car l) r)))))) | |
446 | -;;@args x list = | |
447 | -;;@args x list | |
448 | -(define delete-duplicates! delete-duplicates) | |
449 | - | |
450 | -;;@subheading Association lists | |
451 | - | |
452 | -;;@args obj alist pred | |
453 | -;;@args obj alist | |
454 | -(define assoc | |
455 | - (let ((old-assoc assoc)) | |
456 | - (lambda (obj alist . pred) | |
457 | - (if (null? pred) | |
458 | - (old-assoc obj alist) | |
459 | - (let ((pred (car pred))) | |
460 | - (find (lambda (pair) (pred obj (car pair))) alist)))))) | |
461 | - | |
462 | -;; XXX maybe define the following in alist and require that module here? | |
463 | - | |
464 | -;;@args key datum alist | |
465 | -(define (alist-cons k d l) (cons (cons k d) l)) | |
466 | - | |
467 | -;;@args alist | |
468 | -(define (alist-copy l) | |
469 | - (map (lambda (x) (cons (car x) (cdr x))) l)) | |
470 | - | |
471 | -;;@args key alist = | |
472 | -;;@args key alist | |
473 | -(define (alist-delete k l . opt) | |
474 | - (let ((key=? (if (pair? opt) (car opt) equal?))) | |
475 | - (remove (lambda (x) (key=? (car x) k)) l))) | |
476 | -;;@args key alist = | |
477 | -;;@args key alist | |
478 | -(define (alist-delete! k l . opt) | |
479 | - (let ((key=? (if (pair? opt) (car opt) equal?))) | |
480 | - (remove! (lambda (x) (key=? (car x) k)) l))) | |
481 | - | |
482 | -;;@subheading Set operations | |
483 | - | |
484 | -;;@args = list1 @dots{} | |
485 | -;;Determine if a transitive subset relation exists between the lists @2 | |
486 | -;;@dots{}, using @1 to determine equality of list members. | |
487 | -(define (lset<= =? . l) | |
488 | - (or (null? l) | |
489 | - (letrec ((subset? (lambda (l1 l2) | |
490 | - (or (eq? l1 l2) | |
491 | - (every (lambda (x) (member x l2)) l1))))) | |
492 | - (let loop ((l1 (car l)) (l (cdr l))) | |
493 | - (or (null? l) | |
494 | - (let ((l2 (car l))) | |
495 | - (and (subset? l1 l2) | |
496 | - (loop l2 (cdr l))))))))) | |
497 | - | |
498 | -;;@args = list1 list2 @dots{} | |
499 | -(define (lset= =? . l) | |
500 | - (or (null? l) | |
501 | - (let loop ((l1 (car l)) (l (cdr l))) | |
502 | - (or (null? l) | |
503 | - (let ((l2 (car l))) | |
504 | - (and (lset<= =? l1 l2) | |
505 | - (lset<= =? l2 l1) | |
506 | - (loop (if (< (length l1) (length l2)) l1 l2) | |
507 | - (cdr l)))))))) | |
508 | - | |
509 | -;;@args list elt1 @dots{} | |
510 | -(define (lset-adjoin =? l1 . l2) | |
511 | - (let ((adjoin (lambda (x l) | |
512 | - (if (member x l =?) l (cons x l))))) | |
513 | - (fold adjoin l1 l2))) | |
514 | - | |
515 | -;;@args = list1 @dots{} | |
516 | -(define (lset-union =? . l) | |
517 | - (let ((union (lambda (l1 l2) | |
518 | - (if (or (null? l2) (eq? l1 l2)) | |
519 | - l1 | |
520 | - (apply lset-adjoin (cons* =? l2 l1)))))) | |
521 | - (fold union '() l))) | |
522 | - | |
523 | -;;@args = list1 list2 @dots{} | |
524 | -(define (lset-intersection =? l1 . l) | |
525 | - (let loop ((l l) (r l1)) | |
526 | - (cond ((null? l) r) | |
527 | - ((null? (car l)) '()) | |
528 | - (else (loop (cdr l) | |
529 | - (filter (lambda (x) (member x (car l) =?)) r)))))) | |
530 | - | |
531 | -;;@args = list1 list2 ... | |
532 | -(define (lset-difference =? l1 . l) | |
533 | - (call-with-current-continuation | |
534 | - (lambda (return) | |
535 | - (let ((diff (lambda (l1 l2) | |
536 | - (cond ((null? l2) (return '())) | |
537 | - ((null? l1) l2) | |
538 | - (else (remove (lambda (x) (member x l1 =?)) | |
539 | - l2)))))) | |
540 | - (fold diff l1 l))))) | |
541 | - | |
542 | -;; Alternatively definition of lset-difference, for large numbers of sets. | |
543 | -;(define (lset-difference =? l1 . l) | |
544 | -; (set! l (cdr (delete-duplicates! (cons l1 l) eq?))) | |
545 | -; (case (length l) | |
546 | -; ((0) l1) | |
547 | -; ((1) (remove (lambda (x) (member x l1 =?)) (car l))) | |
548 | -; (else (apply (lset-difference! (cons* =? (list-copy l1) l)))))) | |
549 | - | |
550 | -;;@args = list1 ... | |
551 | -(define (lset-xor =? . l) | |
552 | - (let ((xor (lambda (l1 l2) (lset-union =? (lset-difference =? l1 l2) | |
553 | - (lset-difference =? l2 l1))))) | |
554 | - (fold xor '() l))) | |
555 | - | |
556 | -;;@args = list1 list2 ... | |
557 | -(define (lset-diff+intersection =? l1 . l) | |
558 | - (let ((u (apply lset-union (cons =? l)))) | |
559 | - (values (lset-difference =? l1 u) | |
560 | - (lset-intersection =? l1 u)))) | |
561 | - | |
562 | -;;@noindent | |
563 | -;;These are linear-update variants. They are allowed, but not | |
564 | -;;required, to use the cons cells in their first list parameter to | |
565 | -;;construct their answer. @code{lset-union!} is permitted to recycle | |
566 | -;;cons cells from any of its list arguments. | |
567 | - | |
568 | -;;@args = list1 list2 ... | |
569 | -(define lset-intersection! lset-intersection) | |
570 | -;;@args = list1 list2 ... | |
571 | -(define (lset-difference! =? l1 . l) | |
572 | - (let loop ((l l) (d l1)) | |
573 | - (if (or (null? l) (null? d)) | |
574 | - d | |
575 | - (loop (cdr l) | |
576 | - (let ((l1 (car l))) | |
577 | - (if (null? l1) d (remove! (lambda (x) (member x l1 =?)) d))))))) | |
578 | - | |
579 | -;;@args = list1 ... | |
580 | -(define (lset-union! =? . l) | |
581 | - (let loop ((l l) (u '())) | |
582 | - (if (null? l) | |
583 | - u | |
584 | - (loop (cdr l) | |
585 | - (cond ((null? (car l)) u) | |
586 | - ((eq? (car l) u) u) | |
587 | - ((null? u) (car l)) | |
588 | - (else (append-reverse! (lset-difference! =? (car l) u) | |
589 | - u))))))) | |
590 | -;;@args = list1 ... | |
591 | -(define lset-xor! lset-xor) | |
592 | - | |
593 | -;;@args = list1 list2 ... | |
594 | -(define lset-diff+intersection! lset-diff+intersection) | |
595 | - | |
596 | - | |
597 | -;;;; helper functions from the reference implementation: | |
598 | - | |
599 | -;;; LISTS is a (not very long) non-empty list of lists. | |
600 | -;;; Return two lists: the cars & the cdrs of the lists. | |
601 | -;;; However, if any of the lists is empty, just abort and return [() ()]. | |
602 | - | |
603 | -(define (%cars+cdrs lists) | |
604 | - (call-with-current-continuation | |
605 | - (lambda (abort) | |
606 | - (let recur ((lists lists)) | |
607 | - (if (pair? lists) | |
608 | - (call-with-values ; expanded a receive call | |
609 | - (lambda () (car+cdr lists)) | |
610 | - (lambda (list other-lists) | |
611 | - (if (null-list? list) (abort '() '()) ; LIST is empty -- bail out | |
612 | - (call-with-values ; expanded a receive call | |
613 | - (lambda () (car+cdr list)) | |
614 | - (lambda (a d) | |
615 | - (call-with-values ; expanded a receive call | |
616 | - (lambda () (recur other-lists)) | |
617 | - (lambda (cars cdrs) | |
618 | - (values (cons a cars) (cons d cdrs))))))))) | |
619 | - (values '() '())))))) | |
620 | - | |
621 | -;;; Like %CARS+CDRS, but blow up if any list is empty. | |
622 | -(define (%cars+cdrs/no-test lists) | |
623 | - (let recur ((lists lists)) | |
624 | - (if (pair? lists) | |
625 | - (call-with-values ; expanded a receive call | |
626 | - (lambda () (car+cdr lists)) | |
627 | - (lambda (list other-lists) | |
628 | - (call-with-values ; expanded a receive call | |
629 | - (lambda () (car+cdr list)) | |
630 | - (lambda (a d) | |
631 | - (call-with-values ; expanded a receive call | |
632 | - (lambda () (recur other-lists)) | |
633 | - (lambda (cars cdrs) | |
634 | - (values (cons a cars) (cons d cdrs)))))))) | |
635 | - (values '() '())))) | |
636 | - | |
637 | -(define (%cdrs lists) | |
638 | - (call-with-current-continuation | |
639 | - (lambda (abort) | |
640 | - (let recur ((lists lists)) | |
641 | - (if (pair? lists) | |
642 | - (let ((lis (car lists))) | |
643 | - (if (null-list? lis) (abort '()) | |
644 | - (cons (cdr lis) (recur (cdr lists))))) | |
645 | - '()))))) |
@@ -49,8 +49,8 @@ | ||
49 | 49 | (begin |
50 | 50 | (guard (err |
51 | 51 | (else |
52 | - ;; currently not working | |
53 | - ;;(%%backtrace) | |
52 | + (display err) | |
53 | + (%%backtrace) | |
54 | 54 | #f)) |
55 | 55 | ((if uim-sh-opt-strict-batch |
56 | 56 | (lambda (obj) #f) |
@@ -44,6 +44,7 @@ static void *uim_scm_symbol_value_int_internal(const char *symbol_str); | ||
44 | 44 | static char *uim_scm_symbol_value_str_internal(const char *symbol_str); |
45 | 45 | #endif |
46 | 46 | |
47 | +extern uim_lisp uim_scm_last_val; | |
47 | 48 | static uim_lisp return_val; |
48 | 49 | |
49 | 50 | /* will be deprecated. use uim_scm_c_str() instead */ |
@@ -56,8 +57,7 @@ uim_get_c_string(uim_lisp str) | ||
56 | 57 | long |
57 | 58 | uim_scm_repl_c_string(char *str, long want_init, long want_print) |
58 | 59 | { |
59 | - /* TODO: fix return value */ | |
60 | - scm_eval_c_string(str); | |
60 | + uim_scm_last_val = scm_eval_c_string(str); | |
61 | 61 | |
62 | 62 | return 0; |
63 | 63 | } |
@@ -221,42 +221,32 @@ uim_scm_nth(uim_lisp n, uim_lisp lst) | ||
221 | 221 | uim_lisp |
222 | 222 | uim_scm_list1(uim_lisp elm1) |
223 | 223 | { |
224 | - uim_lisp lst; | |
225 | - lst = uim_scm_cons(elm1, uim_scm_null_list()); | |
226 | - return lst; | |
224 | + return uim_scm_cons(elm1, uim_scm_null_list()); | |
227 | 225 | } |
228 | 226 | |
229 | 227 | uim_lisp |
230 | 228 | uim_scm_list2(uim_lisp elm1, uim_lisp elm2) |
231 | 229 | { |
232 | - uim_lisp lst; | |
233 | - lst = uim_scm_cons(elm1, uim_scm_cons(elm2, uim_scm_null_list())); | |
234 | - return lst; | |
230 | + return uim_scm_cons(elm1, uim_scm_list1(elm2)); | |
235 | 231 | } |
236 | 232 | |
237 | 233 | uim_lisp |
238 | 234 | uim_scm_list3(uim_lisp elm1, uim_lisp elm2, uim_lisp elm3) |
239 | 235 | { |
240 | - uim_lisp lst; | |
241 | - lst = uim_scm_cons(elm1, uim_scm_cons(elm2, uim_scm_cons(elm3, uim_scm_null_list()))); | |
242 | - return lst; | |
236 | + return uim_scm_cons(elm1, uim_scm_list2(elm2, elm3)); | |
243 | 237 | } |
244 | 238 | |
245 | 239 | uim_lisp |
246 | 240 | uim_scm_list4(uim_lisp elm1, uim_lisp elm2, uim_lisp elm3, uim_lisp elm4) |
247 | 241 | { |
248 | - uim_lisp lst; | |
249 | - lst = uim_scm_cons(elm1, uim_scm_list3(elm2, elm3, elm4)); | |
250 | - return lst; | |
242 | + return uim_scm_cons(elm1, uim_scm_list3(elm2, elm3, elm4)); | |
251 | 243 | } |
252 | 244 | |
253 | 245 | uim_lisp |
254 | 246 | uim_scm_list5(uim_lisp elm1, uim_lisp elm2, uim_lisp elm3, uim_lisp elm4, |
255 | 247 | uim_lisp elm5) |
256 | 248 | { |
257 | - uim_lisp lst; | |
258 | - lst = uim_scm_cons(elm1, uim_scm_cons(elm2, uim_scm_list3(elm3, elm4, elm5))); | |
259 | - return lst; | |
249 | + return uim_scm_cons(elm1, uim_scm_list4(elm2, elm3, elm4, elm5)); | |
260 | 250 | } |
261 | 251 | |
262 | 252 | /* Is this function used from somewhere? I think this function could be removed. */ |
@@ -124,12 +124,6 @@ struct uim_context_ { | ||
124 | 124 | }; |
125 | 125 | |
126 | 126 | |
127 | -/* | |
128 | - Most of following definitions should be separated into another file such as | |
129 | - private.h since they are not relevant to input contexts. I'm not having | |
130 | - enough time to do and validate it. Anyone? -- YamaKen 2005-07-30 | |
131 | -*/ | |
132 | - | |
133 | 127 | #if 0 |
134 | 128 | /* |
135 | 129 | Evaluating a S-expression in C involves the two problems, performance and |
@@ -49,6 +49,7 @@ | ||
49 | 49 | #include <stdlib.h> |
50 | 50 | #include <string.h> |
51 | 51 | #include <ctype.h> |
52 | + | |
52 | 53 | #include "uim-stdint.h" |
53 | 54 | #include "uim-scm.h" |
54 | 55 | #include "uim-compat-scm.h" |
@@ -77,7 +78,7 @@ static const char *uim_scm_refer_c_str_internal(void *uim_lisp_str); | ||
77 | 78 | static void *uim_scm_eval_internal(void *uim_lisp_obj); |
78 | 79 | #endif |
79 | 80 | |
80 | -static uim_lisp last_val; | |
81 | +uim_lisp uim_scm_last_val; | |
81 | 82 | static uim_bool sscm_is_exit_with_fatal_error; |
82 | 83 | static FILE *uim_output = NULL; |
83 | 84 |
@@ -249,7 +250,7 @@ uim_scm_make_str(const char *str) | ||
249 | 250 | char * |
250 | 251 | uim_scm_c_symbol(uim_lisp symbol) |
251 | 252 | { |
252 | - return strdup((char*)SCM_SYMBOL_NAME((ScmObj)symbol)); | |
253 | + return strdup((char *)SCM_SYMBOL_NAME((ScmObj)symbol)); | |
253 | 254 | } |
254 | 255 | |
255 | 256 | uim_lisp |
@@ -450,16 +451,16 @@ uim_scm_eval_internal(void *uim_lisp_obj) | ||
450 | 451 | uim_lisp |
451 | 452 | uim_scm_eval_c_string(const char *str) |
452 | 453 | { |
453 | - last_val = (uim_lisp)scm_eval_c_string(str); | |
454 | + uim_scm_last_val = (uim_lisp)scm_eval_c_string(str); | |
454 | 455 | |
455 | - return last_val; | |
456 | + return uim_scm_last_val; | |
456 | 457 | } |
457 | 458 | |
458 | 459 | uim_lisp |
459 | 460 | uim_scm_return_value(void) |
460 | 461 | { |
461 | 462 | /* FIXME: This function should be removed. */ |
462 | - return last_val; | |
463 | + return uim_scm_last_val; | |
463 | 464 | } |
464 | 465 | |
465 | 466 | uim_lisp |
@@ -507,6 +508,10 @@ uim_scm_cons(uim_lisp car, uim_lisp cdr) | ||
507 | 508 | uim_lisp |
508 | 509 | uim_scm_length(uim_lisp lst) |
509 | 510 | { |
511 | + /* | |
512 | + although nlength() of siod returns length of anything, this | |
513 | + function should be called only for list | |
514 | + */ | |
510 | 515 | return (uim_lisp)scm_p_length((ScmObj)lst); |
511 | 516 | } |
512 | 517 |
@@ -574,7 +579,7 @@ exit_hook(void) | ||
574 | 579 | sscm_is_exit_with_fatal_error = UIM_TRUE; |
575 | 580 | /* FIXME: Add longjmp() to outermost uim API call, and make all API |
576 | 581 | * calls uim_scm_is_alive()-sensitive. It should be fixed on uim |
577 | - * 1.3. -- YamaKen 2006-06-06 */ | |
582 | + * 1.5. -- YamaKen 2006-06-06, 2006-12-27 */ | |
578 | 583 | } |
579 | 584 | |
580 | 585 | void |
@@ -624,7 +629,7 @@ uim_scm_init(const char *verbose_level) | ||
624 | 629 | scm_use("srfi-34"); |
625 | 630 | scm_use("siod"); |
626 | 631 | |
627 | - uim_scm_gc_protect(&last_val); | |
632 | + uim_scm_gc_protect(&uim_scm_last_val); | |
628 | 633 | uim_scm_set_verbose_level(vlevel); |
629 | 634 | } |
630 | 635 |
@@ -58,16 +58,6 @@ | ||
58 | 58 | extern "C" { |
59 | 59 | #endif |
60 | 60 | |
61 | -/* | |
62 | - UIM_SCM_EXTENDED_API indicates that the interfaces are extended in | |
63 | - the r5rs barnch. Some of interfaces are re-adopted from | |
64 | - uim-compat-scm.h. Since it contradicts with the "core interface | |
65 | - policy" described above (2005-01-10 YamaKen), it must be | |
66 | - distinguished from original ones for now. A discussion may be | |
67 | - required to make the new API standard before next stable series | |
68 | - has been released. -- YamaKen 2005-07-29 | |
69 | -*/ | |
70 | -#define UIM_SCM_EXTENDED_API | |
71 | 61 | |
72 | 62 | #define UIM_SCM_GCC4_READY_GC 1 |
73 | 63 |
@@ -42,7 +42,6 @@ | ||
42 | 42 | #include "uim.h" |
43 | 43 | #include "uim-im-switcher.h" |
44 | 44 | #include "uim-scm.h" |
45 | -#include "uim-compat-scm.h" | |
46 | 45 | #include "uim-custom.h" |
47 | 46 | #include "uim-internal.h" |
48 | 47 | #include "gettext.h" |
@@ -196,19 +195,7 @@ uim_create_context(void *ptr, | ||
196 | 195 | uim_last_client_encoding = strdup(enc); |
197 | 196 | } |
198 | 197 | |
199 | -#ifdef UIM_EVAL_SEXP_AS_STRING | |
200 | 198 | UIM_EVAL_FSTRING3(uc, "(create-context %d '%s '%s)", uc->id, lang, engine); |
201 | -#else | |
202 | - { | |
203 | - uim_lisp id_ = uim_scm_make_int(uc->id); | |
204 | - uim_lisp lang_ = uim_scm_quote(uim_scm_make_symbol(lang)); | |
205 | - uim_lisp engine_ = uim_scm_quote(uim_scm_make_symbol(engine)); | |
206 | - uim_lisp proc = uim_scm_make_symbol("create-context"); | |
207 | - uim_lisp form = uim_scm_list4(proc, id_, lang_, engine_); | |
208 | - | |
209 | - uim_scm_eval(form); | |
210 | - } | |
211 | -#endif /* UIM_EVAL_SEXP_AS_STRING */ | |
212 | 199 | return uc; |
213 | 200 | } |
214 | 201 |
@@ -85,11 +85,9 @@ static const char *candwin_command(void) | ||
85 | 85 | |
86 | 86 | user_config = getenv("UIM_CANDWIN_PROG"); |
87 | 87 | #ifdef UIM_COMPAT_SCM |
88 | -#if 0 | |
89 | 88 | if (!user_config) |
90 | 89 | user_config = uim_scm_symbol_value_str("uim-candwin-prog"); |
91 | 90 | #endif |
92 | -#endif | |
93 | 91 | |
94 | 92 | if (user_config) { |
95 | 93 | asprintf(&candwin_prog, UIM_LIBEXECDIR "/%s", user_config); |