Fixed a bug in enum-set-universe not returning an enum type.
This commit is contained in:
parent
3bcc3249e5
commit
b5fc5624ec
|
@ -31,15 +31,23 @@
|
||||||
(opaque #t) (sealed #t)
|
(opaque #t) (sealed #t)
|
||||||
(nongenerative))
|
(nongenerative))
|
||||||
|
|
||||||
|
(define (remove-dups ls)
|
||||||
|
(cond
|
||||||
|
[(null? ls) '()]
|
||||||
|
[else (cons (car ls) (remq (car ls) (cdr ls)))]))
|
||||||
|
|
||||||
|
|
||||||
(define (make-enumeration ls)
|
(define (make-enumeration ls)
|
||||||
(unless (and (list? ls) (for-all symbol? ls))
|
(unless (and (list? ls) (for-all symbol? ls))
|
||||||
(die 'make-enumeration "not a list of symbols" ls))
|
(die 'make-enumeration "not a list of symbols" ls))
|
||||||
(make-enum (gensym) ls ls))
|
(let ([u (remove-dups ls)])
|
||||||
|
(make-enum (gensym) u u)))
|
||||||
|
|
||||||
(define (enum-set-universe x)
|
(define (enum-set-universe x)
|
||||||
(unless (enum? x)
|
(unless (enum? x)
|
||||||
(die 'enum-set-universe "not an enumeration" x))
|
(die 'enum-set-universe "not an enumeration" x))
|
||||||
(enum-univ x))
|
(let ([u (enum-univ x)])
|
||||||
|
(make-enum (enum-g x) u u)))
|
||||||
|
|
||||||
(define (enum-set-indexer x)
|
(define (enum-set-indexer x)
|
||||||
(unless (enum? x)
|
(unless (enum? x)
|
||||||
|
@ -58,7 +66,6 @@
|
||||||
(define (enum-set-constructor x)
|
(define (enum-set-constructor x)
|
||||||
(unless (enum? x)
|
(unless (enum? x)
|
||||||
(die 'enum-set-constructor "not an enumeration" x))
|
(die 'enum-set-constructor "not an enumeration" x))
|
||||||
(let ([idx (enum-set-indexer x)])
|
|
||||||
(lambda (ls)
|
(lambda (ls)
|
||||||
(unless (and (list? ls) (for-all symbol? ls))
|
(unless (and (list? ls) (for-all symbol? ls))
|
||||||
(die 'enum-set-constructor "not a list of symbols" ls))
|
(die 'enum-set-constructor "not a list of symbols" ls))
|
||||||
|
@ -68,15 +75,17 @@
|
||||||
(die 'enum-set-constructor "not in the universe" s x)))
|
(die 'enum-set-constructor "not in the universe" s x)))
|
||||||
ls)
|
ls)
|
||||||
(make-enum (enum-g x) (enum-univ x)
|
(make-enum (enum-g x) (enum-univ x)
|
||||||
(map car
|
(remove-dups ls))))
|
||||||
(list-sort (lambda (a b) (< (cdr a) (cdr b)))
|
|
||||||
(map (lambda (x) (cons x (idx x)))
|
|
||||||
ls)))))))
|
|
||||||
|
|
||||||
(define (enum-set->list x)
|
(define (enum-set->list x)
|
||||||
(unless (enum? x)
|
(unless (enum? x)
|
||||||
(die 'enum-set->list "not an enumeration" x))
|
(die 'enum-set->list "not an enumeration" x))
|
||||||
(map values (enum-values x)))
|
(let ([idx (enum-set-indexer x)]
|
||||||
|
[ls (enum-values x)])
|
||||||
|
(map car
|
||||||
|
(list-sort (lambda (a b) (< (cdr a) (cdr b)))
|
||||||
|
(map (lambda (x) (cons x (idx x)))
|
||||||
|
ls)))))
|
||||||
|
|
||||||
(define (enum-set-member? s x)
|
(define (enum-set-member? s x)
|
||||||
(if (enum? x)
|
(if (enum? x)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
1468
|
1469
|
||||||
|
|
|
@ -1367,14 +1367,25 @@
|
||||||
(or (null? x)
|
(or (null? x)
|
||||||
(and (not (memq (car x) (cdr x)))
|
(and (not (memq (car x) (cdr x)))
|
||||||
(set? (cdr x)))))
|
(set? (cdr x)))))
|
||||||
|
(define (remove-dups ls)
|
||||||
|
(cond
|
||||||
|
[(null? ls) '()]
|
||||||
|
[else
|
||||||
|
(cons (car ls)
|
||||||
|
(remove-dups (remq (car ls) (cdr ls))))]))
|
||||||
(syntax-match stx ()
|
(syntax-match stx ()
|
||||||
[(_ name (id* ...) maker)
|
[(_ name (id* ...) maker)
|
||||||
(and (id? name) (id? maker) (for-all id? id*))
|
(and (id? name) (id? maker) (for-all id? id*))
|
||||||
(let ([name* (syntax->datum id*)] [mk (gensym)])
|
(let ([name* (remove-dups (syntax->datum id*))] [mk (gensym)])
|
||||||
(unless (set? name*)
|
|
||||||
(stx-error stx "duplicate names in enumeration set"))
|
|
||||||
(bless
|
(bless
|
||||||
`(begin
|
`(begin
|
||||||
|
;;; can be constructed at compile time
|
||||||
|
;;; but .... it's not worth it.
|
||||||
|
;;; also, generativity of defined enum types
|
||||||
|
;;; is completely unspecified, making them just
|
||||||
|
;;; more useless than they really are.
|
||||||
|
;;; eventually, I'll make them all compile-time
|
||||||
|
;;; generative just to piss some known people off.
|
||||||
(define ,mk
|
(define ,mk
|
||||||
(enum-set-constructor
|
(enum-set-constructor
|
||||||
(make-enumeration ',name*)))
|
(make-enumeration ',name*)))
|
||||||
|
@ -1385,9 +1396,9 @@
|
||||||
(identifier? #'n)
|
(identifier? #'n)
|
||||||
(if (memq (syntax->datum #'n) ',name*)
|
(if (memq (syntax->datum #'n) ',name*)
|
||||||
#''n
|
#''n
|
||||||
(syntax-error x
|
(syntax-violation ',name
|
||||||
"not a member of set"
|
"not a member of set"
|
||||||
',name*))])))
|
x #'n))])))
|
||||||
(define-syntax ,maker
|
(define-syntax ,maker
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(syntax-case x ()
|
(syntax-case x ()
|
||||||
|
@ -1396,9 +1407,17 @@
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (n)
|
(lambda (n)
|
||||||
(unless (identifier? n)
|
(unless (identifier? n)
|
||||||
(syntax-error x "non-identifier argument"))
|
(syntax-violation
|
||||||
|
',maker
|
||||||
|
"non-identifier argument"
|
||||||
|
x
|
||||||
|
n))
|
||||||
(unless (memq (syntax->datum n) ',name*)
|
(unless (memq (syntax->datum n) ',name*)
|
||||||
(syntax-error n "not a member of set")))
|
(syntax-violation
|
||||||
|
',maker
|
||||||
|
"not a member of set"
|
||||||
|
x
|
||||||
|
n)))
|
||||||
#'(n* ...))
|
#'(n* ...))
|
||||||
#'(,mk '(n* ...)))]))))))])))
|
#'(,mk '(n* ...)))]))))))])))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue