[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: |
Sun, 02 Jan 2011 23:52:34 +0100 (CET) |
[Thien-Thi Nguyen <address@hidden> (2011-01-02 21:45:56 UTC)]
> In Scheme, the expression:
>
> (cond (EXPR => (lambda (X) ...)))
>
> provides the lambda expression parameter X with the non-false
> value computed from evaluating EXPR. [...]
>
> What do people think of adding this to Emacs Lisp?
If you think you need this, I suspect the need can just as easily be
covered using a macro:
(defmacro acond (&rest clauses)
"Anaphoric `cond': Like `cond', except the value of the condition is bound
to the variable `it' during the execution of the corresponding body."
;; Bug: This macro does no error checking.
`(let (it)
(cond ,@(mapcar (lambda (clause) (cons (list 'setq 'it (car clause))
(cdr clause)))
clauses))))
Example usage:
(acond
((foo) (do-something-with it))
((bar) (do-something-else-with it)))
I learned about anaphoric macros from Paul Graham's "On Lisp".
They can be very handy.
- Harald