<commit_before>(in-package :cl-user)
(defpackage cl21.core.sequence
  (:use :cl)
  (:shadow :nth
           :first
           :second
           :third
           :fourth
           :fifth
           :sixth
           :seventh
           :eighth
           :ninth
           :tenth
           :last
           :push
           :pushnew
           :pop)
  (:import-from :split-sequence
                :split-sequence
                :split-sequence-if)
  (:export :nth
           :first
           :second
           :third
           :fourth
           :fifth
           :sixth
           :seventh
           :eighth
           :ninth
           :tenth
           :last
           :split-sequence
           :split-sequence-if

           :sequence
           :fill
           :copy-seq
           :make-sequence
           :subseq
           :reduce
           :count
           :count-if
           :length ;; TODO: Write as a generic function
           :reverse
           :nreverse
           :sort
           :stable-sort

           :find
           :find-if
           :position
           :position-if

           :search
           :mismatch
           :replace
           :concatenate
           :elt
           :merge

           :map
           :map-into

           :remove
           :remove-if
           :remove-if-not
           :filter
           :remove-duplicates

           :delete
           :delete-if
           :delete-if-not
           :delete-duplicates

           :substitute
           :substitute-if
           :nsubstitute
           :nsubstitute-if

           :push
           :pushnew
           :pop))
(in-package :cl21.core.sequence)

(defgeneric nth (n sequence)
  (:method (n (seq list))
    (nth n seq))
  (:method (n (seq vector))
    (elt seq n)))

(defgeneric (setf nth) (val n sequence)
  (:method (val n seq)
    (setf (cl:nth n seq) val))
  (:method (val n (seq vector))
    (setf (aref seq n) val)))

#.`(progn
     ,@(loop for (function . n) in '((first . 0)
                                     (second . 1)
                                     (third . 2)
                                     (fourth . 3)
                                     (fifth . 4)
                                     (sixth . 5)
                                     (seventh . 6)
                                     (eighth . 7)
                                     (ninth . 8)
                                     (tenth . 9))
             collect `(defgeneric ,function (seq)
                        (:method ((seq list))
                          (,(intern (string function) :cl) seq))
                        (:method ((seq sequence))
                          (elt seq ,n)))))

(defgeneric last (seq &optional n)
  (:method ((seq list) &optional (n 1))
    (cl:last seq n))
  (:method ((seq sequence) &optional (n 1))
    (elt seq (- (length seq) n))))

(setf (symbol-function 'filter) (symbol-function 'remove-if-not))

(defmacro push (value place)
  `(typecase ,place
     (vector (vector-push-extend ,value ,place))
     (T (cl:push ,value ,place))))

(defmacro pushnew (value place &rest keys)
  `(typecase ,place
     (vector (or (find ,value ,place ,@keys)
                 (vector-push-extend ,place ,value)))
     (T (cl:pushnew ,value ,place ,@keys))))

(defmacro pop (place)
  `(typecase ,place
     (vector (cl:vector-pop ,place))
     (T (cl:pop ,place))))<commit_msg>Redefine nth & last as a general function.<commit_after>(in-package :cl-user)
(defpackage cl21.core.sequence
  (:use :cl)
  (:shadow :nth
           :first
           :second
           :third
           :fourth
           :fifth
           :sixth
           :seventh
           :eighth
           :ninth
           :tenth
           :last
           :push
           :pushnew
           :pop)
  (:import-from :split-sequence
                :split-sequence
                :split-sequence-if)
  (:export :nth
           :first
           :second
           :third
           :fourth
           :fifth
           :sixth
           :seventh
           :eighth
           :ninth
           :tenth
           :last
           :split-sequence
           :split-sequence-if

           :sequence
           :fill
           :copy-seq
           :make-sequence
           :subseq
           :reduce
           :count
           :count-if
           :length ;; TODO: Write as a generic function
           :reverse
           :nreverse
           :sort
           :stable-sort

           :find
           :find-if
           :position
           :position-if

           :search
           :mismatch
           :replace
           :concatenate
           :elt
           :merge

           :map
           :map-into

           :remove
           :remove-if
           :remove-if-not
           :filter
           :remove-duplicates

           :delete
           :delete-if
           :delete-if-not
           :delete-duplicates

           :substitute
           :substitute-if
           :nsubstitute
           :nsubstitute-if

           :push
           :pushnew
           :pop))
(in-package :cl21.core.sequence)

(defun nth (n seq)
  (typecase seq
    (list (cl:nth n seq))
    (vector (elt seq n))))

(defun (setf nth) (val n seq)
  (typecase seq
    (list (setf (cl:nth n seq) val))
    (vector (setf (aref seq n) val))))

#.`(progn
     ,@(loop for (function . n) in '((first . 0)
                                     (second . 1)
                                     (third . 2)
                                     (fourth . 3)
                                     (fifth . 4)
                                     (sixth . 5)
                                     (seventh . 6)
                                     (eighth . 7)
                                     (ninth . 8)
                                     (tenth . 9))
             collect `(defgeneric ,function (seq)
                        (:method ((seq list))
                          (,(intern (string function) :cl) seq))
                        (:method ((seq sequence))
                          (elt seq ,n)))))

(defun last (seq &optional n)
  (etypecase seq
    (list (cl:last seq n))
    (sequence (elt seq (- (length seq) n)))))

(setf (symbol-function 'filter) (symbol-function 'remove-if-not))

(defmacro push (value place)
  `(typecase ,place
     (vector (vector-push-extend ,value ,place))
     (T (cl:push ,value ,place))))

(defmacro pushnew (value place &rest keys)
  `(typecase ,place
     (vector (or (find ,value ,place ,@keys)
                 (vector-push-extend ,place ,value)))
     (T (cl:pushnew ,value ,place ,@keys))))

(defmacro pop (place)
  `(typecase ,place
     (vector (cl:vector-pop ,place))
     (T (cl:pop ,place))))
{'fraction_non_alphanumeric': 0.10967646185811813, 'fraction_numerical': 0.004452359750667854, 'mean_word_length': 1.0334942667471334, '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': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '624103', 'n_tokens_mistral': 1979, 'n_tokens_neox': 1862, 'n_words': 496}