[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Sweeter Emacs Lisp
From: |
Thien-Thi Nguyen |
Subject: |
Re: Sweeter Emacs Lisp |
Date: |
Tue, 23 Jul 2013 06:37:50 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
() Stefan Monnier <address@hidden>
() Mon, 22 Jul 2013 17:04:04 -0400
> RMS suggested instead:
> (cond VAR (CONDITION [BODY...])
> ...)
As I pointed out back then, a more general solution is a way to
let-bind new variables in between cond clauses, as in
(cond
(<test1> <body1>)
(let x <foo>)
(<test2> <body2>))
which would be used in cases where we currently use
(let (x)
(cond
(<test1> <body1>)
((progn (setq x <foo>) <test2>) <body2>))
Yes, i see this can be used as the basis of the other forms. Cool.
Has anyone done a C implementation? Here's a sketch (in *scratch*):
(defmacro cool-cond (&rest clauses)
(let ((rev (reverse clauses))
one elab)
(while (setq one (pop rev))
(setq elab (pcase one
(`(let ,var ,exp)
`((t (let ((,var ,exp))
(cond ,@elab)))))
(`(let ,var)
`((t (let (,var)
(cond ,@elab)))))
(_ (cons one elab)))))
`(cond ,@elab)))
(macroexpand '(cool-cond
(nil t)
(t nil)))
(cond
(nil t)
(t nil))
(macroexpand '(cool-cond
(let bar 'none)
(nil t)
(let foo (list bar 42))
(foo)
(t nil)))
(cond
(t
(let
((bar 'none))
(cond
(nil t)
(t
(let
((foo
(list bar 42)))
(cond
(foo)
(t nil))))))))
--
Thien-Thi Nguyen
GPG key: 4C807502
(if you're human and you know it)
read my lisp: (responsep (questions 'technical)
(not (via 'mailing-list)))
=> nil
pgpfbj0sqGfPy.pgp
Description: PGP signature
- Re: Sweeter Emacs Lisp, (continued)
- Re: Sweeter Emacs Lisp, Juanma Barranquero, 2013/07/16
- Re: Sweeter Emacs Lisp, Andreas Schwab, 2013/07/16
- Re: Sweeter Emacs Lisp, Thierry Volpiatto, 2013/07/16
- Re: Sweeter Emacs Lisp, Juanma Barranquero, 2013/07/16
- Re: Sweeter Emacs Lisp, Andreas Schwab, 2013/07/16
- Re: Sweeter Emacs Lisp, Juanma Barranquero, 2013/07/16
- Re: Sweeter Emacs Lisp, Stefan Monnier, 2013/07/16
Re: Sweeter Emacs Lisp, Stefan Monnier, 2013/07/22