srfi-14.stk 20.3 KB
Newer Older
eg's avatar
eg committed
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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
;;;;
;;;; srfi-14.stk	-- Implementation of SRFI-14
;;;; 
;;;; Copyright © 2002 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
;;;; 
;;;; 
;;;; This program 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 2 of the License, or
;;;; (at your option) any later version.
;;;; 
;;;; This program 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 this program; if not, write to the Free Software
;;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
;;;; USA.
;;;; 
;;;; This file uses some work from the Olin Shivers implementation of
;;;; this SRFI. See the end of this file for the tedious details of the
;;;; original copyright
;;;;
;;;;           Author: Erick Gallesio [eg@essi.fr]
;;;;    Creation date: 14-Jun-2002 21:36 (eg)
;;;; Last file update: 31-Jul-2002 23:31 (eg)
;;;;

;;;
;;; This implementation uses a bignum to represent a character set. Union 
;;; Intersection (and so on) on character sets is implemented with STklos
;;; bit operations on integers.



(define-module SRFI-14
  (export  ;; Predicates & comparison
	   char-set? char-set= char-set<= char-set-hash

	   ;; Iterating over character sets
	   char-set-cursor char-set-ref char-set-cursor-next end-of-char-set? 
	   char-set-fold char-set-unfold char-set-unfold!
	   char-set-for-each char-set-map

	   ;; Creating character sets
	   char-set-copy char-set

	   list->char-set  string->char-set
	   list->char-set! string->char-set!
    
	   char-set-filter  ucs-range->char-set 
	   char-set-filter! ucs-range->char-set!

	   ->char-set

	   ;; Querying character sets
	   char-set->list char-set->string
	   char-set-size char-set-count char-set-contains?
	   char-set-every char-set-any

	   ;; Character-set algebra
	   char-set-adjoin  char-set-delete
	   char-set-adjoin! char-set-delete!

	   char-set-complement  char-set-union  char-set-intersection
	   char-set-complement! char-set-union! char-set-intersection!

	   char-set-difference  char-set-xor  char-set-diff+intersection
	   char-set-difference! char-set-xor! char-set-diff+intersection!
	   
	   ;; Standard character sets
	   
	   char-set:lower-case  char-set:upper-case  char-set:title-case
	   char-set:letter      char-set:digit       char-set:letter+digit
	   char-set:graphic     char-set:printing    char-set:whitespace
	   char-set:iso-control char-set:punctuation char-set:symbol
	   char-set:hex-digit   char-set:blank       char-set:ascii
	   char-set:empty       char-set:full)


(define-macro (check-arg pred val caller)
  `(if (,pred ,val) 
       ,val 
       (error ,caller "bad argument ~S" ,val)))

;;;
;;; The class which defines a character set
;;; 
(define-class <char-set> ()
  ((value :init-form 0 :init-keyword :value)))

(define %full-set-val (- (expt 2 256) 1))

(define (%is-in? csv i)
  (positive? (bit-and csv (expt 2 i))))

(define (%char-set-add1-char csv c)
  (bit-or csv (expt 2 (char->integer c))))

(define (%char-set-del1-char csv c)
  (let ((bit (expt 2 (char->integer c))))
    (if (positive? (bit-and csv bit))
	(- csv bit)
	csv)))

(define (%char-set-add1-int csv i)
  (bit-or csv (expt 2 i)))

(define (%make-char-set-from-integer v)
  (make <char-set> :value v))

(define (%char-set-value-set! cs v)
  (slot-set! cs 'value v))

(define (%char-set-copy cs)
  (deep-clone cs))

(define (make-char-set . l)
  (let ((v 0))
    (for-each (lambda (x)
		(unless (char? x)
		  (error 'make-char-set "bad character ~S" x))
		(set! v (%char-set-add1-char v x)))
	      l)
    (%make-char-set-from-integer v)))

(define (%char-set-val cs proc)
  (unless (is-a? cs <char-set>)
    (error proc "bad char set ~S" cs))
  (slot-ref cs 'value))

(define %latin1->char integer->char)

(define (%char-set-add proc cs . l)
  (let ((v (%char-set-val cs proc)))
    (for-each (lambda (x)
		(set! v (%char-set-add1-char v x)))
	      l)
    (slot-set! cs 'value v)))

;;;; ======================================================================
;;;;
;;;;  			G E N E R A L   P R O C E D U R E S
;;;;
;;;; ======================================================================
(define (char-set? x)
  (is-a? x <char-set>))

(define (char-set= . rest)
  (if (null? rest)
      #t
      (let ((l (map (lambda (x) (%char-set-val x 'char-set=)) rest)))
	(apply = l))))

(define (char-set<= . rest)
  (let ((<=? (lambda (v1 v2) (= (bit-and v1 v2) v1)))
	(l   (map (lambda (x) (%char-set-val x 'char-set<=)) rest)))
    (let Loop ((l l))
      (cond
	((null? l) #t)
	((null? (cdr l)) #t)
	(else (and (<=? (car l) (cadr l))
		   (Loop (cdr l))))))))

(define (char-set-hash cs :optional (bound 0))
  (let ((h (%char-set-val cs 'char-set-hash)))
    (if (positive? bound)
	(modulo h bound)
	h)))

;;;; ======================================================================
;;;;
;;;;  				I T E R A T I O N
;;;;
;;;; ======================================================================
(define (%valid-cursor cursor proc)
  (unless cursor
    (error proc "end of char set"))
  (unless (and (integer? cursor) (<= 0 cursor 255))
    (error proc "bad cursor ~S" cursor)))

(define (%char-set-unfold! proc p f g seed base-cs)
  (check-arg procedure? p proc)
  (check-arg procedure? f proc)
  (check-arg procedure? g proc)
  (let Loop ((seed seed))
    (if (p seed)
        base-cs
        (let ((c (f seed)))
          (%char-set-add (void) base-cs c)
          (Loop (g seed))))))

;;;
;;; Exported procedures
;;;
(define (char-set-cursor cs)
  (let ((v (%char-set-val cs 'char-set-cursor)))
    (let Loop ((i 0))
      (cond
	((= i 256) #f)
	((%is-in? v i) i)
	(else (Loop (+ i 1)))))))

(define (char-set-ref cset cursor)
  (%valid-cursor cursor 'char-set-cursor)
  (%latin1->char cursor))

(define (char-set-cursor-next cs cursor)
  (%valid-cursor cursor 'char-set-cursor-next)
  (let ((v (%char-set-val cs 'char-set-cursor-next)))
    (let Loop ((i (+ cursor 1)))
      (cond
	((= i 256) #f)
	((%is-in? v i) i)
	(else (Loop (+ i 1)))))))

(define (end-of-char-set? cursor)
  (not cursor))

(define (char-set-fold kons knil cs)
  (check-arg procedure? kons 'char-set-fold)
  (let ((v (%char-set-val cs 'char-set-fold)))
    (let Loop ((i 255) (res knil))
      (if (< i 0)
	  res
	  (Loop (- i 1) (if (%is-in? v i)
			    (kons (%latin1->char i) res)
			    res))))))

(define (char-set-unfold p f g seed :optional (base-set #f base-set?))
  (let ((base-set (if base-set?
		      (if (char-set? base-set)
			  (%char-set-copy base-set)
			  (error "bad char set ~S" base-set))
		      (make-char-set))))
    (%char-set-unfold! 'char-set-unfold p f g seed base-set)))

(define (char-set-unfold! p f g seed base-set)
  (%char-set-unfold! 'char-set-unfold! p f g seed base-set))

(define (char-set-for-each proc cs)
  (check-arg procedure? proc 'char-set-for-each)
  (let ((v (%char-set-val cs 'char-set-for-each)))
    (let Loop ((i 0))
      (when (< i 256)
	(if (%is-in? v i)
	    (proc (%latin1->char i)))
	(Loop (+ i 1))))))

(define (char-set-map proc cs)
  (check-arg procedure? proc 'char-set-map)
  (let ((v   (%char-set-val cs 'char-set-map))
	(new 0))
    (let Loop ((i 0))
      (when (< i 256)
	(if (%is-in? v i)
	    (set! new (%char-set-add1-char new (proc (%latin1->char i)))))
	(Loop (+ i 1))))
    (%make-char-set-from-integer new)))

;;;; ======================================================================
;;;;
;;;;  		C H A R A C T E R   S E T S   C R E A T I O N
;;;;
;;;; ======================================================================
(define (%char-set-filter! pred cs bs proc)
  (check-arg procedure? pred proc)
  (let ((v   (%char-set-val cs proc))
	(new (%char-set-val bs proc)))
    (let Loop ((i 255))
      (when (>= i 0)
	(let ((char (%latin1->char i)))
	  (when (and (%is-in? v i) (pred char))
	    (set! new (%char-set-add1-char new char))))
	(Loop (- i 1))))
    (%char-set-value-set! bs new)))

;;;
;;; Exported procedures
;;;
(define char-set-copy %char-set-copy)

(define char-set make-char-set)

(define (list->char-set lst :optional (base-set #f base-set?))
  (let ((base-set (if base-set?
		      (if (char-set? base-set)
			  (%char-set-copy base-set)
			  (error "bad char set ~S" base-set))
		      (make-char-set))))
    (apply %char-set-add 'list->char-set base-set lst)
    base-set))

(define (list->char-set! lst base-set)
  (apply %char-set-add 'list->char-set! base-set lst)
  base-set ;; This is requested by SRFI-14 but I find it awfull
)

(define (string->char-set str :optional (base-set #f base-set?))
  (if base-set?
      (list->char-set (string->list str) base-set)
      (list->char-set (string->list str))))

(define (string->char-set! str base-set)
  (list->char-set! (string->list str) base-set))

(define (char-set-filter predicate cs :optional (base-set #f base-set?))
  (let ((base-set (if base-set?
		      (if (char-set? base-set)
			  (%char-set-copy base-set)
			  (error "bad char set ~S" base-set))
		      (make-char-set))))
    (%char-set-filter! predicate
		       cs
		       base-set
		       'char-set-filter)
    base-set))

(define (char-set-filter! predicate cs base-set)
  (%char-set-filter! predicate
		     cs
		     base-set
		     'char-set-filter!)
  base-set)

  
(define (%ucs-range->char-set! lower upper error? bs proc)
  (check-arg (lambda (x) (and (integer? x) (exact? x) (<= 0 x))) lower proc)
  (check-arg (lambda (x) (and (integer? x) (exact? x) (<= lower x))) upper proc)
  
  (when (and error? (< lower upper) (< 256 upper))
    (error proc
	   (string-append "Requested UCS range contains unavailable characters"
			  " -- this implementation only supports Latin-1"
			  " -- ~S ~S"
			  lower upper)))
  (let ((v (%char-set-val bs proc)))
    (let Loop ((i (- (min upper 256) 1)))
      (when (<= lower i)
	(set! v (%char-set-add1-int v i))
	(Loop (- i 1))))
    (%char-set-value-set! bs v)))

(define (ucs-range->char-set lower upper
			     :optional (error? #f) (base-set #f base-set?))
  (let ((base-set (if base-set?
		      (if (char-set? base-set)
			  (%char-set-copy base-set)
			  (error 'ucs-range->char-set "bad char set ~S" base-set))
		      (make-char-set))))
    (%ucs-range->char-set! lower upper error? base-set 'ucs-range->char-set)
    base-set))

(define (ucs-range->char-set! lower upper error? base-set)
  (%ucs-range->char-set! lower upper error? base-set 'ucs-range->char-set)
  base-set)

(define (->char-set x)
  (cond
    ((char-set? x) x)
    ((string? x)   (string->char-set x))
    ((char? x)     (char-set x))
    (else          (error '->char-set "not a charset, string or char. ~S" x))))

;;;; ======================================================================
;;;;
;;;;		Q U E R Y I N G   C H A R A C T E R   S E T S
;;;;
;;;; ======================================================================
(define (char-set-size cs)
  (check-arg char-set? cs 'char-set-size)
  (char-set-fold (lambda (c i) (+ i 1)) 0 cs))

(define (char-set-count pred cs)
  (check-arg procedure? pred 'char-set-count)
  (let ((v (%char-set-val cs 'char-set-count)))
    (let Loop ((i 255) (count 0))
      (if (< i 0)
	  count
	  (Loop (- i 1) (if (and (%is-in? v i) (pred (%latin1->char i)))
			    (+ count 1)
			    count))))))

(define (char-set->list cs)
  (check-arg char-set? cs 'char-set->list)
  (let Loop ((v (slot-ref cs 'value)) (i 0))
    (cond
      ((zero? v) '())
      ((odd? v)  (cons (integer->char i) (Loop (quotient v 2) (+ i 1))))
      (else      (Loop (quotient v 2) (+ i 1))))))

(define (char-set->string cs)
  (check-arg char-set? cs 'char-set->string)
  (list->string (char-set->list cs)))

(define (char-set-contains? cs char)
  (check-arg char? char 'char-set-contains?)
  (let ((v (%char-set-val cs 'char-set-contains?)))
    (%is-in? v (char->integer char))))

(define (char-set-every pred cs)
  (check-arg procedure? pred 'char-set-every)
  (let ((v (%char-set-val cs 'char-set-every)))
    (let Loop ((i 255))
      (or (< i 0)
	  (and (or (not (%is-in? v i)) (pred (%latin1->char i)))
	       (Loop (- i 1)))))))

(define (char-set-any pred cs)
  (check-arg procedure? pred 'char-set-any)
  (let ((v (%char-set-val cs 'char-set-any)))
    (let Loop ((i 255))
      (and (>= i 0)
	   (or (and (%is-in? v i) (pred (%latin1->char i)))
	       (Loop (- i 1)))))))


;;;; ======================================================================
;;;;
;;;;		C H A R A C T E R - S E T   A L G E B R A 
;;;;
;;;; ======================================================================

(define (%char-set-setop proc-name default bit-op)
  (lambda cs
    (let ((v (cond
	     ((null? cs)	default)
	     ((null? (cdr cs)) (%char-set-val (car cs) proc-name))
	     (else
	      (let ((v default))
		(for-each (lambda (x)
			    (set! v (bit-op v (%char-set-val x proc-name))))
			  cs)
		v)))))
      (%make-char-set-from-integer v))))

(define (%char-set-setop! proc-name default bit-op)
  (lambda cs
    (let* ((ref #f)
	   (v   (cond
		  ((null? cs)	  default)
		  ((null? (cdr cs)) (%char-set-val (car cs) proc-name))
		  (else
		   (set! ref (car cs))
		   (let ((v default))
		     (for-each (lambda (x)
				 (set! v (bit-op v (%char-set-val x proc-name))))
			       cs)
		     v)))))
      (if ref
	  (begin (%char-set-value-set! ref v) ref)
	  (%make-char-set-from-integer v)))))
;;;
;;; Exported procedures
;;;
(define (char-set-adjoin cs . chars)
  (let ((v (%char-set-val cs 'char-set-adjoin)))
    (for-each (lambda (x) (set! v (%char-set-add1-char v x)))
	      chars)
    (%make-char-set-from-integer v)))

(define (char-set-delete cs . chars)
  (let ((v (%char-set-val cs 'char-set-delete)))
    (for-each (lambda (x) (set! v (%char-set-del1-char v x)))
	      chars)
    (%make-char-set-from-integer v)))

(define (char-set-adjoin! cs . chars)
  (let ((v (%char-set-val cs 'char-set-adjoin!)))
    (for-each (lambda (x) (set! v (%char-set-add1-char v x)))
	      chars)
    (%char-set-value-set! cs v)
    cs))

(define (char-set-delete! cs . chars)
  (let ((v (%char-set-val cs 'char-set-delete!)))
    (for-each (lambda (x) (set! v (%char-set-del1-char v x)))
	      chars)
    (%char-set-value-set! cs v)
    cs))

(define (char-set-complement cs)
  (let ((v (%char-set-val cs 'char-set-complement)))
    (%make-char-set-from-integer (bit-xor v %full-set-val))))

(define char-set-union
  (%char-set-setop 'char-set-union 0 bit-or))

(define char-set-intersection
  (%char-set-setop 'char-set-intersection %full-set-val bit-and))

(define char-set-xor
  (%char-set-setop 'char-set-xor 0 bit-xor))

(define (char-set-diff+intersection cs1 . cs)
  (char-set-intersection cs1 (apply char-set-union cs)))

(define (char-set-complement! cs)
  (let ((v (%char-set-val cs 'char-set-complement)))
    (%char-set-value-set! cs (bit-xor v %full-set-val))
    cs))

(define char-set-union!
  (%char-set-setop! 'char-set-union! 0 bit-or))

(define char-set-intersection!
  (%char-set-setop! 'char-set-intersection! %full-set-val bit-and))

(define char-set-xor!
  (%char-set-setop! 'char-set-xor! 0 bit-xor))

(define (char-set-diff+intersection! cs1 . cs)
  (char-set-intersection! cs1 (apply char-set-union! cs)))

;;;; ======================================================================
;;;;
;;;;		   S T A N D A R D   C H A R A C T E R   S E T S
;;;;
;;;; ======================================================================
(define char-set:full  (%make-char-set-from-integer %full-set-val))
(define char-set:empty (%make-char-set-from-integer 0))


(define char-set:lower-case
  (let* ((a-z (ucs-range->char-set #x61 #x7B))
	 (latin1 (ucs-range->char-set! #xdf #xf7  #t a-z))
	 (latin2 (ucs-range->char-set! #xf8 #x100 #t latin1)))
    (char-set-adjoin! latin2 (%latin1->char #xb5))))

(define char-set:upper-case
  (let ((A-Z (ucs-range->char-set #x41 #x5B)))
    ;; Add in the Latin-1 upper-case chars.
    (ucs-range->char-set! #xd8 #xdf #t
			  (ucs-range->char-set! #xc0 #xd7 #t A-Z))))

(define char-set:title-case char-set:empty)

(define char-set:letter
  (let ((u/l (char-set-union char-set:upper-case char-set:lower-case)))
    (char-set-adjoin! u/l
		      (%latin1->char #xaa)	; FEMININE ORDINAL INDICATOR
		      (%latin1->char #xba))))

(define char-set:digit     (string->char-set "0123456789"))

(define char-set:letter+digit
  (char-set-union char-set:letter char-set:digit))

(define char-set:whitespace
  (list->char-set (map %latin1->char '(#x09 ; HORIZONTAL TABULATION
				       #x0A ; LINE FEED		
				       #x0B ; VERTICAL TABULATION
				       #x0C ; FORM FEED
				       #x0D ; CARRIAGE RETURN
				       #x20 ; SPACE
				       #xA0))))
(define char-set:iso-control
  (ucs-range->char-set! #x7F #xA0 #t (ucs-range->char-set 0 32)))

(define char-set:punctuation
  (let ((ascii (string->char-set "!\"#%&'()*,-./:;?@[\\]_{}"))
	(latin-1-chars (map %latin1->char
			    '(#xA1 ; INVERTED EXCLAMATION MARK
			      #xAB ; LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
			      #xAD ; SOFT HYPHEN
			      #xB7 ; MIDDLE DOT
			      #xBB ; RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
			      #xBF)))) ; INVERTED QUESTION MARK
    (list->char-set! latin-1-chars ascii)))

(define char-set:symbol
  (let ((ascii (string->char-set "$+<=>^`|~"))
	(latin-1-chars (map %latin1->char '(#x00A2 ; CENT SIGN
					    #x00A3 ; POUND SIGN
					    #x00A4 ; CURRENCY SIGN
					    #x00A5 ; YEN SIGN
					    #x00A6 ; BROKEN BAR
					    #x00A7 ; SECTION SIGN
					    #x00A8 ; DIAERESIS
					    #x00A9 ; COPYRIGHT SIGN
					    #x00AC ; NOT SIGN
					    #x00AE ; REGISTERED SIGN
					    #x00AF ; MACRON
					    #x00B0 ; DEGREE SIGN
					    #x00B1 ; PLUS-MINUS SIGN
					    #x00B4 ; ACUTE ACCENT
					    #x00B6 ; PILCROW SIGN
					    #x00B8 ; CEDILLA
					    #x00D7 ; MULTIPLICATION SIGN
					    #x00F7)))) ; DIVISION SIGN
    (list->char-set! latin-1-chars ascii)))

(define char-set:hex-digit (string->char-set "0123456789abcdefABCDEF"))

(define char-set:blank
  (list->char-set (map %latin1->char '(#x09     ; HORIZONTAL TABULATION
				       #x20     ; SPACE
				       #xA0)))) ; NO-BREAK SPACE

(define char-set:ascii (ucs-range->char-set 0 128))

(define char-set:graphic
  (char-set-union char-set:letter+digit char-set:punctuation char-set:symbol))

(define char-set:printing (char-set-union char-set:whitespace char-set:graphic))

) ;; END OF DEFINE-MODULE
;;;; ======================================================================
(select-module STklos)
(import SRFI-14)

(provide "srfi-14")

;;; Copyright notice
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Copyright (c) 1988-1995 Massachusetts Institute of Technology
;;; 
;;; This material was developed by the Scheme project at the Massachusetts
;;; Institute of Technology, Department of Electrical Engineering and
;;; Computer Science.  Permission to copy and modify this software, to
;;; redistribute either the original software or a modified version, and
;;; to use this software for any purpose is granted, subject to the
;;; following restrictions and understandings.
;;; 
;;; 1. Any copy made of this software must include this copyright notice
;;; in full.
;;; 
;;; 2. Users of this software agree to make their best efforts (a) to
;;; return to the MIT Scheme project any improvements or extensions that
;;; they make, so that these may be included in future releases; and (b)
;;; to inform MIT of noteworthy uses of this software.
;;; 
;;; 3. All materials developed as a consequence of the use of this
;;; software shall duly acknowledge such use, in accordance with the usual
;;; standards of acknowledging credit in academic research.
;;; 
;;; 4. MIT has made no warrantee or representation that the operation of
;;; this software will be error-free, and MIT is under no obligation to
;;; provide any services, by way of maintenance, update, or otherwise.
;;; 
;;; 5. In conjunction with products arising from the use of this material,
;;; there shall be no use of the name of the Massachusetts Institute of
;;; Technology nor of any adaptation thereof in any advertising,
;;; promotional, or sales literature without prior written consent from
;;; MIT in each case.






#|
For tests
(define cs1 (make-char-set #\a #\b #\d))
(define cs2 (make-char-set #\a #\b #\d #\e))
(define cs3 (make-char-set #\a #\b))
(define cs4 (make-char-set #\x #\y))
(define cs5 (string->char-set
	     "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"))
(define cs6 (make-char-set #\A #\B #\space))

(char-set->list (char-set-filter! char-upper-case? cs5 cs2))
|#