<commit_before>;;; -*- Gerbil -*-
;;; (C) vyzo at hackzen.org, proksi at disroot.org
;;; generic ref

(import :gerbil/gambit
        :std/generic)

(export ref ~ :ref
        ref-set! ~-set! :set!)

(defalias ~ ref)

(defalias ~-set! ref-set!)

(defrules ref ()
  ((_ obj x) (:ref obj x))
  ((recur obj x rest ...) (recur (:ref obj x) rest ...)))

(defgeneric :ref (lambda args #f))

(defmethod (:ref (lst <pair>) (n <fixnum>))
  (list-ref lst n))

(defmethod (:ref (hsh <hash-table>) (k <t>))
  (hash-ref hsh k))

(defmethod (:ref (vctr <u8vector>) (n <fixnum>))
  (u8vector-ref vctr n))

(defmethod (:ref (vctr <u16vector>) (n <fixnum>))
  (u16vector-ref vctr n))

(defmethod (:ref (vctr <u32vector>) (n <fixnum>))
  (u32vector-ref vctr n))

(defmethod (:ref (vctr <u64vector>) (n <fixnum>))
  (u64vector-ref vctr n))

(defmethod (:ref (vctr <f32vector>) (n <fixnum>))
  (f32vector-ref vctr n))

(defmethod (:ref (vctr <f64vector>) (n <fixnum>))
  (f64vector-ref vctr n))

(defmethod (:ref (str <string>) (n <fixnum>))
  (string-ref str n))

(defrules ref-set! ()
  ((_ obj x val) (:set! obj x val))
  ((recur obj x y rest ...) (recur (:set! obj x y) rest ...)))

(defgeneric :set! (lambda args #f))

(defmethod (:set! (lst <pair>) (n <fixnum>) (val <t>))
  (list-set! lst n val))

(defmethod (:set! (hsh <hash-table>) (k <t>) (val <t>))
  (hash-put! hsh k val))

(defmethod (:set! (vctr <u8vector>) (n <fixnum>) (val <fixnum>))
  (u8vector-set! vctr n val))

(defmethod (:set! (vctr <u16vector>) (n <fixnum>) (val <fixnum>))
  (u16vector-set! vctr n val))

(defmethod (:set! (vctr <u32vector>) (n <fixnum>) (val <fixnum>))
  (u32vector-set! vctr n val))

(defmethod (:set! (vctr <u64vector>) (n <fixnum>) (val <fixnum>))
  (u64vector-set! vctr n val))

(defmethod (:set! (vctr <f32vector>) (n <fixnum>) (val <real>))
  (f32vector-set! vctr n val))

(defmethod (:set! (vctr <f64vector>) (n <fixnum>) (val <real>))
  (f64vector-set! vctr n val))

(defmethod (:set! (str <string>) (n <fixnum>) (val <char>))
  (string-set! str n val))<commit_msg>Add vector, removed default #f<commit_after>;;; -*- Gerbil -*-
;;; (C) vyzo at hackzen.org, proksi at disroot.org
;;; generic ref

(import :gerbil/gambit
        :std/generic)

(export ref ~ :ref
        ref-set! ~-set! :set!)

(defalias ~ ref)

(defalias ~-set! ref-set!)

(defrules ref ()
  ((_ obj x) (:ref obj x))
  ((recur obj x rest ...) (recur (:ref obj x) rest ...)))

(defgeneric :ref)

(defmethod (:ref (lst <pair>) (n <fixnum>))
  (list-ref lst n))

(defmethod (:ref (hsh <hash-table>) (k <t>))
  (hash-ref hsh k))

(defmethod (:ref (vctr <u8vector>) (n <fixnum>))
  (u8vector-ref vctr n))

(defmethod (:ref (vctr <u16vector>) (n <fixnum>))
  (u16vector-ref vctr n))

(defmethod (:ref (vctr <u32vector>) (n <fixnum>))
  (u32vector-ref vctr n))

(defmethod (:ref (vctr <u64vector>) (n <fixnum>))
  (u64vector-ref vctr n))

(defmethod (:ref (vctr <f32vector>) (n <fixnum>))
  (f32vector-ref vctr n))

(defmethod (:ref (vctr <f64vector>) (n <fixnum>))
  (f64vector-ref vctr n))

(defmethod (:ref (str <string>) (n <fixnum>))
  (string-ref str n))

(defmethod (:ref (vctr <vector>) (n <fixnum>))
  (vector-ref vctr n))

(defrules ref-set! ()
  ((_ obj x val) (:set! obj x val))
  ((recur obj x y rest ...) (recur (:set! obj x y) rest ...)))

(defgeneric :set!)

(defmethod (:set! (lst <pair>) (n <fixnum>) (val <t>))
  (list-set! lst n val))

(defmethod (:set! (hsh <hash-table>) (k <t>) (val <t>))
  (hash-put! hsh k val))

(defmethod (:set! (vctr <u8vector>) (n <fixnum>) (val <fixnum>))
  (u8vector-set! vctr n val))

(defmethod (:set! (vctr <u16vector>) (n <fixnum>) (val <fixnum>))
  (u16vector-set! vctr n val))

(defmethod (:set! (vctr <u32vector>) (n <fixnum>) (val <fixnum>))
  (u32vector-set! vctr n val))

(defmethod (:set! (vctr <u64vector>) (n <fixnum>) (val <fixnum>))
  (u64vector-set! vctr n val))

(defmethod (:set! (vctr <f32vector>) (n <fixnum>) (val <real>))
  (f32vector-set! vctr n val))

(defmethod (:set! (vctr <f64vector>) (n <fixnum>) (val <real>))
  (f64vector-set! vctr n val))

(defmethod (:set! (str <string>) (n <fixnum>) (val <char>))
  (string-set! str n val))

(defmethod (:set! (vctr <vector>) (n <fixnum>) (val <t>))
  (vector-set! vctr n val))

{'fraction_non_alphanumeric': 0.22673594709494568, 'fraction_numerical': 0.020784128483703354, 'mean_word_length': 4.05973715651135, 'pattern_counts': {'":': 0, '<': 98, '<?xml version=': 0, '>': 98, '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': '4252403', 'n_tokens_mistral': 1907, 'n_tokens_neox': 1868, 'n_words': 538}