<commit_before>
(module kw-file "pre-base.ss" 

  (provide -open-input-file
           -open-output-file
           -open-input-output-file
           -call-with-input-file
           -call-with-output-file
           -with-input-from-file
           -with-output-to-file
           call-with-input-file*
           call-with-output-file*)

  (define exists-syms
    '(error append update replace truncate truncate/replace))

  (define exists-desc
    "'error, 'append, 'update, 'replace, 'truncate, or 'truncate/replace")

  (define -open-input-file
    (let ([open-input-file (lambda (path #:mode [mode 'binary])
                             (unless (path-string? path)
                               (raise-type-error 'open-input-file "path or string" path))
                             (unless (memq mode '(binary text))
                               (raise-type-error 'open-input-file "'binary or 'text" mode))
                             (open-input-file path mode))])
      open-input-file))

  (define -open-output-file
    (let ([open-output-file (lambda (path #:mode [mode 'binary]
                                          #:exists [exists 'error])
                             (unless (path-string? path)
                               (raise-type-error 'open-output-file "path or string" path))
                             (unless (memq mode '(binary text))
                               (raise-type-error 'open-output-file "'binary or 'text" mode))
                             (unless (memq exists exists-syms)
                               (raise-type-error 'open-output-file exists-desc exists))
                             (open-output-file path mode exists))])
      open-output-file))

  (define -open-input-output-file
    (let ([open-input-output-file (lambda (path #:mode [mode 'binary]
                                                #:exists [exists 'error])
                                    (unless (path-string? path)
                                      (raise-type-error 'open-input-output-file "path or string" path))
                                    (unless (memq mode '(binary text))
                                      (raise-type-error 'open-input-output-file "'binary or 'text" mode))
                                    (unless (memq exists exists-syms)
                                      (raise-type-error 'open-input-output-file exists-desc exists))
                                    (open-input-output-file path mode exists))])
      open-input-output-file))

  (define -call-with-input-file
    (let ([call-with-input-file (lambda (path proc #:mode [mode 'binary])
                             (unless (path-string? path)
                               (raise-type-error 'call-with-input-file "path or string" path))
                             (unless (and (procedure? proc)
                                          (procedure-arity-includes? proc 1))
                               (raise-type-error 'call-with-input-file "procedure (arity 1)" path))
                             (unless (memq mode '(binary text))
                               (raise-type-error 'call-with-input-file "'binary or 'text" mode))
                             (call-with-input-file path proc mode))])
      call-with-input-file))

  (define -call-with-output-file
    (let ([call-with-output-file (lambda (path proc 
                                               #:mode [mode 'binary]
                                               #:exists [exists 'error])
                             (unless (path-string? path)
                               (raise-type-error 'call-with-output-file "path or string" path))
                             (unless (and (procedure? proc)
                                          (procedure-arity-includes? proc 1))
                               (raise-type-error 'call-with-output-file "procedure (arity 1)" path))
                             (unless (memq mode '(binary text))
                               (raise-type-error 'call-with-output-file "'binary or 'text" mode))
                             (unless (memq exists exists-syms)
                               (raise-type-error 'call-with-output-file exists-desc exists))
                             (call-with-output-file path proc mode exists))])
      call-with-output-file))
  
  (define -with-input-from-file
    (let ([with-input-from-file (lambda (path proc #:mode [mode 'binary])
                             (unless (path-string? path)
                               (raise-type-error 'with-input-from-file "path or string" path))
                             (unless (and (procedure? proc)
                                          (procedure-arity-includes? proc 0))
                               (raise-type-error 'with-input-from-file "procedure (arity 0)" path))
                             (unless (memq mode '(binary text))
                               (raise-type-error 'with-input-from-file "'binary or 'text" mode))
                             (with-input-from-file path proc mode))])
      with-input-from-file))

  (define -with-output-to-file
    (let ([with-output-to-file (lambda (path proc
                                             #:mode [mode 'binary]
                                             #:exists [exists 'error])
                             (unless (path-string? path)
                               (raise-type-error 'with-output-to-file "path or string" path))
                             (unless (and (procedure? proc)
                                          (procedure-arity-includes? proc 0))
                               (raise-type-error 'with-output-to-file "procedure (arity 0)" path))
                             (unless (memq mode '(binary text))
                               (raise-type-error 'with-output-to-file "'binary or 'text" mode))
                             (unless (memq exists exists-syms)
                               (raise-type-error 'with-output-to-file exists-desc exists))
                             (with-output-to-file path proc mode exists))])
      with-output-to-file))

  (define call-with-input-file*
    (lambda (path proc #:mode [mode 'binary])
      (unless (path-string? path)
        (raise-type-error 'call-with-input-file* "path or string" path))
      (unless (and (procedure? proc)
                   (procedure-arity-includes? proc 1))
        (raise-type-error 'call-with-input-file* "procedure (arity 1)" path))
      (unless (memq mode '(binary text))
        (raise-type-error 'call-with-input-file* "'binary or 'text" mode))
      (let ([p (open-input-file path mode)])
        (dynamic-wind
            void
            (lambda () (proc p))
            (lambda () (close-input-port p))))))

  (define call-with-output-file*
    (lambda (path proc 
                  #:mode [mode 'binary]
                  #:exists [exists 'error])
      (unless (path-string? path)
        (raise-type-error 'call-with-output-file* "path or string" path))
      (unless (and (procedure? proc)
                   (procedure-arity-includes? proc 1))
        (raise-type-error 'call-with-output-file* "procedure (arity 1)" path))
      (unless (memq mode '(binary text))
        (raise-type-error 'call-with-output-file* "'binary or 'text" mode))
      (unless (memq exists exists-syms)
        (raise-type-error 'call-with-output-file* exists-desc exists))
      (let ([p (open-output-file path mode exists)])
        (dynamic-wind
            void
            (lambda () (proc p))
            (lambda () (close-output-port p)))))))<commit_msg>fixed error messages<commit_after>
(module kw-file "pre-base.ss" 

  (provide -open-input-file
           -open-output-file
           -open-input-output-file
           -call-with-input-file
           -call-with-output-file
           -with-input-from-file
           -with-output-to-file
           call-with-input-file*
           call-with-output-file*)

  (define exists-syms
    '(error append update replace truncate truncate/replace))

  (define exists-desc
    "'error, 'append, 'update, 'replace, 'truncate, or 'truncate/replace")

  (define -open-input-file
    (let ([open-input-file (lambda (path #:mode [mode 'binary])
                             (unless (path-string? path)
                               (raise-type-error 'open-input-file "path or string" path))
                             (unless (memq mode '(binary text))
                               (raise-type-error 'open-input-file "'binary or 'text" mode))
                             (open-input-file path mode))])
      open-input-file))

  (define -open-output-file
    (let ([open-output-file (lambda (path #:mode [mode 'binary]
                                          #:exists [exists 'error])
                             (unless (path-string? path)
                               (raise-type-error 'open-output-file "path or string" path))
                             (unless (memq mode '(binary text))
                               (raise-type-error 'open-output-file "'binary or 'text" mode))
                             (unless (memq exists exists-syms)
                               (raise-type-error 'open-output-file exists-desc exists))
                             (open-output-file path mode exists))])
      open-output-file))

  (define -open-input-output-file
    (let ([open-input-output-file (lambda (path #:mode [mode 'binary]
                                                #:exists [exists 'error])
                                    (unless (path-string? path)
                                      (raise-type-error 'open-input-output-file "path or string" path))
                                    (unless (memq mode '(binary text))
                                      (raise-type-error 'open-input-output-file "'binary or 'text" mode))
                                    (unless (memq exists exists-syms)
                                      (raise-type-error 'open-input-output-file exists-desc exists))
                                    (open-input-output-file path mode exists))])
      open-input-output-file))

  (define -call-with-input-file
    (let ([call-with-input-file (lambda (path proc #:mode [mode 'binary])
                             (unless (path-string? path)
                               (raise-type-error 'call-with-input-file "path or string" path))
                             (unless (and (procedure? proc)
                                          (procedure-arity-includes? proc 1))
                               (raise-type-error 'call-with-input-file "procedure (arity 1)" proc))
                             (unless (memq mode '(binary text))
                               (raise-type-error 'call-with-input-file "'binary or 'text" mode))
                             (call-with-input-file path proc mode))])
      call-with-input-file))

  (define -call-with-output-file
    (let ([call-with-output-file (lambda (path proc 
                                               #:mode [mode 'binary]
                                               #:exists [exists 'error])
                             (unless (path-string? path)
                               (raise-type-error 'call-with-output-file "path or string" path))
                             (unless (and (procedure? proc)
                                          (procedure-arity-includes? proc 1))
                               (raise-type-error 'call-with-output-file "procedure (arity 1)" proc))
                             (unless (memq mode '(binary text))
                               (raise-type-error 'call-with-output-file "'binary or 'text" mode))
                             (unless (memq exists exists-syms)
                               (raise-type-error 'call-with-output-file exists-desc exists))
                             (call-with-output-file path proc mode exists))])
      call-with-output-file))
  
  (define -with-input-from-file
    (let ([with-input-from-file (lambda (path proc #:mode [mode 'binary])
                             (unless (path-string? path)
                               (raise-type-error 'with-input-from-file "path or string" path))
                             (unless (and (procedure? proc)
                                          (procedure-arity-includes? proc 0))
                               (raise-type-error 'with-input-from-file "procedure (arity 0)" proc))
                             (unless (memq mode '(binary text))
                               (raise-type-error 'with-input-from-file "'binary or 'text" mode))
                             (with-input-from-file path proc mode))])
      with-input-from-file))

  (define -with-output-to-file
    (let ([with-output-to-file (lambda (path proc
                                             #:mode [mode 'binary]
                                             #:exists [exists 'error])
                             (unless (path-string? path)
                               (raise-type-error 'with-output-to-file "path or string" path))
                             (unless (and (procedure? proc)
                                          (procedure-arity-includes? proc 0))
                               (raise-type-error 'with-output-to-file "procedure (arity 0)" proc))
                             (unless (memq mode '(binary text))
                               (raise-type-error 'with-output-to-file "'binary or 'text" mode))
                             (unless (memq exists exists-syms)
                               (raise-type-error 'with-output-to-file exists-desc exists))
                             (with-output-to-file path proc mode exists))])
      with-output-to-file))

  (define call-with-input-file*
    (lambda (path proc #:mode [mode 'binary])
      (unless (path-string? path)
        (raise-type-error 'call-with-input-file* "path or string" path))
      (unless (and (procedure? proc)
                   (procedure-arity-includes? proc 1))
        (raise-type-error 'call-with-input-file* "procedure (arity 1)" proc))
      (unless (memq mode '(binary text))
        (raise-type-error 'call-with-input-file* "'binary or 'text" mode))
      (let ([p (open-input-file path mode)])
        (dynamic-wind
            void
            (lambda () (proc p))
            (lambda () (close-input-port p))))))

  (define call-with-output-file*
    (lambda (path proc 
                  #:mode [mode 'binary]
                  #:exists [exists 'error])
      (unless (path-string? path)
        (raise-type-error 'call-with-output-file* "path or string" path))
      (unless (and (procedure? proc)
                   (procedure-arity-includes? proc 1))
        (raise-type-error 'call-with-output-file* "procedure (arity 1)" proc))
      (unless (memq mode '(binary text))
        (raise-type-error 'call-with-output-file* "'binary or 'text" mode))
      (unless (memq exists exists-syms)
        (raise-type-error 'call-with-output-file* exists-desc exists))
      (let ([p (open-output-file path mode exists)])
        (dynamic-wind
            void
            (lambda () (proc p))
            (lambda () (close-output-port p)))))))
{'fraction_non_alphanumeric': 0.12207501153516577, 'fraction_numerical': 0.0015819655922483687, 'mean_word_length': 1.2956574368285672, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 54, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2250730', 'n_tokens_mistral': 4031, 'n_tokens_neox': 3832, 'n_words': 981}