<commit_before>(cl:in-package #:sicl-cons)

(declaim (inline consp car cdr rplaca rplacd))

;;; It might seem backward to define CONSP in terms of TYPEP, but
;;; TYPEP with a quoted arguments is transformed by a compiler macro
;;; into (SICL-TYPE:TYPEQ OBJECT CONS), which is processed by the type
;;; inference mechanism.  Should there be any remaining instances of
;;; (SICL-TYPE:TYPEQ OBJECT CONS) when the type inference is finished,
;;; it is transformed into a low-level operation that tests the tag
;;; bits.  In the implementation of TYPEP, when it turns out that the
;;; type being tested for is CONS, there might very well be a call to
;;; CONSP, which might then look circular, but it really is not
;;; because of what was said above.
(defun consp (object)
  (typep object 'cons))

(defun car (list)
  (declare (type list list))
  (if (consp list)
      (load-car list)
      nil))

(defun cdr (list)
  (declare (type list list))
  (if (consp list)
      (load-cdr list)
      nil))
  
(defun rplaca (cons object)
  (declare (type cons cons))
  (store-car cons object)
  cons)

(defun rplacd (cons object)
  (declare (type cons cons))
  (store-cdr cons object)
  cons)<commit_msg>Simplify and use recently introduced Cleavir PRIMOPs.<commit_after>(cl:in-package #:sicl-cons)

(defun car (list)
  (declare (type list list))
  (if (consp list)
      (cleavir-primop:car list)
      nil))

(defun cdr (list)
  (declare (type list list))
  (if (consp list)
      (cleavir-primop:cdr list)
      nil))
  
(defun rplaca (cons object)
  (declare (type cons cons))
  (cleavir-primop:rplaca cons object)
  cons)

(defun rplacd (cons object)
  (declare (type cons cons))
  (cleavir-primop:rplacd cons object)
  cons)
{'fraction_non_alphanumeric': 0.1100757134536983, 'fraction_numerical': 0.0, 'mean_word_length': 3.74585635359116, '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': '1023076', 'n_tokens_mistral': 601, 'n_tokens_neox': 582, 'n_words': 227}