Add define/abstract/error.

This commit is contained in:
Sergiu Ivanov 2022-08-03 01:15:24 +02:00
parent 3691c42e67
commit 77f2fcb58f
2 changed files with 25 additions and 2 deletions

View file

@ -4,7 +4,8 @@
"../utils.rkt" "../utils.rkt"
(only-in typed/graph Graph) (only-in typed/graph Graph)
(only-in racket/set set) (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 @(define utils-evaluator
(parameterize ([sandbox-output 'string] (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} @section{Hashtable injection}
This section defines some utilities to streamline the usage of hash tables This section defines some utilities to streamline the usage of hash tables

View file

@ -6,7 +6,7 @@
(provide (provide
Variable VariableMapping GeneralPair 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/: eval-with eval1-with auto-hash-ref/explicit auto-hash-ref/:
extract-symbols any->string stringify-variable-mapping string->any extract-symbols any->string stringify-variable-mapping string->any
handle-org-booleans map-sexp read-org-sexp unorg unstringify-pairs handle-org-booleans map-sexp read-org-sexp unorg unstringify-pairs
@ -61,6 +61,10 @@
(cons i j)) (cons i j))
'(2 . 4)))) '(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)) (: eval-with (-> (VariableMapping Any) Any AnyValues))
(define (eval-with ht expr) (define (eval-with ht expr)
(parameterize ([current-namespace (make-base-namespace)]) (parameterize ([current-namespace (make-base-namespace)])