<commit_before>#|

  Copyright (c) 2013, <NAME>. All rights reserved.

  This program and the accompanying materials are made available under
  the terms of the Eclipse Public License v1.0 which accompanies this
  distribution, and is available at
  http://www.eclipse.org/legal/epl-v10.html

|#

(in-package #:lupine/aux)

(deftype class-designator ()
  '(or symbol class))

(defun compute-class (c)
  (declare (type class-designator c)
	   (values class &optional))
  (etypecase c
    (symbol (find-class c))
    (class c)))

(deftype type-designator ()
  '(or class-designator (cons symbol t)))

(defun member-typep (type list)
  (declare
   (type type-designator type)
   (type list list)
   (values t (or unsigned-byte null) &optional))
  (do* ((restv list (cdr restv))
	(eltv (car restv) (car restv))
	(n 0 (incf n)))
       ((null restv) (values nil nil))
    (when (typep eltv type)
      (return (values eltv n)))))

;; (member-typep 'string '(1 2 "Three" #:4))
;; => "Three", 2
;; (member-typep 'string '(1 2 "Three"))
;; => "Three", 2
;; (member-typep 'string '("Three" 2 1))
;; => "Three", 0
;; (member-typep 'bignum '("Three" 2 1))
;; => NIL, NIL


(defun simplify-string (str)
  (declare (type string str)
	   (values (or simple-string simple-base-string)
		   &optional))
  (handler-case
      (coerce str 'simple-base-string)
    (type-error ()
      (coerce str 'simple-string))))


#|
 (type-of (simplify-string "FOO"))

 (type-of
 (simplify-string (make-array 31 :element-type 'character :adjustable t
		       :initial-element (code-char #x3C0))))
|#
<commit_msg>compute-class defun->defmacro (sb compiler 'env' arg handling)<commit_after>#|

  Copyright (c) 2013, <NAME>. All rights reserved.

  This program and the accompanying materials are made available under
  the terms of the Eclipse Public License v1.0 which accompanies this
  distribution, and is available at
  http://www.eclipse.org/legal/epl-v10.html

|#

(in-package #:lupine/aux)

(deftype class-designator ()
  '(or symbol class))

(defmacro compute-class (c &environment env)
  (let ((%c (gensym "%C-")))
    `(let ((,%c ,c))
       (etypecase ,%c
	 (symbol (find-class ,%c t ,env))
	 (class ,%c)))))

;; (compute-class 'standard-class)

(deftype type-designator ()
  '(or class-designator (cons symbol t)))

(defun member-typep (type list)
  (declare
   (type type-designator type)
   (type list list)
   (values t (or unsigned-byte null) &optional))
  (do* ((restv list (cdr restv))
	(eltv (car restv) (car restv))
	(n 0 (incf n)))
       ((null restv) (values nil nil))
    (when (typep eltv type)
      (return (values eltv n)))))

;; (member-typep 'string '(1 2 "Three" #:4))
;; => "Three", 2
;; (member-typep 'string '(1 2 "Three"))
;; => "Three", 2
;; (member-typep 'string '("Three" 2 1))
;; => "Three", 0
;; (member-typep 'bignum '("Three" 2 1))
;; => NIL, NIL


(defun simplify-string (str)
  (declare (type string str)
	   (values (or simple-string simple-base-string)
		   &optional))
  (handler-case
      (coerce str 'simple-base-string)
    (type-error ()
      (coerce str 'simple-string))))


#|
 (type-of (simplify-string "FOO"))

 (type-of
 (simplify-string (make-array 31 :element-type 'character :adjustable t
		       :initial-element (code-char #x3C0))))
|#

{'fraction_non_alphanumeric': 0.17033639143730886, 'fraction_numerical': 0.01529051987767584, 'mean_word_length': 3.5304709141274238, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5267134', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1155, 'n_words': 358}