#cs(module docs mzscheme (require (lib "error.ss" "htdp") (lib "list.ss") (lib "prim.ss" "lang")) (provide atom? annotation? end-annotation write-file ) (define-primitive atom? atom?/proc) (define-primitive annotation? annotation?/proc) (define-primitive end-annotation? end-annotation?/proc) (define-primitive write-file write-file/proc) ;; mk-annotation : ;; (str number[str-lenght] -> bool) -> (any-value -> bool) (define (mk-annotation test) (lambda (val) (and (symbol? val) (let ((str (symbol->string val))) (test str (sub1 (string-length str))))))) ;; annotation? : any-value -> bool (define annotation?/proc (mk-annotation (lambda (str E);; str : string, E : integer (and (> E 1) (eqv? (string-ref str 0) #\<) (eqv? (string-ref str E) #\>))))) ;; end-annotation? : any-value -> bool (define end-annotation?/proc (mk-annotation (lambda (str E);; str : string, E : integer (and (> E 2) (eqv? (string-ref str 0) #\<) (eqv? (string-ref str 1) #\/) (eqv? (string-ref str E) #\>))))) ;; end-annotation : annotation -> end-annotation (define (end-annotation ann) (check-arg 'end-annotation (annotation? ann) "annotation (str)" "first" ann) (let ((str (symbol->string ann))) (string->symbol (string-append "" (substring str 1 (string-length str)))))) ;; line-breaking? : any-value -> bool (define (line-breaking? x) (and (annotation? x) (memq x LNBRK) #t)) (define LNBRK (let ((x '(