Add define/abstract/error.
This commit is contained in:
parent
3691c42e67
commit
77f2fcb58f
2 changed files with 25 additions and 2 deletions
|
@ -4,7 +4,8 @@
|
|||
"../utils.rkt"
|
||||
(only-in typed/graph Graph)
|
||||
(only-in racket/set set)
|
||||
(only-in racket/stream stream->list stream-take)))
|
||||
(only-in racket/stream stream->list stream-take)
|
||||
(only-in typed/racket/class class super-new new send)))
|
||||
|
||||
@(define utils-evaluator
|
||||
(parameterize ([sandbox-output 'string]
|
||||
|
@ -88,6 +89,24 @@ The implementation of these macros is a simplified version the definition of
|
|||
|
||||
}
|
||||
|
||||
@defform[(define/abstract/error method-name args ...)]{
|
||||
|
||||
In a typed class, defines a public method @racket[method-name] with the
|
||||
arguments @racket[args] and with the body announcing that this method
|
||||
is abstract.
|
||||
|
||||
@ex[
|
||||
(define my-abstract-class%
|
||||
(class object%
|
||||
(super-new)
|
||||
|
||||
(: abstract-increment (-> Integer Integer))
|
||||
(define/abstract/error (abstract-increment x))))
|
||||
|
||||
(define obj (new my-abstract-class%))
|
||||
(eval:error (send obj abstract-increment 1))
|
||||
]}
|
||||
|
||||
@section{Hashtable injection}
|
||||
|
||||
This section defines some utilities to streamline the usage of hash tables
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
(provide
|
||||
Variable VariableMapping GeneralPair
|
||||
|
||||
assert-type for/first/typed for*/first/typed
|
||||
assert-type for/first/typed for*/first/typed define/abstract/error
|
||||
eval-with eval1-with auto-hash-ref/explicit auto-hash-ref/:
|
||||
extract-symbols any->string stringify-variable-mapping string->any
|
||||
handle-org-booleans map-sexp read-org-sexp unorg unstringify-pairs
|
||||
|
@ -61,6 +61,10 @@
|
|||
(cons i j))
|
||||
'(2 . 4))))
|
||||
|
||||
(define-syntax-parser define/abstract/error
|
||||
[(_ (name:id args:id ...))
|
||||
#`(define/public (name args ...) (error 'name "abstract method"))])
|
||||
|
||||
(: eval-with (-> (VariableMapping Any) Any AnyValues))
|
||||
(define (eval-with ht expr)
|
||||
(parameterize ([current-namespace (make-base-namespace)])
|
||||
|
|
Loading…
Reference in a new issue