ruricolist / serapeum

Utilities beyond Alexandria
MIT License
428 stars 42 forks source link

Consider adding conditionals that test for t #180

Open kilianmh opened 1 month ago

kilianmh commented 1 month ago

Sometime conditionals that test for t instead of non-nil are desired.

In this situation it might be convenient to have: if-t, when-t, cond-t or maybe even or-t and and-t.

What do you think? @ruricolist

ruricolist commented 1 month ago

My first thought is that a function to cast non-t to nil (like partially applied eq t) would accomplish the same thing without needing to introduce macros.

kilianmh commented 1 month ago

A function should also work and if we inline it there should be no performance penalty.

I can do the PR if you tell me which functions you want and with which name.

It should look like this then?

(defun if-t (test then &optional else)
  "If TEST evaluates to T, evaluate THEN and return its values,
otherwise evaluate ELSE and return its values. ELSE defaults to NIL."
  (if test
      (if (eq test t)
      then
      else)
      else))

(declaim (inline if-t))