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

;;;; This file contains some utilities that are useful in
;;;; discriminating functions, and perhaps elsewhere as well.
;;;; 
;;;; The utilities defined here are special versions of functions that
;;;; exist in standard Common Lisp.  The reason for not using the more
;;;; general existing version is that those versions might be defined
;;;; as GENERIC functions in some implementations, in particular in
;;;; SICL, and we these functions in the general machinery for making
;;;; generic functions work.  So to avoid circular dependencies and
;;;; metastability issues, we define these special versions that only
;;;; work on list. 

;;; Non-destructive list reversal. 
(defun list-reverse (list)
  (loop with result = '()
	for element in list
	do (push element result)
	finally (return result)))<commit_msg>Added destructive merge function for lists.<commit_after>(cl:in-package #:sicl-clos)

;;;; This file contains some utilities that are useful in
;;;; discriminating functions, and perhaps elsewhere as well.
;;;; 
;;;; The utilities defined here are special versions of functions that
;;;; exist in standard Common Lisp.  The reason for not using the more
;;;; general existing version is that those versions might be defined
;;;; as GENERIC functions in some implementations, in particular in
;;;; SICL, and we these functions in the general machinery for making
;;;; generic functions work.  So to avoid circular dependencies and
;;;; metastability issues, we define these special versions that only
;;;; work on list. 

;;; Non-destructive list reversal. 
(defun list-reverse (list)
  (loop with result = '()
	for element in list
	do (push element result)
	finally (return result)))

;;; Destructive list merging.
(defun list-merge (list1 list2 predicate &key key)
  (when (null key)
    (setf key #'identity))
  (cond ((null list1)
	 list2)
	((null list2)
	 list1)
	(t
	 (let ((result '()))
	   ;; Figure out a first element to put on the resulting list.
	   (if (funcall predicate
			(funcall key (car list2))
			(funcall key (car list1)))
	       (let ((temp (cdr list2)))
		 (setf result list2)
		 (setf list2 temp))
	       (let ((temp (cdr list1)))
		 (setf result list1)
		 (setf list1 temp)))
	   ;; Do the remaining elements
	   (let ((rest result))
	     (loop until (or (null list1) (null list2))
		   do (if (funcall predicate
				   (funcall key (car list2))
				   (funcall key (car list1)))
			  (let ((temp (cdr list2)))
			    (setf (cdr rest) list2)
			    (setf list2 temp))
			  (let ((temp (cdr list1)))
			    (setf (cdr rest) list1)
			    (setf list1 temp)))
		      (setf rest (cdr rest)))
	     (setf (cdr rest)
		   (if (null list1) list2 list1)))
	   result))))
		      
		 
  
{'fraction_non_alphanumeric': 0.11272200072490032, 'fraction_numerical': 0.009786154403769481, 'mean_word_length': 3.5847176079734218, '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': '1437087', 'n_tokens_mistral': 872, 'n_tokens_neox': 765, 'n_words': 355}