Added raise-support-error and exn:fail:support to racket/generic.
The exn:fail:support exception is used to signal "unsupported" values for generic methods, e.g. a vector as argument to dict-remove. Right interface, just the wrong kind of instance. The exception type helps define the notion of a "supported" method, since a method might have a fallback implementation yet some values are not considered "supported".
This commit is contained in:
parent
766761f6b4
commit
acc4afad6f
|
@ -14,6 +14,8 @@
|
|||
|
||||
(provide define-generics
|
||||
define/generic
|
||||
raise-support-error
|
||||
(struct-out exn:fail:support)
|
||||
chaperone-generics
|
||||
impersonate-generics
|
||||
redirect-generics
|
||||
|
|
|
@ -316,9 +316,6 @@
|
|||
(for/list ([k*v (in-dict-pairs d)])
|
||||
k*v))
|
||||
|
||||
(define (raise-support-error name s)
|
||||
(raise-mismatch-error name "not implemented for " s))
|
||||
|
||||
(define-primitive-generics
|
||||
(dict gen:dict prop:gen:dict prop:gen:dict-methods dict? dict-implements?)
|
||||
#:fast-defaults
|
||||
|
|
|
@ -9,7 +9,9 @@
|
|||
|
||||
(provide define-primitive-generics
|
||||
define-primitive-generics/derived
|
||||
define/generic)
|
||||
define/generic
|
||||
raise-support-error
|
||||
(struct-out exn:fail:support))
|
||||
|
||||
(begin-for-syntax
|
||||
|
||||
|
@ -383,11 +385,17 @@
|
|||
#'(define (method-name . method-formals)
|
||||
(define proc-name proc)
|
||||
(unless proc-name
|
||||
(raise-arguments-error 'method-name
|
||||
(format "not implemented for ~e"
|
||||
self-name)))
|
||||
(raise-support-error 'method-name self-name))
|
||||
method-apply))]))
|
||||
|
||||
(struct exn:fail:support exn:fail [] #:transparent)
|
||||
|
||||
(define (raise-support-error name v)
|
||||
(raise
|
||||
(exn:fail:support
|
||||
(format "~a: not implemented for ~e" name v)
|
||||
(current-continuation-marks))))
|
||||
|
||||
(define-syntax (check-generic-method stx)
|
||||
(syntax-case stx ()
|
||||
[(check-generic-method
|
||||
|
|
|
@ -386,9 +386,6 @@
|
|||
(set-remove! s x))]
|
||||
[else (raise-support-error 'set-symmetric-difference! s)]))
|
||||
|
||||
(define (raise-support-error name s)
|
||||
(raise-mismatch-error name "not implemented for " s))
|
||||
|
||||
(define-sequence-syntax *in-set
|
||||
(lambda () #'in-set)
|
||||
(lambda (stx)
|
||||
|
|
Loading…
Reference in New Issue
Block a user