<commit_before>;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; indent-tabs-mode: nil -*-

;; This file is part of Sheeple

;; sheep-creation.lisp
;;
;; Sheep creation, cloning, inspection
;;
;; TODO - write validate-hierarchy-list, which could be called whenever the parents list changes.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(in-package :sheeple)

;; We declare these base vars here so that bootstrapping won't complain.
;; They're also initialized to (gensym) so that pre-bootstrap tests have
;; something to check against that isn't all NIL.
(defvar =standard-metasheep= (gensym "=STANDARD-METASHEEP="))
(defvar =t= (gensym "=T="))
(defvar =standard-sheep= (gensym "=STANDARD-SHEEP="))

;;;
;;; Sheeple object
;;;

;; Sketch of a freshly-consed sheep:
;; (cons =standard-metasheep=)
;;       (vector parents properties property-metaobjects roles hierarchy-list children))
;;
;; By default, everything in the cdr of the sheep is initialized to nil.
(defun allocate-std-sheep ()
  "Creates a standard sheep object."
  (cons =standard-metasheep=
        (make-array 6 :initial-element nil)))

(defun std-sheep-p (obj)
  "A standard sheep object is a simple cons that points to the vector where the actual
'metaproperties' live. For a standard sheep object, this vector is 6 elements long, and
everything is initialized to nil."
  (when (and (consp obj)
             (eql =standard-metasheep=
                  (car obj))
             (vectorp (cdr obj))
             (= 6 (length (cdr obj))))
    t))

(defun allocate-sheep (metasheep)
  "Allocates the basic skeleton for a sheep object in memory and returns it."
  (if (eql =standard-metasheep= metasheep)
      (allocate-std-sheep)
      (allocate-sheep-using-metasheep metasheep)))

(defun sheepp (sheep)
  "Predicate for sheepdom."
  (if (std-sheep-p sheep)
      t
      (and (consp sheep)
           (std-sheep-p (car sheep)))))

;;; Some useful accessors...
(defun sheep-metasheep (sheep)
  "Returns SHEEP's metasheep. For now, there is no support for changing a sheep's metasheep."
  (car sheep))
;; no (setf sheep-metasheep) for now.

(defun sheep-parents (sheep)
  (svref (cdr sheep) 0))
(defun (setf sheep-parents) (new-value sheep)
  (setf (svref (cdr sheep) 0) new-value))
<commit_msg>Let's print these guys early.<commit_after>;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; indent-tabs-mode: nil -*-

;; This file is part of Sheeple

;; sheep-creation.lisp
;;
;; Sheep creation, cloning, inspection
;;
;; TODO - write validate-hierarchy-list, which could be called whenever the parents list changes.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(in-package :sheeple)

;; We declare these base vars here so that bootstrapping won't complain.
;; They're also initialized to (gensym) so that pre-bootstrap tests have
;; something to check against that isn't all NIL.
(defvar =standard-metasheep= (gensym "=STANDARD-METASHEEP="))
(defvar =t= (gensym "=T="))
(defvar =standard-sheep= (gensym "=STANDARD-SHEEP="))

;;;
;;; Sheeple object
;;;

;; Sketch of a freshly-consed sheep:
;; (cons =standard-metasheep=)
;;       (vector parents properties property-metaobjects roles hierarchy-list children))
;;
;; By default, everything in the cdr of the sheep is initialized to nil.
(defun allocate-std-sheep ()
  "Creates a standard sheep object."
  (cons =standard-metasheep=
        (make-array 6 :initial-element nil)))

(defun std-sheep-p (obj)
  "A standard sheep object is a simple cons that points to the vector where the actual
'metaproperties' live. For a standard sheep object, this vector is 6 elements long, and
everything is initialized to nil."
  (when (and (consp obj)
             (eql =standard-metasheep=
                  (car obj))
             (vectorp (cdr obj))
             (= 6 (length (cdr obj))))
    t))

(defun early-print-sheep (sheep stream)
  (print-unreadable-object (sheep stream :identity t)
    (format stream "Early Sheep")))
(defmethod print-object ((obj cons) stream)
  (if (std-sheep-p obj)
      (early-print-sheep obj stream)
      (call-next-method)))

(defun allocate-sheep (metasheep)
  "Allocates the basic skeleton for a sheep object in memory and returns it."
  (if (eql =standard-metasheep= metasheep)
      (allocate-std-sheep)
      (allocate-sheep-using-metasheep metasheep)))

(defun sheepp (sheep)
  "Predicate for sheepdom."
  (if (std-sheep-p sheep)
      t
      (and (consp sheep)
           (std-sheep-p (car sheep)))))

;;; Some useful accessors...
(defun sheep-metasheep (sheep)
  "Returns SHEEP's metasheep. For now, there is no support for changing a sheep's metasheep."
  (car sheep))
;; no (setf sheep-metasheep) for now.

(defun sheep-parents (sheep)
  (svref (cdr sheep) 0))
(defun (setf sheep-parents) (new-value sheep)
  (setf (svref (cdr sheep) 0) new-value))

{'fraction_non_alphanumeric': 0.16419426945742735, 'fraction_numerical': 0.002844950213371266, 'mean_word_length': 3.746383799421408, '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': '183096', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1619, 'n_words': 539}