[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: emacs lisp syntax rfc: (cond (EXPR => (lambda (X) ...)))

From: Harald Hanche-Olsen
Subject: Re: emacs lisp syntax rfc: (cond (EXPR => (lambda (X) ...)))
Date: Tue, 04 Jan 2011 18:56:13 +0100 (CET)

[Thien-Thi Nguyen <address@hidden> (2011-01-04 16:41:06 UTC)]

> () Harald Hanche-Olsen <address@hidden>
> () Sun, 02 Jan 2011 23:52:34 +0100 (CET)
>    If you think you need this, I suspect the need can
>    just as easily be covered using a macro:
>    (defmacro acond (&rest clauses) ...)
>    They can be very handy.
> True.  For my own code, i would not hesitate to use it.
> However, this macro masks ‘it’ from an outer scope, so is
> not a good general (for installation into Emacs) solution.

I offered the solution firstly to argue that the new syntax may not be
needed, since it is easily emulated. But if you want something to add
to emacs for general use, it is easy enough to tweak my macro so it
names the bound variable explicitly:

(defmacro acond (var &rest clauses)
  "Binds variable VAR and processes CLAUSES just like `cond', except that VAR
is set to the condition of the successful clause when the corresponding body
is executed."
  `(let (,var)
     (cond ,@(mapcar (lambda (clause) `((setq ,var ,(car clause))
                                        ,@(cdr clause)))

- Harald

reply via email to

[Prev in Thread] Current Thread [Next in Thread]