<commit_before>(in-package :cl-user)
(defpackage clep
  (:use :cl)
  (:export
   :search-result
   :search-result-p
   :search-result-form
   :search-result-binds
   :search-result-footprints
   :search-result-pathname
   :search-result-form-count
   :clep-sexp
   :clep-stream
   :clep-files))
(in-package :clep)

(defstruct search-result
  form
  binds
  file-position
  footprints
  pathname
  form-count)

(defun %match (pattern expr binds)
  (cond ((and (symbolp pattern)
              (symbolp expr)
              (equal (symbol-name pattern)
                     (symbol-name expr)))
         (values binds t))
        ((and (consp pattern)
              (case (car pattern)
                (:lisp
                 (when (funcall (cadr pattern) expr)
                   (push expr binds)
                   t))
                (:*
                 (push expr binds)
                 t)
                (otherwise
                 nil)))
         (values binds t))
        ((and (consp pattern)
              (consp expr)
              (let ((match-p nil))<commit_msg>マッチ関数とオペレータの定義を分割<commit_after>(in-package :cl-user)
(defpackage clep
  (:use :cl)
  (:export
   :search-result
   :search-result-p
   :search-result-form
   :search-result-binds
   :search-result-footprints
   :search-result-pathname
   :search-result-form-count
   :clep-sexp
   :clep-stream
   :clep-files))
(in-package :clep)

(defstruct search-result
  form
  binds
  file-position
  footprints
  pathname
  form-count)

(defvar *operators* (make-hash-table))

(defmacro define-operator ((operator &rest operator-args) (expr) &body body)
  (check-type operator symbol)
  (check-type operator-args list)
  (check-type expr symbol)
  `(setf (gethash ',operator *operators*)
         (cons (lambda (,expr ,@operator-args)
                 ,@body)
               ,(length operator-args))))

(define-operator (:*) (expr)
  (declare (ignore expr))
  t)

(define-operator (:lisp fun) (expr)
  (funcall fun expr))

(defun %match (pattern expr binds)
  (cond ((and (symbolp pattern)
              (symbolp expr)
              (string= pattern expr))
         (values binds t))
        ((and (consp pattern)
              (let ((matcher-and-argnum (gethash (car pattern) *operators*)))
                (when matcher-and-argnum
                  (destructuring-bind (matcher . argnum) matcher-and-argnum
                    (when (and (= argnum (length (cdr pattern)))
                               (apply matcher expr (cdr pattern)))
                      (push expr binds)
                      t)))))
         (values binds t))
        ((and (consp pattern)
              (consp expr)
              (let ((match-p nil))
{'fraction_non_alphanumeric': 0.12300260126347083, 'fraction_numerical': 0.0, 'mean_word_length': 1.8277310924369747, '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': '1819796', 'n_tokens_mistral': 865, 'n_tokens_neox': 835, 'n_words': 207}