<commit_before>(define-record-type logging-cons
  (make-logging-cons lcar lcdr)
  logging-cons?
  logging-cons-id
  lcar
  lcdr)

(define (lnull? lcons)
  (and (logging-cons? lcons)
       (null? (lcdr lcons))))

(define (lpair? lcons)
  (and (logging-cons? lcons)
       (not (null? (lcdr lcons)))))

(define (lcons lcar lcdr)
  (let ((id (uuidgen)))
    (make-logging-cons id lcar lcdr)))

(define (llist lcar lcdr)
  (lcons lcar
         (lcons lcdr '())))

(define (map* f lst)
  (if (lnull? lst)
      lst
      (let ((head (lcar lst)) (tail (lcdr lst)))
        (let ((head1 (f head))
              (tail1 (map* f tail)))
          (if (and (eq? head1 head) (eq? tail1 tail))
              lst
              (lcons head1 tail1))))))

(define (depth-first handle tree)
  (cond ((lnull? tree) tree)
        ((handle tree) =>
         (lambda (new-tree) new-tree))
        ((not (lpair? tree)) tree)
        (else
         (let ((mapped (map* (lambda (kid)
                               (depth-first handle kid))
                             tree)))
           (if (eq? mapped tree)
               tree
               mapped)))))<commit_msg>zipper: logging cons works, for whatever that's worth<commit_after>(define-record-type logging-cons rtd/logging-cons
  (make-logging-cons id car cdr)
  lpair?
  (id logging-cons-id)
  (car lcar)
  (cdr lcdr))

(define-record-discloser rtd/logging-cons
  (lambda (lcons)
    `(lcons ,(lcar lcons)
            ,(lcdr lcons))))

(define lnil (list '()))

(define (lnull? lcons)
  (eq? lcons lnil))

(define (lcons lcar lcdr)
  (let* ((id (uuidgen))
         (cell (make-logging-cons id lcar lcdr)))
    (log-logging-cons cell)
    cell))

(define (llist . args)
  (fold-right lcons
              lnil
              args))

(define (log-logging-cons lcons . port)
  (let-optionals* port ((port (current-output-port)))
   (define (show obj)
     (let ((datum (lpair? obj)))
       (if datum
           (display (logging-cons-id obj) port)
           (write obj port))
       (display #\: port)))
   (and (show lcons)
        (show (lcar lcons))
        (show (lcdr lcons)))
   (newline port)))

(define (map* f lst)
  (if (lnull? lst)
      lst
      (let ((head (lcar lst)) (tail (lcdr lst)))
        (let ((head1 (f head))
              (tail1 (map* f tail)))
          (if (and (eq? head1 head) (eq? tail1 tail))
              lst
              (lcons head1 tail1))))))

(define (depth-first handle tree)
  (cond ((lnull? tree) tree)
        ((handle tree) =>
         (lambda (new-tree) new-tree))
        ((not (lpair? tree)) tree)
        (else
         (let ((mapped (map* (lambda (kid)
                               (depth-first handle kid))
                             tree)))
           (if (eq? mapped tree)
               tree
               mapped)))))

;; (define lst1 (llist 4 1 2 3))

;; (define (testing)
;;   (map* (lambda (x)
;;           (if (= x 4)
;;               8
;;               x))
;;         lst1))
{'fraction_non_alphanumeric': 0.15661839003031325, 'fraction_numerical': 0.006736274840013472, 'mean_word_length': 1.8151658767772512, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2815448', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1036, 'n_words': 298}