(define-syntax assert-type (syntax-rules () ((assert-type loc expr) (unless expr (abort (make-composite-condition (make-property-condition 'exn 'location loc 'message "type check failed" 'arguments (list 'expr)) (make-property-condition 'type) (make-property-condition 'assertion))))))) (define (arity-exception loc argl) (abort (make-composite-condition (make-property-condition 'exn 'location loc 'message "invalid number of arguments" 'arguments argl) (make-property-condition 'arity) (make-property-condition 'assertion)))) (define (bounds-exception loc msg . args) (abort (make-composite-condition (make-property-condition 'exn 'location loc 'message msg 'arguments args) (make-property-condition 'bounds) (make-property-condition 'assertion)))) (define (%check-cursor loc s cur) (assert-type loc (string-cursor? cur)) (unless (<= 0 cur (string-length s)) (bounds-exception loc "cursor out of bounds" cur s))) (define (%check-range loc s start end) (assert-type loc (string-cursor? start)) (assert-type loc (string-cursor? end)) (unless (<= 0 start end (string-length s)) (bounds-exception loc "invalid cursor range" start end s)))