<commit_before>(in-package :cl-notebook)

(defparameter *base-js*
  (ps
;;;; base.js contains general utilities that might be useful in other JS
;;;; applications too. Nothing notebook-specific here.

    (defun now! ()
      (chain -date (now)))

    ;; basic functional stuff
    (defun identity (thing) thing)

    (defun constantly (thing) (lambda () thing))

    (defun rest (array) (chain array (slice 1)))

    (defun map (fn thing)
      (if (object? thing)
          (let ((res (-array)))
            (for-in (k thing) (chain res (push (fn (aref thing k) k))))
            res)
          (loop for elem in thing collect (fn elem))))

    (defun copy-list (list)
      (map identity list))

    (defun sort (list comparison &key (key identity))
      (chain (copy-list list)
             (sort (lambda (a b)
                     (let ((a^ (key a))
                           (b^ (key b)))
                       (cond ((comparison a^ b^) -1)
                             ((comparison b^ a^) 1)
                             (t 0)))))))

    (defun fold (fn memo thing)
      (let ((m memo))
        (if (object? thing)
            (for-in (k thing) (setf m (fn (aref thing k) m)))
            (loop for elem in thing do (setf m (fn elem m))))
        m))

    (defun filter (fn thing)
      (loop for elem in thing when (fn elem) collect elem))

    (defun extend (obj &rest other-objs)
      (flet ((ext! (dest src) (map (lambda (v k) (setf (aref dest k) v)) src)))
        (let ((res (create)))
          (ext! res obj)
          (map (lambda (obj) (ext! res obj)) other-objs)
          res)))

    (defun append-new (list-a list-b)
      (let ((s (new (-set list-a)))
            (lst (map #'identity list-a)))
        (loop for elem in list-b
           unless (chain s (has elem))
           do (chain lst (push elem)))
        lst))

    (defun lines (string) (chain string (split #\newline)))

    (defun join (strings &optional (separator "")) (chain strings (join separator)))<commit_msg>Add reverse function to base.lisp<commit_after>(in-package :cl-notebook)

(defparameter *base-js*
  (ps
;;;; base.js contains general utilities that might be useful in other JS
;;;; applications too. Nothing notebook-specific here.

    (defun now! ()
      (chain -date (now)))

    ;; basic functional stuff
    (defun identity (thing) thing)

    (defun constantly (thing) (lambda () thing))

    (defun rest (array) (chain array (slice 1)))

    (defun map (fn thing)
      (if (object? thing)
          (let ((res (-array)))
            (for-in (k thing) (chain res (push (fn (aref thing k) k))))
            res)
          (loop for elem in thing collect (fn elem))))

    (defun copy-list (list)
      (map identity list))

    (defun sort (list comparison &key (key identity))
      (chain (copy-list list)
             (sort (lambda (a b)
                     (let ((a^ (key a))
                           (b^ (key b)))
                       (cond ((comparison a^ b^) -1)
                             ((comparison b^ a^) 1)
                             (t 0)))))))

    (defun reverse (list)
      (chain (copy-list list) (reverse)))

    (defun fold (fn memo thing)
      (let ((m memo))
        (if (object? thing)
            (for-in (k thing) (setf m (fn (aref thing k) m)))
            (loop for elem in thing do (setf m (fn elem m))))
        m))

    (defun filter (fn thing)
      (loop for elem in thing when (fn elem) collect elem))

    (defun extend (obj &rest other-objs)
      (flet ((ext! (dest src) (map (lambda (v k) (setf (aref dest k) v)) src)))
        (let ((res (create)))
          (ext! res obj)
          (map (lambda (obj) (ext! res obj)) other-objs)
          res)))

    (defun append-new (list-a list-b)
      (let ((s (new (-set list-a)))
            (lst (map #'identity list-a)))
        (loop for elem in list-b
           unless (chain s (has elem))
           do (chain lst (push elem)))
        lst))

    (defun lines (string) (chain string (split #\newline)))

    (defun join (strings &optional (separator "")) (chain strings (join separator)))
{'fraction_non_alphanumeric': 0.1464486209421528, 'fraction_numerical': 0.001952648279228704, 'mean_word_length': 1.8717589348283112, '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': '4489502', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1237, 'n_words': 486}