<commit_before>;; -*- lisp -*-

(in-package :it.bese.arnesi)

;;;; * Various flow control operators

;;;; ** Anaphoric conditionals

(defmacro if-bind (var test then &optional else)
  "Anaphoric IF control structure.

VAR (a symbol) will be bound to the primary value of TEST. If
TEST returns a true value then THEN will be executed, otherwise
ELSE will be executed."
  `(let ((,var ,test))
     (if ,var ,then ,else)))

(defmacro aif (test then &optional else)
  "Just like IF-BIND but the var is always IT."
  `(if-bind it ,test ,then ,else))

(defmacro when-bind (var test &body body)
  "Just like @code{WHEN} except @var{var} will be bound to the
  result of @var{test} in @var{body}."
  `(if-bind ,var ,test (progn ,@body)))

(defmacro awhen (test &body body)
  "Just like @code{WHEN} expect the symbol @code{IT} will be
  bound to the result of @var{test} in @var{body}."
  `(when-bind it ,test ,@body))

(defmacro cond-bind (var &body clauses)
  "Just like @code{COND} @var{var} will be bound to the result of
  the first cond which returns true."
  (if clauses
      (destructuring-bind ((test &rest body) &rest others)
          clauses
        `(if-bind ,var ,test
                  (progn ,@body)
                  (cond-bind ,var ,@others)))
      nil))
<commit_msg>Changed lambda list of IF-BIND so that slime will ident it better.<commit_after>;; -*- lisp -*-

(in-package :it.bese.arnesi)

;;;; * Various flow control operators

;;;; ** Anaphoric conditionals

(defmacro if-bind (var test &body then/else)
  "Anaphoric IF control structure.

VAR (a symbol) will be bound to the primary value of TEST. If
TEST returns a true value then THEN will be executed, otherwise
ELSE will be executed."
  (assert (first then/else)
          (then/else)
          "IF-BIND missing THEN clause.")
  (destructuring-bind (then &optional else)
      then/else
    `(let ((,var ,test))
       (if ,var ,then ,else))))

(defmacro aif (test then &optional else)
  "Just like IF-BIND but the var is always IT."
  `(if-bind it ,test ,then ,else))

(defmacro when-bind (var test &body body)
  "Just like @code{WHEN} except @var{var} will be bound to the
  result of @var{test} in @var{body}."
  `(if-bind ,var ,test (progn ,@body)))

(defmacro awhen (test &body body)
  "Just like @code{WHEN} expect the symbol @code{IT} will be
  bound to the result of @var{test} in @var{body}."
  `(when-bind it ,test ,@body))

(defmacro cond-bind (var &body clauses)
  "Just like @code{COND} @var{var} will be bound to the result of
  the first cond which returns true."
  (if clauses
      (destructuring-bind ((test &rest body) &rest others)
          clauses
        `(if-bind ,var ,test
                  (progn ,@body)
                  (cond-bind ,var ,@others)))
      nil))

{'fraction_non_alphanumeric': 0.1325126719768284, 'fraction_numerical': 0.0, 'mean_word_length': 3.0933333333333333, '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': '2933498', 'n_tokens_mistral': 937, 'n_tokens_neox': 912, 'n_words': 359}