<commit_before>;;;; several higher order functions

(def testify (x)
  "If passed a function, returns it. Otherwise returns a function which
   tests equality for the object passed"
  (if (functionp x) x [iso x _]))

(def del (test xs &rest args)
  "Deletes all of the elements that pass test in the list xs. If test
   is a function all objects passing the test are removed. If test is
   anything else, all objects iso with it are removed
   NOTE: note the same as delete, as del is not a destructive function"
  (apply #'remove-if (testify test) xs args))

(def keep (test xs &rest args)
  "Same as del but keeps the elements that pass the test"
  (apply #'remove-if-not (testify test) xs args))

(def mem (test xs &rest args)
  "Analog for del and keep but for member"
  (apply #'member-if (testify test) xs args))

(def fnd (test xs &rest args)
  "Analog for del and keep but for find"
  (apply #'find-if (testify test) xs args))

(def pos (test xs &rest args)
  "Analog for del and keep but for position"
  (apply #'position-if (testify test) xs args))

(def mappend (f xs)
  "Joins the results of mapping f over xs"
  (apply #'join (mapf f xs)))
<commit_msg>added alter<commit_after>;;;; several higher order functions

(def testify (x)
  "If passed a function, returns it. Otherwise returns a function which
   tests equality for the object passed"
  (if (functionp x) x [iso x _]))

(def del (test xs &rest args)
  "Deletes all of the elements that pass test in the list xs. If test
   is a function all objects passing the test are removed. If test is
   anything else, all objects iso with it are removed
   NOTE: note the same as delete, as del is not a destructive function"
  (apply #'remove-if (testify test) xs args))

(def keep (test xs &rest args)
  "Same as del but keeps the elements that pass the test"
  (apply #'remove-if-not (testify test) xs args))

(def mem (test xs &rest args)
  "Analog for del and keep but for member"
  (apply #'member-if (testify test) xs args))

(def fnd (test xs &rest args)
  "Analog for del and keep but for find"
  (apply #'find-if (testify test) xs args))

(def pos (test xs &rest args)
  "Analog for del and keep but for position"
  (apply #'position-if (testify test) xs args))

(def mappend (f xs)
  "Joins the results of mapping f over xs"
  (apply #'join (mapf f xs)))

(def alter (old new seq)
  "Substitues everything passes the testified version of old
   with new (which can be a function)"
  (with (test (testify old) next (if (typep new 'function)
				     new
				     (const new)))
    (rec (tree seq)
       (if (atom tree)
	   (if (funcall test tree)
	       (funcall next tree)
	       tree)
	   (cons (recur (car tree))
		 (recur (cdr tree)))))))



{'fraction_non_alphanumeric': 0.09669117647058824, 'fraction_numerical': 0.0, 'mean_word_length': 3.395799676898223, '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': '1010493', 'n_tokens_mistral': 911, 'n_tokens_neox': 854, 'n_words': 438}