diff --git a/scribblings/utils.scrbl b/scribblings/utils.scrbl index 841a6bc..b753322 100644 --- a/scribblings/utils.scrbl +++ b/scribblings/utils.scrbl @@ -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 diff --git a/utils.rkt b/utils.rkt index 4cc5421..b55ba0c 100644 --- a/utils.rkt +++ b/utils.rkt @@ -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)])