<commit_before>(ns infinitelives.pixi.macros)

(defmacro ^:private assert-args
  [& pairs]
  `(do (when-not ~(first pairs)
         (throw (IllegalArgumentException.
                 (str (first ~'&form) " requires " ~(second pairs) " in " ~'*ns* ":" (:line (meta ~'&form))))))
       ~(let [more (nnext pairs)]
          (when more
            (list* `assert-args more)))))

(defmacro get-layer [canvas layer]
  `(-> ~canvas :layer ~layer))

(defmacro with-sprite [canvas layer bindings & body]
  (assert-args
   (vector? bindings) "a vector for its binding"
   (even? (count bindings)) "an even number of forms in binding vector")

  (if (pos? (count bindings))
    (let [symb (first bindings) val (second bindings)]
      `(let [~symb ~val]
         (.addChild (get-layer ~canvas ~layer) ~symb)
         (with-sprite ~canvas ~layer ~(subvec bindings 2) ~@body)
         (.removeChild (get-layer ~canvas ~layer) ~symb)))
    `(do ~@body)))

(defmacro with-layered-sprite [bindings & body]
  (assert-args
   (vector? bindings) "a vector for its binding"
   (= 0 (mod (count bindings) 3)) "triplets of forms in binding vector")

  (if (pos? (count bindings))
    (let [symb (first bindings)
          layer (second bindings)
          val (nth bindings 2)]
      `(let [~symb ~val
             canvas# infinitelives.pixi.canvas/*canvas*]
         (.addChild
          (get-layer canvas# ~layer)
          ~symb)
         (with-sprite ~(subvec bindings 3) ~@body)
         (.removeChild
          (get-layer canvas# ~layer)
          ~symb)))
    `(do ~@body)))

(defmacro with-sprite-set [canvas layer bindings & body]
  (assert-args
   (vector? bindings) "a vector for its binding"
   (even? (count bindings)) "an even number of forms in binding vector")

  (if (pos? (count bindings))
    (let [symb (first bindings) val (second bindings)]
      `(let [~symb ~val]
         (doseq [sprite# ~symb]
           (.addChild (get-layer ~canvas ~layer) sprite#))
         (with-sprite-set ~canvas ~layer ~(subvec bindings 2) ~@body)
         (doseq [sprite# ~symb]
           (.removeChild (get-layer ~canvas ~layer) sprite#))))
    `(do ~@body)))

(defmacro while-let
    "Repeatedly executes body while test expression is true, evaluating the body with binding-form bound to the value of test."
    [bindings & body]
    (let [form (first bindings) test (second bindings)]
        `(loop [~form ~test]
             (when ~form
                 ~@body
                 (recur ~test)))))

(defmacro with-canvas
  "Set the default canvas context to that specified"
  [canvas & body]
  `(binding [infinitelives.pixi.canvas/*canvas* ~canvas]
     ~@body))<commit_msg>fix default canvas<commit_after>(ns infinitelives.pixi.macros)

(defmacro ^:private assert-args
  [& pairs]
  `(do (when-not ~(first pairs)
         (throw (IllegalArgumentException.
                 (str (first ~'&form) " requires " ~(second pairs) " in " ~'*ns* ":" (:line (meta ~'&form))))))
       ~(let [more (nnext pairs)]
          (when more
            (list* `assert-args more)))))

(defmacro get-layer [canvas layer]
  `(-> ~canvas :layer ~layer))

(defmacro with-sprite [canvas layer bindings & body]
  (assert-args
   (vector? bindings) "a vector for its binding"
   (even? (count bindings)) "an even number of forms in binding vector")

  (if (pos? (count bindings))
    (let [symb (first bindings) val (second bindings)]
      `(let [~symb ~val]
         (.addChild (get-layer ~canvas ~layer) ~symb)
         (with-sprite ~canvas ~layer ~(subvec bindings 2) ~@body)
         (.removeChild (get-layer ~canvas ~layer) ~symb)))
    `(do ~@body)))

(defmacro with-layered-sprite [bindings & body]
  (assert-args
   (vector? bindings) "a vector for its binding"
   (= 0 (mod (count bindings) 3)) "triplets of forms in binding vector")

  (if (pos? (count bindings))
    (let [symb (first bindings)
          layer (second bindings)
          val (nth bindings 2)]
      `(let [~symb ~val
             canvas# (infinitelives.pixi.canvas/get)]
         (.addChild
          (get-layer canvas# ~layer)
          ~symb)
         (with-layered-sprite ~(subvec bindings 3) ~@body)
         (.removeChild
          (get-layer canvas# ~layer)
          ~symb)))
    `(do ~@body)))

(defmacro with-sprite-set [canvas layer bindings & body]
  (assert-args
   (vector? bindings) "a vector for its binding"
   (even? (count bindings)) "an even number of forms in binding vector")

  (if (pos? (count bindings))
    (let [symb (first bindings) val (second bindings)]
      `(let [~symb ~val]
         (doseq [sprite# ~symb]
           (.addChild (get-layer ~canvas ~layer) sprite#))
         (with-sprite-set ~canvas ~layer ~(subvec bindings 2) ~@body)
         (doseq [sprite# ~symb]
           (.removeChild (get-layer ~canvas ~layer) sprite#))))
    `(do ~@body)))

(defmacro while-let
    "Repeatedly executes body while test expression is true, evaluating the body with binding-form bound to the value of test."
    [bindings & body]
    (let [form (first bindings) test (second bindings)]
        `(loop [~form ~test]
             (when ~form
                 ~@body
                 (recur ~test)))))
{'fraction_non_alphanumeric': 0.147588611272516, 'fraction_numerical': 0.002324230098779779, 'mean_word_length': 2.628952916373858, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, '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': '5310304', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1635, 'n_words': 535}