[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: condition-case
From: |
Ted Zlatanov |
Subject: |
Re: condition-case |
Date: |
Wed, 08 Dec 2010 09:49:58 -0600 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux) |
On Tue, 07 Dec 2010 10:58:23 -0500 Stefan Monnier <monnier@iro.umontreal.ca>
wrote:
>>>> I mean *today* why shouldn't `handler-case' be part of Emacs? Is there
>>>> anything blocking its inclusion in cl.el?
SM> I can't remember hearing of even a rumor of a patch to implement it.
SM> So, I guess that's the reason.
>> OK. So, given the source code Pascal posted, and assuming he assigns
>> the copyright, we could bring that into cl.el, right? Or will that not
>> work?
SM> I haven't noticed that source code, so I don't know whether it's any
SM> good, but assuming it's good enough and the copyright is in order, then
SM> I see no immediate reason why we'd reject it.
Here's what Pascal posted originally. I tested it a little and it seems
to work OK; it's basically syntactic sugar but pretty pleasant. We
should also consider `handler-bind' which is like `handler-case' but
executes handlers directly. Pascal, do you have an implementation of
that as well?
Thanks
Ted
(defmacro handler-case (expression &rest clauses)
"Common-Lisp
IMPLEMENTATION: The clause variable symbols are substituted by one single
condition-case variable symbol. This may cause problems
if the same symbol is used as data or if it's a dynamic
variable.
"
(let* ((var (gensym))
(neclause (assoc :NO-ERROR clauses))
(nell (cadr neclause))
(nebody (cddr neclause))
(handlers (mapcar (lambda (clause)
(let ((typespec (car clause))
(clausvar (cadr clause))
(body (cddr clause)))
(cons (if (and (consp typespec)
(eq 'or (car typespec)))
(cdr typespec)
typespec)
(if (null clausvar)
body
(subst var (car clausvar) body)))))
(remove neclause clauses))))
(if neclause
`(condition-case ,var
(multiple-value-bind ,nell ,expression ,@nebody)
,@handlers)
`(condition-case ,var
,expression
,@handlers))))
- Re: condition-case, (continued)
- Re: condition-case, Ted Zlatanov, 2010/12/08
- Re: condition-case, Pascal J. Bourguignon, 2010/12/08
- Re: condition-case, Ted Zlatanov, 2010/12/08
- Re: condition-case, Pascal J. Bourguignon, 2010/12/08
- Re: condition-case, Elena, 2010/12/08
- Re: condition-case, Pascal J. Bourguignon, 2010/12/08
- Re: condition-case, Ted Zlatanov, 2010/12/08
- Re: condition-case, Stefan Monnier, 2010/12/08
- Re: condition-case, Ted Zlatanov, 2010/12/08
- Re: condition-case, Stefan Monnier, 2010/12/08
- Re: condition-case,
Ted Zlatanov <=
- Re: condition-case, Pascal J. Bourguignon, 2010/12/08
- Re: condition-case, Stefan Monnier, 2010/12/09
- Re: condition-case, Ted Zlatanov, 2010/12/10
- Re: condition-case, Stefan Monnier, 2010/12/10
- Re: condition-case, Ted Zlatanov, 2010/12/13
- Re: condition-case, Ted Zlatanov, 2010/12/13
- Re: condition-case, Stefan Monnier, 2010/12/15
- Re: condition-case, Ted Zlatanov, 2010/12/15
- Re: condition-case, Stefan Monnier, 2010/12/16
- Re: condition-case, Pascal J. Bourguignon, 2010/12/08