chickadee » transmission » alist-let/nor

(alist-let alist (formal ...) body ...)syntax
(alist-let/and alist (formal ...) body ...)syntax
(alist-let/nor alist (formal ...) body ...)syntax

Where formal is either key, which will be used both as the key name and the variable, or (var key), which will be the variable name and key respectively.

Equivalent to:

(let ((var (alist-ref 'key alist))
      ...)
  body
  ...)

Except that, with alist-let/and, if alist is false, the whole expression evaluates to false; and with alist-let/nor, if alist is false, the whole expression evaluates to true.

Example:

(alist-let/and '((ant . 3) (bunny . 5) (Cat . 3))
               (ant bunny (cat Cat))
  (list ant bunny  cat))

Expands to something like this:

(let ((%alist '((ant . 3) (bunny . 5) (Cat . 3))))
  (let ((ant (alist-ref 'ant %alist))
        (bunny (alist-ref 'bunny %alist))
        (cat (alist-ref 'Cat %alist)))
  (list ant bunny cat)))