<commit_before>#lang racket

(provide readline)

(require "types.rkt")

(define (readline prompt)
  (_printf "~a" prompt)
  (let ([line (read-line (current-input-port) 'any)])
    (if (eq? eof line)
      nil
      line)))

      
<commit_msg>Racket: add readline/line edit support.<commit_after>#lang racket

(provide readline)

(require (prefix-in readline: readline/readline))

(require "types.rkt")

(define history-loaded #f)
(define HISTORY-FILE (format "~a/.mal-history" (find-system-path 'home-dir)))

(define (load-history path)
  (map 
    (lambda (line) (readline:add-history line))
    (string-split
      (port->string (open-input-file path))
      #px"\n")))

(define (readline prompt)
  (when (not history-loaded)
    (set! history-loaded #t)
    (load-history HISTORY-FILE))
  (let ([line (readline:readline prompt)])
    (if (eq? eof line)
      nil
      (begin
        (readline:add-history line)
        (with-output-to-file
          HISTORY-FILE
          (lambda () (printf "~a~n" line))
          #:exists 'append)
        line))))
{'fraction_non_alphanumeric': 0.15924170616113745, 'fraction_numerical': 0.0, 'mean_word_length': 2.955056179775281, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6772244', 'n_tokens_mistral': 379, 'n_tokens_neox': 366, 'n_words': 91}