unstable/generics: define-methods' ->
methods'
`define-methods' is a bad name for an expression form.
This commit is contained in:
parent
e4a3001af6
commit
36980c262f
|
@ -152,13 +152,13 @@
|
|||
(require racket/stxparam)
|
||||
(define-syntax-parameter define/generic
|
||||
(lambda (stx)
|
||||
(raise-syntax-error 'define/generic "only allowed inside define-methods" stx)))
|
||||
(raise-syntax-error 'define/generic "only allowed inside methods" stx)))
|
||||
(provide define/generic)
|
||||
|
||||
;; utility for specification of methods for a group of generic functions
|
||||
;; (could make this do all the checks instead of a guard for the property)
|
||||
(provide define-methods)
|
||||
(define-syntax (define-methods stx)
|
||||
(provide methods)
|
||||
(define-syntax (methods stx)
|
||||
(syntax-case stx (=>)
|
||||
[(_ generics . mthds)
|
||||
(identifier? #'generics)
|
||||
|
|
|
@ -63,7 +63,7 @@ context of @racket[name].
|
|||
|
||||
}
|
||||
|
||||
@defform[(define-methods name definition ...)
|
||||
@defform[(methods name definition ...)
|
||||
#:contracts
|
||||
([name identifier?])]{
|
||||
|
||||
|
@ -89,11 +89,11 @@ Allows @racket[define/generic] to appear in @racket[definition ...].
|
|||
([local-name identifier?]
|
||||
[method-name identifier?])]{
|
||||
|
||||
When used inside @racket[define-methods], binds @racket[local-name] to
|
||||
When used inside @racket[methods], binds @racket[local-name] to
|
||||
the generic for @racket[method-name]. This is useful for method
|
||||
specializations to use the generic methods on other values.
|
||||
|
||||
Syntactically an error when used outside @racket[define-methods].
|
||||
Syntactically an error when used outside @racket[methods].
|
||||
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ Syntactically an error when used outside @racket[define-methods].
|
|||
|
||||
(define-struct num (v)
|
||||
#:property prop:printable
|
||||
(define-methods printable
|
||||
(methods printable
|
||||
(define/generic super-print gen-print)
|
||||
(define (gen-print n [port (current-output-port)])
|
||||
(fprintf port "Num: ~a" (num-v n)))
|
||||
|
@ -127,7 +127,7 @@ Syntactically an error when used outside @racket[define-methods].
|
|||
|
||||
(define-struct bool (v)
|
||||
#:property prop:printable
|
||||
(define-methods printable
|
||||
(methods printable
|
||||
(define/generic super-print gen-print)
|
||||
(define (gen-print b [port (current-output-port)])
|
||||
(fprintf port "Bool: ~a"
|
||||
|
|
|
@ -535,7 +535,7 @@
|
|||
|
||||
(struct custom-hash (table make-box)
|
||||
#:property prop:dict
|
||||
(define-methods dict
|
||||
(methods dict
|
||||
(define dict-ref custom-hash-ref)
|
||||
(define dict-set! custom-hash-set!)
|
||||
(define dict-remove! custom-hash-remove!)
|
||||
|
@ -555,7 +555,7 @@
|
|||
|
||||
(struct immutable-custom-hash custom-hash ()
|
||||
#:property prop:dict
|
||||
(define-methods dict
|
||||
(methods dict
|
||||
(define dict-ref custom-hash-ref)
|
||||
(define dict-set custom-hash-set)
|
||||
(define dict-remove custom-hash-remove)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
(define-struct ex ()
|
||||
#:property prop:lots
|
||||
(define-methods lots
|
||||
(methods lots
|
||||
(define (f #:foo foo lots zog [def #t])
|
||||
1)))]
|
||||
(test
|
||||
|
@ -32,7 +32,7 @@
|
|||
|
||||
(define-struct ex ()
|
||||
#:property prop:lots
|
||||
(define-methods lots
|
||||
(methods lots
|
||||
(define (f #:foo foo lots zog #:def [def #t])
|
||||
1)))]
|
||||
(test
|
||||
|
@ -46,7 +46,7 @@
|
|||
|
||||
(define-struct ex ()
|
||||
#:property prop:lots
|
||||
(define-methods lots
|
||||
(methods lots
|
||||
(define/generic gen:f f)
|
||||
(define (f lots idx val)
|
||||
(if (zero? idx)
|
||||
|
@ -63,7 +63,7 @@
|
|||
|
||||
(define-struct alist ([l #:mutable])
|
||||
#:property prop:table
|
||||
(define-methods table
|
||||
(methods table
|
||||
(define (get table idx [default #f])
|
||||
(cond [(massq idx (alist-l table)) => mcdr]
|
||||
[else default]))
|
||||
|
@ -114,7 +114,7 @@
|
|||
|
||||
(define-struct num (v)
|
||||
#:property prop:printable
|
||||
(define-methods printable
|
||||
(methods printable
|
||||
(define/generic super-print gen-print)
|
||||
(define (gen-print n [port (current-output-port)])
|
||||
(fprintf port "Num: ~a" (num-v n)))
|
||||
|
@ -125,7 +125,7 @@
|
|||
|
||||
(define-struct bool (v)
|
||||
#:property prop:printable
|
||||
(define-methods printable
|
||||
(methods printable
|
||||
(define/generic super-print gen-print)
|
||||
(define (gen-print b [port (current-output-port)])
|
||||
(fprintf port "Bool ~a" (if (bool-v b) "Yes" "No")))
|
||||
|
|
Loading…
Reference in New Issue
Block a user