;;; -*- mode: Lisp; Syntax: Common-Lisp; -*- ;;; ;;; Copyright (c) 2009 by the authors. ;;; ;;; See LICENCE for details. (in-package :hu.dwim.util) ;;;;;; ;;; Anaphora extensions (def (macro e) if-bind (var test &body then/else) (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)))) (def (macro e) when-bind (var test &body body) `(if-bind ,var ,test (progn ,@body))) (def (macro e) cond-bind (var &body clauses) "Just like COND but VAR will be bound to the result of the condition in the clause when executing the body of the clause." (if clauses (destructuring-bind ((test &rest body) &rest others) clauses `(if-bind ,var ,test (progn ,@(if body body (list var))) (cond-bind ,var ,@others))) nil)) (def (macro e) prog1-bind (var ret &body body) `(let ((,var ,ret)) ,@body ,var))