Change &optional branches to &rest branches in `-if-let`s

master
Matus Goljer 13 years ago
parent 6d20aa0864
commit bf85b21eb2
  1. 16
      dash.el

@ -821,31 +821,31 @@ body."
(when it
,@body)))
(defmacro -if-let (var-val then &optional else)
(defmacro -if-let (var-val then &rest else)
"If VAL evaluates to non-nil, bind it to VAR and do THEN,
otherwise do ELSE. VAR-VAL should be a (VAR VAL) pair."
(let ((var (car var-val))
(val (cadr var-val)))
`(let ((,var ,val))
(if ,var ,then ,else))))
(if ,var ,then ,@else))))
(defmacro -if-let* (vars-vals then &optional else)
(defmacro -if-let* (vars-vals then &rest else)
"If all VALS evaluate to true, bind them to their corresponding
VARS and do THEN, otherwise do ELSE. VARS-VALS should be a list
of (VAR VAL) pairs (corresponding to the bindings of `let*')."
(let ((first-pair (car vars-vals))
(rest (cdr vars-vals)))
(if (= (length vars-vals) 1)
`(-if-let ,first-pair ,then ,else)
`(-if-let ,first-pair ,then ,@else)
`(-if-let ,first-pair
(-if-let* ,rest ,then ,else)
,else))))
(-if-let* ,rest ,then ,@else)
,@else))))
(defmacro --if-let (val then &optional else)
(defmacro --if-let (val then &rest else)
"If VAL evaluates to non-nil, bind it to `it' and do THEN,
otherwise do ELSE."
`(let ((it ,val))
(if it ,then ,else)))
(if it ,then ,@else)))
(put '-when-let 'lisp-indent-function 1)
(put '-when-let* 'lisp-indent-function 1)

Loading…
Cancel
Save