<commit_before>(in-package :js)

(defun list-join (list elt)
  (let (res)
    (dolist (i list)
      (push i res)
      (push elt res))
    (pop res)
    (nreverse res)))

;;; wie herrlich effizient
(defun list-to-string (list)
  (reduce #'(lambda (str1 &optional (str2 ""))
              (concatenate 'string str1 str2))
          list))

(defun append-to-last (form elt)
  (cond ((stringp form)
	 (concatenate 'string form elt))
	((consp form)
	 (let ((last (last form)))
	   (if (stringp (car last))
	       (rplaca last (concatenate 'string (car last) elt))
	       (append-to-last (car last) elt))
	   form))
	(t (error "unsupported form ~S" form))))

(defun prepend-to-first (form elt)
  (cond ((stringp form)
	 (concatenate 'string elt form))
	((consp form)
	 (let ((first (first form)))
	   (if (stringp first)
	       (rplaca form (concatenate 'string elt first))
	       (prepend-to-first first elt))
	   form))
	(t (error "unsupported form ~S" form))))

(defun string-join (strings elt)
  (list-to-string (list-join strings elt)))

(defun val-to-string (val)
  (cond ((stringp val) val)<commit_msg>Bah, speed up list-to-string by a few factors...<commit_after>(in-package :js)

(defun list-join (list elt)
  (let (res)
    (dolist (i list)
      (push i res)
      (push elt res))
    (pop res)
    (nreverse res)))

(defun list-to-string (list)
  (with-output-to-string (str)
    (dolist (el list)
      (write-string el str))))

(defun append-to-last (form elt)
  (cond ((stringp form)
	 (concatenate 'string form elt))
	((consp form)
	 (let ((last (last form)))
	   (if (stringp (car last))
	       (rplaca last (concatenate 'string (car last) elt))
	       (append-to-last (car last) elt))
	   form))
	(t (error "unsupported form ~S" form))))

(defun prepend-to-first (form elt)
  (cond ((stringp form)
	 (concatenate 'string elt form))
	((consp form)
	 (let ((first (first form)))
	   (if (stringp first)
	       (rplaca form (concatenate 'string elt first))
	       (prepend-to-first first elt))
	   form))
	(t (error "unsupported form ~S" form))))

(defun string-join (strings elt)
  (list-to-string (list-join strings elt)))

(defun val-to-string (val)
  (cond ((stringp val) val)
{'fraction_non_alphanumeric': 0.15961800818553887, 'fraction_numerical': 0.0018190086402910413, 'mean_word_length': 3.074074074074074, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2431931', 'n_tokens_mistral': 843, 'n_tokens_neox': 817, 'n_words': 255}