<commit_before>;;; i think this cons unnecessarily
(defun my-flatten (lst)
  (labels ((flat (lst acc)
             (if (null lst)
                 (nreverse acc)
                 (progn
                   (if (atom (car lst))
                       (push (car lst) acc)
                       (dolist (i (flat (car lst) nil))
                         (push i acc))) ; unnecessary cons?
                   (flat (cdr lst) acc)))))
    (flat lst nil)))

;;; i think this doesn't cons unnecessarily
(defun my-flatten (lst)
  (labels ((flat (lst acc)
             (if (null lst)
                 acc
                 (progn
                   (if (atom (car lst))
                       (push (car lst) acc)
                       (setf acc (flat (car lst) acc)))
                   (flat (cdr lst) acc)))))
    (nreverse (flat lst nil))))<commit_msg>even cleaner, non-consing solution<commit_after>(use-package :rt)

(deftest example
    (my-flatten '(a (b (c d) e))) (A B C D E))

(defun my-flatten (list)
  (labels ((flat (list acc)
             (if list
                 (flat (cdr list) (if (atom (car list))
                                      (cons (car list) acc)
                                      (nconc (flat (car list) nil) acc)))
                 acc)))
    (nreverse (flat list nil))))

(do-tests)
{'fraction_non_alphanumeric': 0.12728658536585366, 'fraction_numerical': 0.0, 'mean_word_length': 1.2677029360967185, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4053163', 'n_tokens_mistral': 400, 'n_tokens_neox': 383, 'n_words': 134}